Gestisci i metadati del documento Excel Microsoft® tramite C++

Visualizza, inserisci, aggiorna, rimuovi o estrai proprietà di documenti Excel personalizzate e integrate all'interno delle applicazioni C++.

 

Metadati in Excel: come visualizzare, inserire e rimuovere i metadati dei file Excel. C++ Libreria Excel faclitates è semplice supportando le proprietà integrate/definite dal sistema come nome dell’autore, titolo, statistiche del documento, ecc. necessarie a volte come controllare quando l’ultimo file viene modificato o salvato insieme alle proprietà personalizzate/definite dall’utente sotto forma di coppie nome/valore. Per automatizzare il processo, la libreria supporta la creazione e la gestione di file Excel di metadati di grandi dimensioni. Cartella di lavoro class Apre una cartella di lavoro per percorso, per flusso e per FileFormatType speciale. Quindi carica il file con il metodo appropriato per l’ulteriore elaborazione. Sono poche le possibilità elencate di seguito e gli sviluppatori possono facilmente migliorare il proprio codice in base ai requisiti dell’applicazione.

Leggere e aggiornare le proprietà integrate

Per automatizzare le proprietà integrate, fornisce API GetBuiltInDocumentProperties() metodo che restituisce una raccolta DocumentProperties che rappresenta tutte le proprietà del documento integrate nel foglio di calcolo. Dopo aver effettuato l’accesso a tutte le proprietà integrate, accedere alle proprietà pertinenti utilizzando il metodo pertinente come GetTitle(), GetSubject() ecc. Per aggiornare le proprietà, API fornisce metodi come SetTitle, SetSubject, SetAuthor, SetComments ecc. Visualizza il raccolta di proprietà del documento incorporata per la funzione richiesta.

C++ Codice per leggere le proprietà definite dal sistema
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++ Codice per aggiornare le proprietà integrate
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();
 

Visualizza e aggiungi proprietà personalizzate

Per la gestione delle proprietà personalizzate, fornisce API Cartella di lavoro::GetCustomDocumentProperties che restituisce tutta la raccolta di proprietà del documento personalizzato del foglio di calcolo. Accedendo innanzitutto alle proprietà personalizzate tramite questo metodo, gli sviluppatori possono utilizzare metodi pertinenti per aggiungere proprietà come AddIDocumentProperty, AddLinkToContentProperty e utilizzare in modo simile UpdateLinkedPropertyValue, UpdateLinkedRange per aggiornare il valore della proprietà del documento personalizzato che si collega rispettivamente al contenuto e all’intervallo collegato. Gli sviluppatori possono utilizzare il metodo pertinente da raccolta di proprietà del documento personalizzate .

C++ Codice per visualizzare le proprietà personalizzate
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++ Codice per aggiungere metadati nel file Excel
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();