Managing Document Properties

Possible Usage Scenario

Aspose.Cells allows you to work with Built-In and Custom document properties. Here is the Microsoft Excel interface to open these Document Properties. Just click on the Advanced Properties as shown in this screenshot and view them.

todo:image_alt_text

Managing Document Properties

The following sample code loads sample excel file and reads the built-in document properties e.g. Title, Subject and then changes them. Then it also reads the custom document property i.e. MyCustom1 and then adds a new custom document property i.e. MyCustom5 and writes the output excel file. The following screenshot shows the effect of the sample code on the sample excel file.

todo:image_alt_text

Sample Code

//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);

Console Output

This is the console output of the above sample code when executed with the provided sample excel file.

 Title: Aspose Team

Subject: Aspose.Cells for C++

MyCustom1: This is my custom one.