Hantera Microsoft® Excel-dokumentmetadata via C++

Visa, infoga, uppdatera, ta bort eller extrahera anpassade och inbyggda Excel-dokumentegenskaper i C++-applikationer.

 

Metadata i Excel - Hur man visar, infogar och tar bort excelfilens metadata. C++ Excel-bibliotek faclitates är på ett enkelt sätt genom att stödja de inbyggda / systemdefinierade egenskaperna såsom författarens namn, titel, dokumentstatistik etc som behövs någon gång som att kontrollera när den sista filen ändras eller sparas tillsammans med anpassade / användardefinierade egenskaper i form av namn/värdepar. För att automatisera processen stöder biblioteket att skapa och underhålla stora Excel-filer med metadata. Arbetsbok class Öppnar en arbetsbok efter sökväg, efter ström och efter speciell filformattyp. Så ladda filen med lämplig metod för vidare bearbetning. Få av de möjligheter som listas nedan och utvecklare kan enkelt förbättra sin kod enligt applikationskrav.

Läs och uppdatera inbyggda egenskaper

För automatisering av de inbyggda egenskaperna tillhandahåller API GetBuiltInDocumentProperties() metod som returnerar en DocumentProperties-samling som representerar alla inbyggda dokumentegenskaper i kalkylarket. Efter att ha kommit åt alla inbyggda egenskaper, få åtkomst till de relevanta egenskaperna med relevant metod som GetTitle(), GetSubject() etc. För att uppdatera egenskaperna tillhandahåller API metoder som SetTitle, SetSubject, SetAuthor, SetComments etc. Visa inbyggd dokumentegendomssamling för önskad funktion.

C++ Kod för att läsa systemdefinierade egenskaper
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++ Kod för att uppdatera inbyggda egenskaper
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();
 

Visa och lägg till anpassade definierade egenskaper

För hantering av anpassade egenskaper tillhandahåller API Arbetsbok::GetCustomDocumentProperties som returnerar alla anpassade dokumentegenskaper i kalkylarket. För det första, genom att komma åt de anpassade egenskaperna via den här metoden, kan utvecklare använda relevanta metoder för att lägga till egenskaper som AddIDocumentProperty, AddLinkToContentProperty och på liknande sätt använda UpdateLinkedPropertyValue, UpdateLinkedRange för att uppdatera anpassat dokumentegenskapsvärde som länkar till innehåll respektive till länkat intervall. Utvecklare kan använda relevant metod från samling av anpassade dokumentegenskaper .

C++ Kod för att visa anpassade egenskaper
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++ Kod för att lägga till metadata i Excel-fil
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();