A Microsoft® Excel dokumentum metaadatainak kezelése a C++ számon keresztül

Egyéni és beépített Excel-dokumentumtulajdonságok megtekintése, beszúrása, frissítése, eltávolítása vagy kibontása a C++ alkalmazásokon belül.

 

Metaadatok az Excelben – Az Excel fájl metaadatainak megtekintése, beszúrása és eltávolítása. C++ Excel Library A faclitates könnyen elérhető, mivel támogatja a beépített / rendszer által meghatározott tulajdonságokat, mint például a szerző neve, címe, dokumentumstatisztikái stb. név/érték párok. A folyamat automatizálása érdekében a könyvtár támogatja a nagy metaadat-fájlok létrehozását és karbantartását. Munkafüzet osztály Megnyitja a munkafüzetet elérési út, adatfolyam és speciális FileFormatType szerint. Tehát töltse be a fájlt a megfelelő módszerrel a további feldolgozáshoz. Az alább felsorolt lehetőségek közül néhány, és a fejlesztők könnyedén javíthatják kódjukat az alkalmazási követelményeknek megfelelően.

Olvassa el és frissítse a beépített tulajdonságokat

A beépített tulajdonságok automatizálását a API biztosítja GetBuiltInDocumentProperties() metódus, amely egy DocumentProperties gyűjteményt ad vissza, amely a táblázat összes beépített dokumentumtulajdonságát reprezentálja. Az összes beépített tulajdonság elérése után érje el a megfelelő tulajdonságokat a megfelelő metódusokkal, például GetTitle(), GetSubject() stb. A tulajdonságok frissítéséhez a API olyan metódust biztosít, mint a SetTitle, SetSubject, SetAuthor, SetComments stb. beépített dokumentumtulajdon-gyűjtemény a szükséges funkcióhoz.

C++ Kód a rendszer által meghatározott tulajdonságok olvasásához
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++ Kód a beépített tulajdonságok frissítéséhez
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();
 

Egyéni definiált tulajdonságok megtekintése és hozzáadása

Az egyéni tulajdonságok kezeléséhez a API rendelkezik Munkafüzet::GetCustomDocumentProperties amely visszaadja a táblázat összes egyéni dokumentumtulajdonság-gyűjteményét. Először is, ha ezzel a módszerrel hozzáférnek az egyéni tulajdonságokhoz, a fejlesztők megfelelő módszereket használhatnak olyan tulajdonságok hozzáadására, mint az AddIDocumentProperty, AddLinkToContentProperty, és hasonlóképpen az UpdateLinkedPropertyValue, UpdateLinkedRange segítségével frissíthetik az egyéni dokumentumtulajdonság értékét, amely a tartalomra, illetve a hivatkozott tartományra hivatkozik. A fejlesztők a megfelelő módszert használhatják egyéni dokumentumtulajdonságok gyűjteménye .

C++ Kód az egyéni tulajdonságok megtekintéséhez
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++ Kód a metaadatok hozzáadásához az Excel-fájlban
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();