Excel管理控件Aspose.Cells开发者指南(二十二):添加自定义XML部件并通过ID选择它们


第五章:关于工作簿的使用

▲第一节:添加自定义XML部件并通过ID选择它们

自定义XML部件是存储在Microsoft Excel文档中的XML数据,供处理它们的应用程序使用。目前尚无直接使用Microsoft Excel UI添加它们的方法。但是,可以通过各种方式以编程方式添加它们,例如,使用VSTO,使用Aspose.Cells等。如果要使用Aspose.Cells API添加自定义XML部件,请使用Workbook.CustomXmlParts.Add()方法。同时还可以使用CustomXmlPart.ID 属性设置其ID 。同样,如果要按ID选择“自定义XML部件”,则可以使用 Workbook.CustomXmlParts.SelectByID()方法。

下面的示例代码首先使用Workbook.CustomXmlParts.Add()方法添加四个Custom XML Parts。然后,使用CustomXmlPart.ID 属性设置其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


还想要更多吗可以点击阅读【2019 · Aspose最新资源整合】查找需要的教程资源。如果您有任何疑问或需求,请随时加入Aspose技术交流群(),我们很高兴为您提供查询和咨询
标签:

声明:本站部分文章及图片源自用户投稿,如本站任何资料有侵权请您尽早请联系jinwei@zod.com.cn进行处理,非常感谢!

上一篇 2020年1月10日
下一篇 2020年1月10日

相关推荐

发表回复

登录后才能评论