翻譯|使用教程|編輯:李顯亮|2020-01-13 13:40:40.420|閱讀 332 次
概述:在本系列教程中,將為開發(fā)者帶來Aspose.Cells for .NET的一系列使用教程,例如關(guān)于加載保存轉(zhuǎn)換、字體、渲染、繪圖、智能標(biāo)記等等。本文將講解如何添加自定義XML部件并通過ID選擇它們。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
Aspose.Cells for .NET是Excel電子表格編程API,可加快電子表格管理和處理任務(wù),支持構(gòu)建具有生成,修改,轉(zhuǎn)換,呈現(xiàn)和打印電子表格功能的跨平臺應(yīng)用程序。
在接下來的系列教程中,將為開發(fā)者帶來Aspose.Cells for .NET的一系列使用教程,例如關(guān)于加載保存轉(zhuǎn)換、字體、渲染、繪圖、智能標(biāo)記等等。本文將講解如何添加自定義XML部件并通過ID選擇它們。
自定義XML部件是存儲在Microsoft Excel文檔中的XML數(shù)據(jù),供處理它們的應(yīng)用程序使用。目前尚無直接使用Microsoft Excel UI添加它們的方法。但是,可以通過各種方式以編程方式添加它們,例如,使用VSTO,使用Aspose.Cells等。如果要使用Aspose.Cells API添加自定義XML部件,請使用Workbook.CustomXmlParts.Add()方法。同時還可以使用CustomXmlPart.ID 屬性設(shè)置其ID 。同樣,如果要按ID選擇“自定義XML部件”,則可以使用 Workbook.CustomXmlParts.SelectByID()方法。
下面的示例代碼首先使用Workbook.CustomXmlParts.Add()方法添加四個Custom XML Parts。然后,使用CustomXmlPart.ID 屬性設(shè)置其ID。最后,它使用Workbook.CustomXmlParts.SelectByID()方法查找或選擇添加的自定義XML部件之一。
// Create empty workbook. Workbook wb = new Workbook(); // Some data in the form of byte array. // Please use correct XML and Schema instead. byte[] btsData = new byte[] { 1, 2, 3 }; byte[] btsSchema = new byte[] { 1, 2, 3 }; // Create four custom xml parts. wb.CustomXmlParts.Add(btsData, btsSchema); wb.CustomXmlParts.Add(btsData, btsSchema); wb.CustomXmlParts.Add(btsData, btsSchema); wb.CustomXmlParts.Add(btsData, btsSchema); // Assign ids to custom xml parts. wb.CustomXmlParts[0].ID = "Fruit"; wb.CustomXmlParts[1].ID = "Color"; wb.CustomXmlParts[2].ID = "Sport"; wb.CustomXmlParts[3].ID = "Shape"; // Specify search custom xml part id. String srchID = "Fruit"; srchID = "Color"; srchID = "Sport"; // Search custom xml part by the search id. Aspose.Cells.Markup.CustomXmlPart cxp = wb.CustomXmlParts.SelectByID(srchID); // Print the found or not found message on console. if (cxp == null) { Console.WriteLine("Not Found: CustomXmlPart ID " + srchID); } else { Console.WriteLine("Found: CustomXmlPart ID " + srchID); }
同時還可以參閱下面給出的代碼的控制臺輸出以供參考。
Found: CustomXmlPart ID Sport
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請郵件反饋至chenjj@fc6vip.cn