C# NPOI 添加修改Excel文件属性

HSSFWorkbook(.xls)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
HSSFWorkbook workbook = new HSSFWorkbook();

DocumentSummaryInformation dsi = PropertySetFactory.CreateDocumentSummaryInformation();
dsi.Company = "Company";
dsi.Category = "Category";
dsi.Manager = "Manager";

SummaryInformation si = PropertySetFactory.CreateSummaryInformation();
si.Subject = "Subject";
si.Title = "Title";
si.ApplicationName = "ApplicationName";
si.Author = "Author";
si.LastAuthor = "LastAuthor";
si.Comments = "Comments";
si.CreateDateTime = DateTime.Now.AddMonths(-2);

workbook.DocumentSummaryInformation = dsi;
workbook.SummaryInformation = si;

XSSFWorkbook(.xlsx)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

XSSFWorkbook workbook = new XSSFWorkbook();

POIXMLProperties xmlprops = workbook.GetProperties();
xmlprops.CoreProperties.Creator = "Creator";
xmlprops.CoreProperties.Subject = "Subject";
xmlprops.CoreProperties.Category = "Category";
xmlprops.CoreProperties.Title = "Title";
xmlprops.CoreProperties.ContentStatus = "ContentStatus";
xmlprops.CoreProperties.ContentType = "ContentType";
xmlprops.CoreProperties.Description = "Description";
xmlprops.CoreProperties.Identifier = "Identifier";
xmlprops.CoreProperties.Keywords = "Keywords";
xmlprops.CoreProperties.Revision = "Revision";

CT_ExtendedProperties ctprops = xmlprops.ExtendedProperties.GetUnderlyingProperties();
ctprops.Application = ("Application");
ctprops.Company = ("Company");