จัดการ Microsoft® ข้อมูลเมตาเอกสาร Excel ผ่าน C++

ดู แทรก อัปเดต ลบ หรือแยกคุณสมบัติเอกสาร Excel แบบกำหนดเองและในตัวภายในแอปพลิเคชัน C++

 

ข้อมูลเมตาใน Excel - วิธีดู แทรก และลบข้อมูลเมตาของไฟล์ Excel C++ เอ็กเซล ไลบรารี่ อำนวยความสะดวกด้วยวิธีง่ายๆ โดยรองรับคุณสมบัติในตัว / ที่ระบบกำหนด เช่น ชื่อผู้แต่ง ชื่อเรื่อง สถิติเอกสาร ฯลฯ ที่จำเป็นบางครั้ง เช่น ตรวจสอบว่าไฟล์สุดท้ายถูกแก้ไขหรือบันทึกเมื่อใด พร้อมด้วยคุณสมบัติแบบกำหนดเอง / ที่ผู้ใช้กำหนดในรูปแบบของ คู่ชื่อ/ค่า เพื่อให้กระบวนการเป็นอัตโนมัติ ไลบรารีรองรับการสร้างและดูแลรักษาไฟล์ Excel เมตาดาต้าขนาดใหญ่ สมุดงาน คลาสเปิดสมุดงานตามเส้นทางตามกระแสและตาม FileFormatType พิเศษ ดังนั้นให้โหลดไฟล์ด้วยวิธีที่เหมาะสมเพื่อการประมวลผลต่อไป ความเป็นไปได้บางประการตามรายการด้านล่าง และนักพัฒนาสามารถปรับปรุงโค้ดของตนได้อย่างง่ายดายตามความต้องการของแอปพลิเคชัน

อ่านและอัปเดตคุณสมบัติบิวท์อิน

สำหรับคุณสมบัติในตัวอัตโนมัติ API จัดให้ GetBuiltInDocumentProperties() วิธีการส่งคืนคอลเลกชัน DocumentProperties ที่แสดงคุณสมบัติเอกสารในตัวทั้งหมดของสเปรดชีต หลังจากเข้าถึงคุณสมบัติบิวท์อินทั้งหมดแล้ว ให้เข้าถึงคุณสมบัติที่เกี่ยวข้องโดยใช้วิธีการที่เกี่ยวข้อง เช่น GetTitle(), GetSubject() ฯลฯ หากต้องการอัปเดตคุณสมบัติ API จัดเตรียมวิธีการ เช่น SetTitle, SetSubject, SetAuthor, SetComments เป็นต้น ดู การรวบรวมคุณสมบัติเอกสารในตัว สำหรับฟังก์ชันที่ต้องการ

C++ รหัสเพื่ออ่านคุณสมบัติที่กำหนดโดยระบบ
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++ รหัสเพื่ออัพเดตคุณสมบัติบิวท์อิน
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();
 

ดูและเพิ่มคุณสมบัติที่กำหนดแบบกำหนดเอง

สำหรับการจัดการคุณสมบัติที่กำหนดเอง API จัดให้ สมุดงาน::GetCustomDocumentProperties ที่ส่งคืนคอลเลกชันคุณสมบัติเอกสารแบบกำหนดเองทั้งหมดของสเปรดชีต ประการแรก การเข้าถึงคุณสมบัติแบบกำหนดเองด้วยวิธีนี้ นักพัฒนาสามารถใช้วิธีการที่เกี่ยวข้องในการเพิ่มคุณสมบัติ เช่น AddIDocumentProperty, AddLinkToContentProperty และใช้ UpdateLinkedPropertyValue, UpdateLinkedRange ในทำนองเดียวกัน เพื่ออัปเดตค่าคุณสมบัติเอกสารแบบกำหนดเองซึ่งลิงก์ไปยังเนื้อหาและไปยังช่วงที่ลิงก์ตามลำดับ นักพัฒนาสามารถใช้วิธีการที่เกี่ยวข้องได้จาก การรวบรวมคุณสมบัติเอกสารที่กำหนดเอง .

C++ รหัสเพื่อดูคุณสมบัติที่กำหนดเอง
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++ โค้ดสำหรับเพิ่ม Metadata ในไฟล์ 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();