Gestione delle proprietà del documento

Possibile scenario di utilizzo

Aspose.Cells consente di lavorare con le proprietà del documento integrate e personalizzate. Ecco l’interfaccia Excel Microsoft per aprirliProprietà del documento . Basta cliccare sulProprietà avanzatecome mostrato in questo screenshot e visualizzarli.

cose da fare:immagine_alt_testo

Gestione delle proprietà del documento

Viene caricato il codice di esempio seguentefile excel di esempio e legge le proprietà del documento integrate, ad esTitolo, Soggetto e poi li cambia. Quindi legge anche la proprietà del documento personalizzato, ad esMyCustom1 e quindi aggiunge una nuova proprietà del documento personalizzata, ad esMyCustom5 e scrive ilfile excel di output. Lo screenshot seguente mostra l’effetto del codice di esempio sul file excel di esempio.

cose da fare:immagine_alt_testo

Codice d’esempio

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

Uscita console

Questo è l’output della console del codice di esempio precedente quando viene eseguito con il metodo fornitofile excel di esempio.

 Title: Aspose Team

Subject: Aspose.Cells for C++

MyCustom1: This is my custom one.