Kelola Microsoft® Metadata Dokumen Excel melalui C++
Lihat, sisipkan, perbarui, hapus atau ekstrak properti dokumen Excel kustom dan bawaan dalam aplikasi C++.
Metadata di Excel - Cara melihat, menyisipkan dan menghapus metadata file excel. C++ Perpustakaan Excel memfasilitasi dengan cara yang mudah dengan mendukung properti bawaan / yang ditentukan sistem seperti nama penulis, judul, statistik dokumen, dll. Kadang-kadang diperlukan seperti memeriksa kapan file terakhir diubah atau disimpan bersama dengan properti khusus / yang ditentukan pengguna dalam bentuk pasangan nama/nilai. Untuk mengotomatiskan proses, perpustakaan mendukung pembuatan dan pemeliharaan file Excel metadata berukuran besar. Buku Kerja class Membuka buku kerja berdasarkan jalur, aliran, dan FileFormatType khusus. Jadi muat file dengan metode yang sesuai untuk diproses lebih lanjut. Beberapa kemungkinan tercantum di bawah ini dan pengembang dapat dengan mudah menyempurnakan kode mereka sesuai dengan kebutuhan aplikasi.
Baca dan Perbarui Properti Bawaan
Untuk mengotomatiskan properti bawaan, API menyediakan GetBuiltInDocumentProperties() metode yang mengembalikan koleksi DocumentProperties yang mewakili semua properti dokumen bawaan spreadsheet. Setelah mengakses semua properti bawaan, akses properti yang relevan menggunakan metode yang relevan seperti GetTitle(), GetSubject() dll. Untuk memperbarui properti, API menyediakan metode seperti SetTitle, SetSubject, SetAuthor, SetComments dll. Lihat koleksi properti dokumen bawaan untuk fungsi yang diperlukan.
C++ Kode untuk Membaca Properti Buatan Sistem
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++ Kode untuk Memperbarui Properti Bawaan
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(); |
Lihat dan Tambahkan Properti Buatan Khusus
Untuk menangani properti khusus, API menyediakan Buku Kerja::GetCustomDocumentProperties yang mengembalikan semua kumpulan properti dokumen kustom dari spreadsheet. Pertama-tama mengakses properti khusus melalui metode ini, pengembang dapat menggunakan metode yang relevan untuk menambahkan properti seperti AddIDocumentProperty, AddLinkToContentProperty dan juga menggunakan UpdateLinkedPropertyValue, UpdateLinkedRange untuk memperbarui nilai properti dokumen khusus yang masing-masing tertaut ke konten dan ke rentang tertaut. Pengembang dapat menggunakan metode yang relevan dari kumpulan properti dokumen khusus .
C++ Kode untuk Melihat Properti Kustom
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++ Kode untuk Menambahkan Metadata di 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(); |