javascript - 如何
使用 Javascript Excel API 用换行符替换 XML
问题描述
我有一个电子表格,其中包含多个包含要删除的 XML 格式的单元格。问题是我不能只删除换行符,因为它会破坏文本的格式。如何<br />
用换行符替换?
function run() {
return Excel.run(function(context) {
const sheet1 = context.workbook.worksheets.getItem("Sheet1");
const sheet2 = context.workbook.worksheets.getItem("Sheet2");
const sourceCell = sheet1.getCell(1,1).load("text")
const destinationCell = sheet2.getCell(1,1)
return context.sync().then(function() {
destinationCell.values = sourceCell.text
})
})
}
假设我的 sourceCell 包含以下文本:
[["08:00 - 08:30 brushing teeth<br />08:30 - 09:00 eating breakfast<br />09:00 - 09:30 ride the bus"]]
我将如何<br />
在目标单元格中用换行符替换?
解决方案
range.values
接受二维数组,因此您可以解析字符串并将其剪切<br />
,将其分配给字符串数组
let mytexts : string[][];
// logic to cut the string based on <br/>
destinationCell.values = mytexts;
推荐阅读
- microsoft-graph-api - Microsoft Graph API - 无法以 endwith 过滤
- python - PyQt5 为每个组合框选项呈现不同的复选框集
- google-analytics - Google 跟踪代码管理器引荐主机名
- angular - 在角度使用 proxy.conf.json 是一个好习惯吗?
- mvvm-light - Windows Template Studio MVVMLight 从详细信息页面访问 ViewModel
- python - 不确定我的 Python/numpy 版本是否使用优化的 BLAS/LAPACK 库?
- c# - 在实体框架中插入多对多的链接表
- mysql - Laravel whereRaw 绑定运算符
- android - android SMS读取权限问题
- sas - sql到proc sql转换