管理文档属性
Contents
[
Hide
]
可能的使用场景
Aspose.Cells 允许您使用内置和自定义文档属性。下面是Microsoft打开这些的Excel界面文档属性.只需点击高级属性如屏幕截图所示并查看它们。
管理文档属性
下面的示例代码加载示例 excel 文件并读取内置文档属性,例如标题、主题然后改变它们。然后它还读取自定义文档属性即我的自定义1然后添加一个新的自定义文档属性即我的自定义5并写下输出excel文件.下面的截图展示了示例代码对示例excel文件的效果。
示例代码
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-C | |
//Source directory path | |
StringPtr dirPath = new String("..\\Data\\LoadingSavingAndConverting\\"); | |
//Output directory path | |
StringPtr outPath = new String("..\\Data\\Output\\"); | |
//Paths of source and output excel files | |
StringPtr samplePath = dirPath->StringAppend(new String(L"sampleManagingDocumentProperties.xlsx")); | |
StringPtr outputPath = outPath->StringAppend(new String(L"outputManagingDocumentProperties.xlsx")); | |
//Load the sample excel file | |
intrusive_ptr<IWorkbook> wb = Factory::CreateIWorkbook(samplePath); | |
//Read built-in title and subject properties | |
StringPtr strTitle = wb->GetIBuiltInDocumentProperties()->GetTitle(); | |
StringPtr strSubject = wb->GetIBuiltInDocumentProperties()->GetSubject(); | |
StringPtr title = new String("Title: "); | |
Console::WriteLine(title->StringAppend(strTitle)); | |
StringPtr subject = new String("Subject: "); | |
Console::WriteLine(subject->StringAppend(strSubject)); | |
//Modify built-in title and subject properties | |
strTitle = new String("Aspose.Cells New Title"); | |
strSubject = new String("Aspose.Cells New Subject"); | |
wb->GetIBuiltInDocumentProperties()->SetTitle(strTitle); | |
wb->GetIBuiltInDocumentProperties()->SetSubject(strSubject); | |
//Read the custom property | |
StringPtr strCustomPropName = new String("MyCustom1"); | |
StringPtr strCustomPropValue = wb->GetICustomDocumentProperties()->GetObjectByIndex(strCustomPropName)->ToString(); | |
StringPtr myCustom1 = new String("\r\nMyCustom1: "); | |
Console::WriteLine(myCustom1->StringAppend(strCustomPropValue)); | |
//Add a new custom property | |
strCustomPropName = new String("MyCustom5"); | |
strCustomPropValue = new String("This is my custom five."); | |
wb->GetICustomDocumentProperties()->AddIDocumentProperty(strCustomPropName, strCustomPropValue); | |
//Save the output excel file | |
wb->Save(outputPath); |
控制台输出
这是使用提供的执行时上述示例代码的控制台输出示例 excel 文件.
Title: Aspose Team
Subject: Aspose.Cells for C++
MyCustom1: This is my custom one.