管理文档属性

可能的使用场景

Aspose.Cells 允许您使用内置和自定义文档属性。 这是打开这些 文档属性 的 Microsoft Excel 界面。 只需单击 高级属性,如此屏幕截图中所示,并查看它们。

todo:image_alt_text

管理文档属性

以下示例代码加载 示例 Excel 文件 并读取内置文档属性,例如 标题、主题,然后更改它们。 然后它还读取自定义文档属性,即 自定义1,然后添加新的自定义文档属性,即 自定义5,并写入 输出 Excel 文件。 以下屏幕截图显示了示例代码对示例 Excel 文件的影响。

todo:image_alt_text

示例代码

Aspose::Cells::Startup();
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C
//Source directory path
U16String dirPath(u"..\\Data\\LoadingSavingAndConverting\\");
//Output directory path
U16String outPath(u"..\\Data\\Output\\");
//Paths of source and output excel files
U16String samplePath(dirPath + u"sampleManagingDocumentProperties.xlsx");
U16String outputPath(outPath + u"outputManagingDocumentProperties.xlsx");
//Load the sample excel file
Workbook wb(samplePath);
//Read built-in title and subject properties
U16String strTitle = wb.GetBuiltInDocumentProperties().GetTitle();
U16String strSubject = wb.GetBuiltInDocumentProperties().GetSubject();
U16String title(u"Title: ");
std::cout << title.ToUtf8() << strTitle.ToUtf8() << std::endl;
U16String subject(u"Subject: ");
std::cout << subject.ToUtf8()<<strSubject.ToUtf8() << std::endl;
//Modify built-in title and subject properties
strTitle = u"Aspose.Cells New Title";
strSubject = u"Aspose.Cells New Subject";
wb.GetBuiltInDocumentProperties().SetTitle(strTitle);
wb.GetBuiltInDocumentProperties().SetSubject(strSubject);
//Read the custom property
U16String strCustomPropName(u"MyCustom1");
U16String strCustomPropValue = wb.GetCustomDocumentProperties().Get(strCustomPropName).ToString();
U16String myCustom1(u"\r\nMyCustom1: ");
std::cout << myCustom1.ToUtf8()<<strCustomPropValue.ToUtf8() << std::endl;
//Add a new custom property
strCustomPropName = u"MyCustom5";
strCustomPropValue = u"This is my custom five.";
wb.GetCustomDocumentProperties().Add(strCustomPropName, strCustomPropValue);
//Save the output excel file
wb.Save(outputPath);
Aspose::Cells::Cleanup();

控制台输出

这是上述示例代码在使用提供的 示例 Excel 文件 时执行的控制台输出。

 Title: Aspose Team

Subject: Aspose.Cells for C++

MyCustom1: This is my custom one.