解压缩用NPOI生成的.xlsx时,我注意到NPOI在docProps / app.xml中将自身设置为“ Application”,并且还将“ Generator”添加到docProps / custom.xml中。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Properties xmlns="http://schemas.openxmlformats.org/officeDocument/2006/extended-properties" xmlns:vt="http://schemas.openxmlformats.org/officeDocument/2006/docPropsVTypes">
<Application>NPOI</Application>
<AppVersion>123.456</AppVersion>
</Properties>
如何在app.xml中编辑应用程序信息?
我只发现了CoreProperties
,CustomProperties
和ExtendedProperties
,但没有找到“ AppProperties”。
答案 0 :(得分:1)
您需要从ExtendedProperties
获取基础属性,然后设置其Application
属性。以下示例设置了Application和AppVersion:
static void Main(string[] args)
{
XSSFWorkbook workbook = new XSSFWorkbook();
ISheet sheet1 = workbook.CreateSheet("Sheet1");
POIXMLProperties props = workbook.GetProperties();
//get the underlying properties (of type NPOI.OpenXmlFormats.CT_ExtendedProperties)
var underlyingProps = props.ExtendedProperties.GetUnderlyingProperties();
//now set the properties (excuse the vanity!)
underlyingProps.Application = "petelids";
underlyingProps.AppVersion = "1.0";
FileStream sw = File.Create("test.xlsx");
workbook.Write(sw);
sw.Close();
}
在Generator
(custom.xml)中更改CustomProperties
的示例。
CustomProperties customProperties = properies.CustomProperties;
customProperties.AddProperty("Generator", "petelids");
customProperties.AddProperty("Generator Version", "1.0");