使用到的两个对象:DocumentSummaryInformation和SummaryInformation。
代码如下:
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属性中可以看到如下信息:
时间: 2024-10-01 20:07:11