如何解决尝试插入文本,如何找到特定对象所在的文档?
我有一个单元格对象,我想向其中添加文本。我正在尝试调用 doc.AddText(textLoc,'cell text');
,但我没有 doc
对象,我只有 cell
对象。
function setCellText(cell,text) {
// Create a text location at the beginning of the cell
var textLoc = new TextLoc();
textLoc.obj = cell;
textLoc.offset = 0;
// Delete all the paragraphs after the first (new) paragraph
while (cell.FirstPgf.id != cell.LastPgf.id) {
cell.LastPgf.Delete();
}
cell.LastPgf.Delete();
// Write the specified cell value to the text location
doc.AddText(textLoc,text); // <== !! How do I get the doc for the current cell?
}
与其为调用 statck 中的每个函数添加一个 doc
参数,我更希望能够从单元格本身确定 doc
。我有一些代码可以查找对象所在的页面,但我不知道如何在此过程中的任何地方访问父文档。
在更高级别上,是否有比 doc.AddText
更好的替代方法向单元格添加文本?我怀疑不是,但以防万一。
fucntion getDoc(obj) {
// ???
}
function getPage(obj) {
if (obj.PageFramePage != undefined && obj.PageFramePage.ObjectValid())
return obj.PageFramePage;
if (obj.FrameParent != undefined && obj.FrameParent.ObjectValid())
return obj.FrameParent.getPage();
if (obj.InTextFrame != undefined && obj.InTextFrame.ObjectValid())
return obj.InTextFrame.getPage();
if (obj.TextLoc != undefined && obj.TextLoc != null)
return obj.TextLoc.obj.getPage();
return null;
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。