カスタムXMLパーツの追加およびIDでの選択
Contents
[
Hide
]
可能な使用シナリオ
カスタムXMLパーツは、Microsoft Excelドキュメント内に保存され、これらを扱うアプリケーションで使用されるXMLデータです。現在、Microsoft ExcelのUIを使用して直接追加する方法はありません。ただし、プログラム的にVSTOやAspose.Cellsなどを利用して追加できます。Aspose.Cells for Python via .NET APIを使用してカスタムXMLパーツを追加するには、Workbook.custom_xml_parts.add()メソッドを使用してください。また、CustomXmlPart.idプロパティを使ってIDを設定できます。同様に、IDでカスタムXMLパーツを選択するにはWorkbook.custom_xml_parts.select_by_id()メソッドを使用します。
カスタムXMLパーツの追加およびIDでの選択
以下のサンプルコードは、まずWorkbook.custom_xml_parts.add()メソッドを使用して4つのカスタムXMLパーツを追加します。次にCustomXmlPart.idプロパティを使用してそれらのIDを設定します。最後にWorkbook.custom_xml_parts.select_by_id()メソッドを使用して追加されたカスタムXMLパーツの1つを検索または選択します。以下のコードのコンソール出力も参照してください。
サンプルコード
This file contains hidden or 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
from aspose.cells import Workbook | |
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET | |
# Create empty workbook. | |
wb = Workbook() | |
# Some data in the form of byte array. | |
# Please use correct XML and Schema instead. | |
btsData = [1, 2, 3 ] | |
btsSchema = [1, 2, 3 ] | |
# Create four custom xml parts. | |
wb.custom_xml_parts.add(btsData, btsSchema) | |
wb.custom_xml_parts.add(btsData, btsSchema) | |
wb.custom_xml_parts.add(btsData, btsSchema) | |
wb.custom_xml_parts.add(btsData, btsSchema) | |
# Assign ids to custom xml parts. | |
wb.custom_xml_parts[0].id = "Fruit" | |
wb.custom_xml_parts[1].id = "Color" | |
wb.custom_xml_parts[2].id = "Sport" | |
wb.custom_xml_parts[3].id = "Shape" | |
# Specify search custom xml part id. | |
srchID = "Fruit" | |
srchID = "Color" | |
srchID = "Sport" | |
# Search custom xml part by the search id. | |
cxp = wb.custom_xml_parts.select_by_id(srchID) | |
# Print the found or not found message on console. | |
if cxp == None: | |
print("Not Found: CustomXmlPart ID " + srchID) | |
else: | |
print("Found: CustomXmlPart ID " + srchID) | |
print("AddCustomXMLPartsAndSelectThemByID executed successfully.") |
コンソール出力
Found: CustomXmlPart ID Sport