使用到的兩個對象:DocumentSummaryInformation和SummaryInformation。spa
代碼以下:code
static void Main(string[] args) { //Create 一個Excel對象 HSSFWorkbook hssfWorkbook = new HSSFWorkbook(); //Create Excel的屬性中的來源以及說明等 DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation(); dsi.Company = "NPOI-1"; dsi.Category = "NPOI-2"; dsi.Manager = "NPOI-3"; //建立好的對象賦給hssfWorkbook,這樣才能保證這些信息被寫入文件 hssfWorkbook.DocumentSummaryInformation = dsi; SummaryInformation si = PropertySetFactory.CreateSummaryInformation(); si.Subject = "NPOI SDK Example 1"; si.Title = "NPOI SDK Example 2"; si.ApplicationName = "NPOI SDK Example 3"; si.Author = "NPOI SDK Example 4"; si.LastAuthor = "NPOI SDK Example 5"; si.Comments = "NPOI SDK Example 6"; si.CreateDateTime = DateTime.Now.AddMonths(-2); //建立好的對象賦給hssfWorkbook,這樣才能保證這些信息被寫入文件 hssfWorkbook.SummaryInformation = si; //建立文件並寫入 FileStream file = new FileStream(@"demo.xls", FileMode.Create); hssfWorkbook.Write(file); file.Close(); }
生成的Excel屬性中能夠看到以下信息:orm