จัดการ Microsoft® ข้อมูลเมตาของไฟล์ Excel via .NET

ดู เพิ่ม อัปเดต ลบ หรือแยกคุณสมบัติไฟล์ Excel ในตัวและแบบกำหนดเองโดยใช้ API ฝั่งเซิร์ฟเวอร์ .NET

 

.NET เอกเซล API รองรับการจัดการคุณสมบัติที่ระบบกำหนด (ในตัว) เช่น ชื่อเรื่อง ชื่อผู้แต่ง สถิติเอกสาร ฯลฯ รวมถึงคุณสมบัติที่ผู้ใช้กำหนด (กำหนดเอง) ในรูปแบบของคู่ชื่อ-ค่า มี ชั้นเรียนสมุดงาน เพื่อโหลดไฟล์และ แผ่นงานคอลเลกชัน เกี่ยวข้องกับการรวบรวมแผ่นงานเช่นกัน ชั้นเรียนแผ่นงาน สำหรับแสดงแผ่นงานเดี่ยว นอกจากคลาสเหล่านี้แล้ว BuiltInDocumentProperties แล้ว CustomDocumentProperties ยังทำให้กระบวนการสำหรับการจัดการข้อมูลเมตาเป็นเรื่องง่าย

การจัดการคุณสมบัติบิวท์อิน

สำหรับการจัดการคุณสมบัติที่ระบบกำหนด API จัดให้ คุณสมบัติเอกสารในตัว และโปรแกรมเมอร์สามารถเข้าถึงคุณสมบัติในตัวและอัปเดตค่าของมันได้อย่างง่ายดาย ขึ้นอยู่กับข้อกำหนดของแอปพลิเคชัน นักพัฒนาสามารถใช้ดัชนีหรือชื่อคุณสมบัติจาก DocumentPropertyCollection .

C# รหัสเพื่อจัดการคุณสมบัติบิวท์อิน
//Create workbook object.
Workbook wb = new Workbook();
//Access system defined document property collection.
Aspose.Cells.Properties.BuiltInDocumentPropertyCollection sdmd = wb.BuiltInDocumentProperties;
//Set the language of the Excel document.
sdmd.Language = "German, French";
//Save the workbook in xlsx format.
wb.Save(outputDir + "system-defined-properties-updated.xlsx", SaveFormat.Xlsx);
 

การจัดการคุณสมบัติที่กำหนดแบบกำหนดเอง

สำหรับการจัดการคุณสมบัติที่ผู้ใช้กำหนด API จัดให้ คุณสมบัติเอกสารแบบกำหนดเอง และนักพัฒนาสามารถเข้าถึงคุณสมบัติที่เพิ่มไว้แล้วรวมทั้งเพิ่มคุณสมบัติใหม่ได้อย่างง่ายดาย ในการเพิ่มคุณสมบัติที่กำหนดเอง เพิ่มวิธีการ ของ CustomDocumentPropertyCollection คลาสเพิ่มคุณสมบัติและส่งกลับการอ้างอิงสำหรับคุณสมบัติใหม่เป็น Properties.DocumentProperty วัตถุ. คลาส DocumentProperty ใช้เพื่อดึงชื่อ ค่า และประเภทของคุณสมบัติเอกสารเป็น DocumentProperty.ชื่อ , DocumentProperty.Value , DocumentProperty.Type ที่ส่งกลับค่าใดค่าหนึ่ง ประเภทอสังหาริมทรัพย์ ค่าแจงนับ

C# โค้ดสำหรับเพิ่ม Metadata ในไฟล์ Excel
// string dataDir = "he path to the documents directory."
// Instantiate a Workbook object
// Open an Excel file
Workbook wkb = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.CustomDocumentPropertyCollection customProperties = wkb.Worksheets.CustomDocumentProperties;
// Adding a custom document property to the Excel file
Aspose.Cells.Properties.DocumentProperty publisher = customProperties.Add("Publisher", "Aspose");
// Add link to content.
customProperties.AddLinkToContent("Owner", "MyRange");
// way to access custom property by using the property name
Aspose.Cells.Properties.DocumentProperty customProperty1 = customProperties["Owner"];
// Saving resultant spreadsheet
wkb.Save(dataDir + "out_sample-document-properties.xlsx");
C# รหัสเพื่อลบคุณสมบัติที่กำหนดเองในไฟล์ Excel
//string dataDir = "The path to the documents directory";
// Instantiate a Workbook object
// Open an Excel file
Workbook wkb = new Workbook(dataDir + "sample-document-properties.xlsx");
// Retrieve a list of all custom document properties of the Excel file
Aspose.Cells.Properties.DocumentPropertyCollection customProperties = wkb.Worksheets.CustomDocumentProperties;
// Removing a custom document property
customProperties.Remove("Publisher");
// Save the file
wkb.Save(dataDir + "out_sample-document-properties.xlsx");