c# - 如何使用 NPOI 更改 app.xml (XSSF) 中的应用程序?

标签 c# openxml npoi

解压缩使用 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中的应用信息?

我只找到了 CorePropertiesCustomPropertiesExtendedProperties,但没有找到“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/

相关文章:

c# - 合并2个foreach循环(删除具有特定扩展名的文件)

c# - 引入静态方法

c# - NPOI Excel/C# 需要公式以编程方式更改条件格式的背景

C# Bouncy CaSTLe 无法解密,异常 : pad block corrupted

c# - Windows Phone 8.1 中的录像机应用程序

c# - 此上下文中不存在名称 SpaceProcessingModeValues

excel - 什么表明 Office Open XML 单元格包含日期/时间值?

c# - 使用 OpenXML SDK 在 Excel 电子表格中创建单元格注释

c# - NPOI 将字体应用于整行单元格

c# - 生成Excel(xlsx)时如何在列之前设置一行