解压缩使用 NPOI 生成的 .xlsx,我注意到 NPOI 在 docProps/app.xml 中将自己设置为“Application”,并且还在 docProps/custom.xml 中添加了“Generator”。
<?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”。
最佳答案
您需要从 ExtendedProperties
获取基础属性,然后设置它的 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();
}
生成器属性
在 CustomProperties
(custom.xml) 中更改 Generator
的示例。
CustomProperties customProperties = properies.CustomProperties;
customProperties.AddProperty("Generator", "petelids");
customProperties.AddProperty("Generator Version", "1.0");
关于c# - 如何使用 NPOI 更改 app.xml (XSSF) 中的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52988023/