Gestion des propriétés du document
Scénario d’utilisation possible
Aspose.Cells vous permet de travailler avec les propriétés de document intégrées et personnalisées. Voici l’interface Excel Microsoft pour ouvrir cesPropriétés du document . Cliquez simplement sur lePropriétés avancéescomme indiqué dans cette capture d’écran et affichez-les.
Gestion des propriétés du document
L’exemple de code suivant se chargeexemple de fichier excel et lit les propriétés de document intégrées, par exempleTitre, sujet puis les modifie. Ensuite, il lit également la propriété de document personnalisée, c’est-à-direMaPersonnalisée1 puis ajoute une nouvelle propriété de document personnalisée, c’est-à-direMaPersonnalisée5 et écrit lefichier excel de sortie. La capture d’écran suivante montre l’effet de l’exemple de code sur l’exemple de fichier Excel.
Exemple de 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); |
Sortie console
Il s’agit de la sortie console de l’exemple de code ci-dessus lorsqu’il est exécuté avec leexemple de fichier excel.
Title: Aspose Team
Subject: Aspose.Cells for C++
MyCustom1: This is my custom one.