Excel.CustomXmlPartCollection class
カスタム XML パーツのコレクション。
- Extends
注釈
プロパティ
context | オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。 |
items | このコレクション内に読み込まれた子アイテムを取得します。 |
メソッド
add(xml) | ブックに新しいカスタム XML パーツを追加します。 |
get |
名前空間が指定した名前空間に一致する、カスタム XML パーツの新しい範囲のコレクションを取得します。 |
get |
コレクション内のカスタム XML パーツの数を取得します。 |
get |
ID に基づいて、カスタム XML パーツを取得します。 |
get |
ID に基づいて、カスタム XML パーツを取得します。 |
load(options) | オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
load(property |
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、 |
toJSON() | API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript |
プロパティの詳細
context
オブジェクトに関連付けられている要求コンテキスト。 これにより、アドインのプロセスが Office ホスト アプリケーションのプロセスに接続されます。
context: RequestContext;
プロパティ値
items
メソッドの詳細
add(xml)
ブックに新しいカスタム XML パーツを追加します。
add(xml: string): Excel.CustomXmlPart;
パラメーター
- xml
-
string
XML コンテンツ。 有効な XML フラグメントである必要があります。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/18-custom-xml-parts/create-set-get-and-delete-custom-xml-parts.yaml
await Excel.run(async (context) => {
// You must have the xmlns attribute to populate the
// CustomXml.namespaceUri property.
const originalXml = "<Reviewers xmlns='http://schemas.contoso.com/review/1.0'><Reviewer>Juan</Reviewer><Reviewer>Hong</Reviewer><Reviewer>Sally</Reviewer></Reviewers>";
const customXmlPart = context.workbook.customXmlParts.add(originalXml);
customXmlPart.load("id");
const xmlBlob = customXmlPart.getXml();
await context.sync();
const readableXml = addLineBreaksToXML(xmlBlob.value);
$("#display-xml").text(readableXml);
// Store the XML part's ID in a setting.
const settings = context.workbook.settings;
settings.add("ContosoReviewXmlPartId", customXmlPart.id);
await context.sync();
});
getByNamespace(namespaceUri)
名前空間が指定した名前空間に一致する、カスタム XML パーツの新しい範囲のコレクションを取得します。
getByNamespace(namespaceUri: string): Excel.CustomXmlPartScopedCollection;
パラメーター
- namespaceUri
-
string
これは完全修飾スキーマ URI である必要があります。たとえば、"http://schemas.contoso.com/review/1.0"。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/18-custom-xml-parts/test-xml-for-unique-namespace.yaml
await Excel.run(async (context) => {
$("#display-xml").text("");
const contosoNamespace = "http://schemas.contoso.com/review/1.0";
const customXmlParts = context.workbook.customXmlParts;
const filteredXmlParts = customXmlParts.getByNamespace(contosoNamespace);
const numberOfPartsInNamespace = filteredXmlParts.getCount();
await context.sync();
if (numberOfPartsInNamespace.value == 1) {
const onlyXmlPartInNamespace = filteredXmlParts.getOnlyItem();
const xmlBlob = onlyXmlPartInNamespace.getXml();
await context.sync();
// Make it a bit more readable.
const readableXml = xmlBlob.value.replace(/></g, ">\n<");
$("#display-xml").text(`The only XML part in the namespace ${contosoNamespace} is:
${readableXml}`);
} else {
console.log(`There are ${numberOfPartsInNamespace.value} XML parts with namespace ${contosoNamespace}. There should be exactly 1.`);
}
await context.sync();
});
getCount()
コレクション内のカスタム XML パーツの数を取得します。
getCount(): OfficeExtension.ClientResult<number>;
戻り値
OfficeExtension.ClientResult<number>
注釈
getItem(id)
ID に基づいて、カスタム XML パーツを取得します。
getItem(id: string): Excel.CustomXmlPart;
パラメーター
- id
-
string
取得するオブジェクトの ID。
戻り値
注釈
例
// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/excel/18-custom-xml-parts/create-set-get-and-delete-custom-xml-parts.yaml
await Excel.run(async (context) => {
const settings = context.workbook.settings;
const xmlPartIDSetting = settings.getItemOrNullObject("ContosoReviewXmlPartId").load("value");
await context.sync();
if (xmlPartIDSetting.value) {
const customXmlPart = context.workbook.customXmlParts.getItem(xmlPartIDSetting.value);
// The setXml method does a whole-for-whole replacement
// of the entire XML.
customXmlPart.setXml("<Reviewers xmlns='http://schemas.contoso.com/review/1.0'><Reviewer>John</Reviewer><Reviewer>Hitomi</Reviewer></Reviewers>");
const xmlBlob = customXmlPart.getXml();
await context.sync();
const readableXml = addLineBreaksToXML(xmlBlob.value);
$("#display-xml").text(readableXml);
await context.sync();
}
});
getItemOrNullObject(id)
ID に基づいて、カスタム XML パーツを取得します。 CustomXmlPart
が存在しない場合、このメソッドは プロパティが に設定されたオブジェクトをisNullObject
true
返します。 詳細については、「 *OrNullObject メソッドとプロパティ」を参照してください。
getItemOrNullObject(id: string): Excel.CustomXmlPart;
パラメーター
- id
-
string
取得するオブジェクトの ID。
戻り値
注釈
load(options)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync()
を呼び出す必要があります。
load(options?: Excel.Interfaces.CustomXmlPartCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions): Excel.CustomXmlPartCollection;
パラメーター
- options
-
Excel.Interfaces.CustomXmlPartCollectionLoadOptions & Excel.Interfaces.CollectionLoadOptions
読み込むオブジェクトのプロパティのオプションを提供します。
戻り値
load(propertyNames)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync()
を呼び出す必要があります。
load(propertyNames?: string | string[]): Excel.CustomXmlPartCollection;
パラメーター
- propertyNames
-
string | string[]
読み込むプロパティを指定するコンマ区切り文字列または文字列の配列。
戻り値
load(propertyNamesAndPaths)
オブジェクトの指定されたプロパティを読み込むコマンドを待ち行列に入れます。 プロパティを読み取る前に、context.sync()
を呼び出す必要があります。
load(propertyNamesAndPaths?: OfficeExtension.LoadOption): Excel.CustomXmlPartCollection;
パラメーター
- propertyNamesAndPaths
- OfficeExtension.LoadOption
propertyNamesAndPaths.select
は、読み込むプロパティを指定するコンマ区切り文字列で propertyNamesAndPaths.expand
、読み込むナビゲーション プロパティを指定するコンマ区切りの文字列です。
戻り値
toJSON()
API オブジェクトが に渡されたときにより便利な出力を提供するために、JavaScript toJSON()
メソッドを JSON.stringify()
オーバーライドします。 (JSON.stringify
さらに、渡される オブジェクトの メソッドを呼び出 toJSON
します)。元 Excel.CustomXmlPartCollection
のオブジェクトは API オブジェクトですが、 toJSON
メソッドは、コレクションの項目から読み込まれたプロパティの浅いコピーを含む "items" 配列を含むプレーンな JavaScript オブジェクト (として Excel.Interfaces.CustomXmlPartCollectionData
型指定) を返します。
toJSON(): Excel.Interfaces.CustomXmlPartCollectionData;
戻り値
Office Add-ins
フィードバック
https://aka.ms/ContentUserFeedback」を参照してください。
以下は間もなく提供いたします。2024 年を通じて、コンテンツのフィードバック メカニズムとして GitHub の issue を段階的に廃止し、新しいフィードバック システムに置き換えます。 詳細については、「フィードバックの送信と表示