google-apps-script - 有没有办法在保留文本格式的同时替换 TextBox 形状内的文本?
问题描述
我正在尝试替换幻灯片文本框中的文本,同时保留先前文本的文本格式。有没有办法使用谷歌应用程序脚本方法来工作?
我尝试将 Google 幻灯片转换为 PDF,然后转换为 DOC 以获取 HTML 值,以便我可以以某种方式保留文本格式。虽然转换工作,但我被困在必须替换 TextBox 中的文本同时保留原始文本格式的部分。
到目前为止,这就是我所拥有的:
function replacePresentationContent(presentationCopyId, slideId, shapeId, content) {
var presentationCopy = SlidesApp.openById(presentationCopyId);
var slidesCopy = presentationCopy.getSlides();
for (var i = 0; i < this.getSlidesCount(presentationCopy); i++) {
var slideCopy = slidesCopy[i];
var slidesCopyId = slideCopy.getObjectId();
var shapesCopy = slideCopy.getShapes();
if (slidesCopyId === slideId) {
for (var j = 0; j < shapesCopy.length; j++) {
if (shapesCopy[j].getObjectId() === shapeId) {
var textRange = shapesCopy[j].getText();
textRange.setText(content);
}
}
}
}
}
解决方案
您可以通过以下方式操作形状的文本来做到这一点:
var shape = slide.getShapes()[0]; //Change this to get the Shape you want
shape.getText().setText("The new text you want here, but with the same formatting!");
希望这可以帮助!
推荐阅读
- flutter - 为什么横幅广告没有加载到我的颤振应用程序中?
- python - 如何在 Kivy 界面中显示变量文本
- php - 如何在多层次营销中显示2级和3级的推荐
- omnet++ - 为什么车辆数量不增加静脉?
- database - Neo4J 服务器没有停止
- html - 引导程序 - 卡片
- flutter - 如何保存从 filepicker_windows 中选择的文件到磁盘(Flutter Desktop)
- python - 如何在 Python3 中访问以下列表和字典值?
- python - 我的脚本在hotels.com 中获得了一个子页面的网址,但该网址又回到了以前的状态
- javascript - keyup 事件未从 textarea 触发