Gestion des propriétés de 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 Microsoft Excel pour ouvrir ces propriétés de document. Cliquez simplement sur Propriétés avancées comme indiqué dans cette capture d’écran et visualisez-les.
Gestion des propriétés du document
Le code d’exemple suivant charge un fichier Excel d’exemple et lit les propriétés de document intégrées telles que Titre, Sujet puis les modifie. Ensuite, il lit également la propriété de document personnalisée, c’est-à-dire MyCustom1 puis ajoute une nouvelle propriété de document personnalisée, c’est-à-dire MyCustom5 et écrit le fichier Excel de sortie. La capture d’écran suivante montre l’effet du code d’exemple sur le fichier Excel d’exemple.
Code d’exemple
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(); |
Sortie console
Il s’agit de la sortie de la console du code d’exemple ci-dessus lorsqu’il est exécuté avec le fichier Excel d’exemple fourni.
Title: Aspose Team
Subject: Aspose.Cells for C++
MyCustom1: This is my custom one.