Beheer Microsoft® Excel-documentmetagegevens via C++

Aangepaste en ingebouwde Excel-documenteigenschappen bekijken, invoegen, bijwerken, verwijderen of extraheren binnen C++-applicaties.

 

Metagegevens in Excel - Metagegevens van Excel-bestanden bekijken, invoegen en verwijderen. C++ Excel-bibliotheek facilitates is op een eenvoudige manier door het ondersteunen van de ingebouwde / door het systeem gedefinieerde eigenschappen zoals auteursnaam, titel, documentstatistieken enz. die soms nodig zijn om te controleren wanneer het laatste bestand wordt gewijzigd of opgeslagen, samen met aangepaste / door de gebruiker gedefinieerde eigenschappen in de vorm van naam/waarde-paren. Om het proces te automatiseren ondersteunt de bibliotheek het maken en onderhouden van grote Excel-bestanden met metagegevens. Werkboek class Opent een werkmap op pad, op stream en op speciaal FileFormatType. Laad het bestand dus met de juiste methode voor verdere verwerking. Er zijn maar weinig van de onderstaande mogelijkheden en ontwikkelaars kunnen hun code eenvoudig verbeteren op basis van de toepassingsvereisten.

Ingebouwde eigenschappen lezen en bijwerken

Voor het automatiseren van de ingebouwde eigenschappen biedt API GetBuiltInDocumentProperties() methode die een DocumentProperties-verzameling retourneert die alle ingebouwde documenteigenschappen van het werkblad vertegenwoordigt. Nadat u toegang heeft gekregen tot alle ingebouwde eigenschappen, krijgt u toegang tot de relevante eigenschappen met behulp van de relevante methode zoals GetTitle(), GetSubject() enz. Om de eigenschappen bij te werken, biedt API methoden zoals SetTitle, SetSubject, SetAuthor, SetComments enz. Bekijk de ingebouwde documenteigenschapsverzameling voor de gewenste functie.

C++ Code om door het systeem gedefinieerde eigenschappen te lezen
Aspose::Cells::Startup();
//Source directory path
U16String dirPath = u"..\\Data\\LoadingSavingForMetadata\\";
//Paths of source and output excel files
U16String samplePath = dirPath + u"sample-metadata-properties.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();
std::cout << "Title: " << strTitle.ToUtf8() << std::endl;
std::cout << "Subject: " << strSubject.ToUtf8() << std::endl;
Aspose::Cells::Cleanup();
C++ Code om ingebouwde eigenschappen bij te werken
Aspose::Cells::Startup();
//Source directory path
U16String dirPath = u"..\\Data\\LoadingSavingForMetadata\\";
//Output directory path
U16String outPath = u"..\\Data\\Output\\";
//Paths of source and output excel files
U16String samplePath = dirPath + u"sample-metadata-properties.xlsx";
U16String outputPath = outPath + u"output-metadata-properties.xlsx";
//Load the sample excel file
Workbook wb(samplePath);
//Modify built-in title and subject properties
U16String strTitle = u"Aspose.Cells New Title";
U16String strSubject = u"Aspose.Cells New Subject";
wb.GetBuiltInDocumentProperties().SetTitle(strTitle);
wb.GetBuiltInDocumentProperties().SetSubject(strSubject);
//Save the output excel file
wb.Save(outputPath);
Aspose::Cells::Cleanup();
 

Bekijk en voeg op maat gedefinieerde eigenschappen toe

Voor het verwerken van aangepaste eigenschappen biedt API Werkmap::GetCustomDocumentProperties dat de volledige verzameling aangepaste documenteigenschappen van het werkblad retourneert. Door via deze methode toegang te krijgen tot de aangepaste eigenschappen, kunnen ontwikkelaars relevante methoden gebruiken om eigenschappen toe te voegen zoals AddIDocumentProperty, AddLinkToContentProperty en op dezelfde manier UpdateLinkedPropertyValue en UpdateLinkedRange gebruiken om de aangepaste documenteigenschapswaarde bij te werken die respectievelijk naar de inhoud en naar het gekoppelde bereik linkt. Ontwikkelaars kunnen de relevante methode gebruiken van verzameling aangepaste documenteigenschappen .

C++ Code om aangepaste eigenschappen te bekijken
Aspose::Cells::Startup();
//Source directory path
U16String dirPath = u"..\\Data\\LoadingSavingAndConverting\\";
//Paths of source and output excel files
U16String samplePath = dirPath + u"sample-metadata-properties.xlsx";
//Load the sample excel file
Workbook wb(samplePath);
//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;
Aspose::Cells::Cleanup();
C++ Code om metagegevens toe te voegen aan het Excel-bestand
Aspose::Cells::Startup();
//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"sample-metadata-properties.xlsx";
U16String outputPath = outPath + u"output-metadata-properties.xlsx";
//method 1
//Load the sample excel file
Workbook wb(samplePath);
//Add a new custom property
U16String strCustomPropName = u"MyCustom5";
U16String strCustomPropValue = u"This is my custom five.";
wb.GetCustomDocumentProperties().Add(strCustomPropName, strCustomPropValue);
//Save the output excel file
wb.Save(outputPath);
////method 2
////Load the sample excel file
//Metadata::MetadataOptions options(Metadata::MetadataType::Document_Properties);
//Metadata::WorkbookMetadata meta(samplePath, options);
////Add a new custom property
//meta.GetCustomDocumentProperties().Add(strCustomPropName, strCustomPropValue);
////Save the output excel file
//meta.Save(outputPath);
Aspose::Cells::Cleanup();