0

我有一个单元格对象,我想向它添加文本。我试图打电话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;
}
4

0 回答 0