跳到主要内容

SetNodeValue

设置当前节点的 XML 内容。

语法

expression.SetNodeValue(xml);

expression - 表示 ApiCustomXmlNode 类的变量。

参数

名称必需/可选数据类型默认值描述
xml必需string要设置为当前节点内容的 XML 字符串。

返回值

boolean

示例

向 XML 节点写入新值以更新电子表格中的存储数据。

// How do I change the value held by an XML node in a spreadsheet?

// Replace an existing node's content with fresh data in a spreadsheet.

const worksheet = Api.GetActiveSheet();
const xmlManager = worksheet.GetCustomXmlParts();
const xmlString = `
<bookstore>
<book>
<title>The Odyssey</title>
<author>Homer</author>
</book>
</bookstore>`;
const xml = xmlManager.Add(xmlString);

const bookNode = xml.GetNodes('/bookstore/book')[0];
bookNode.SetNodeValue('<book>Updated content</book>');
worksheet.GetRange('A1').SetValue('XML after update:');
worksheet.GetRange('B1').SetValue(xml.GetXml());