在 Aspose.Cells 中使用自定义 XML 部件
Contents
[
Hide
]
自定义 XML 部分是 XML 数据,由不同的应用程序(如 SharePoint 等)存储在 excel 文件中。此数据由需要它的不同应用程序使用。 Microsoft Excel 不使用此数据,因此没有用于添加它的 GUI。您可以通过更改扩展名来查看此数据**.xlsx**进入**。压缩**然后使用打开它**WinRAR** .数据存在于**自定义XML**文件夹,如图所示。
您可以使用 Aspose.Cells 通过[Workbook.getContentTypeProperties().add()](https://reference.aspose.com/cells/java/com.aspose.cells/contenttypepropertycollection#add(java.lang.Object)) 方法。
在 Aspose.Cells 中使用自定义 Xml 部件
下面的示例代码使用了[Workbook.getContentTypeProperties().add()](https://reference.aspose.com/cells/java/com.aspose.cells/contenttypepropertycollection#add(java.lang.Object) 方法并添加图书目录 Xml它的名字是书店.下图显示了这段代码的结果。如您所见,Book Catalog Xml 添加到 BookStore 节点中,这是此属性的名称。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(UsingCustomXmlParts.class); | |
String booksXML = "<catalog><book><title>Complete C#</title><price>44</price></book><book><title>Complete Java</title><price>76</price></book><book><title>Complete SharePoint</title><price>55</price></book><book><title>Complete PHP</title><price>63</price></book><book><title>Complete VB.NET</title><price>72</price></book></catalog>"; | |
Workbook workbook = new Workbook(); | |
workbook.getContentTypeProperties().add("BookStore", booksXML); | |
workbook.save(dataDir + "output.xlsx"); |