Word 表格跨页 单元格赋值问题

阅读次数 83

当前页高度不够 表格赋值会报错 await app.ActiveDocument.ActiveWindow.Selection.InsertBreak(app.Enum.WdBreakType.wdTextWrappingBreak); 无效

1 Answers

你好,我们测试过并没有复现,方便的话可以将插入表格和表格赋值的相关代码脱敏后贴出来,这样有利于排查问题,谢谢~

async function insertTable(item) { const app = jssdk.Application;
let req = await axios.get('xxx', { params: { id: item.id, bglx: item.bglx } });
let { records, code } = req.data;
// 返回数据
let data = records.rows;
if (data.length > 0 && code > 0) {
await app.ActiveDocument.ActiveWindow.Selection.InsertBreak(app.Enum.WdBreakType.wdTextWrappingBreak);
const stack = app.Stack();
// 获取所有表格
const tables = await app.ActiveDocument.Tables;
const range = app.ActiveDocument.ActiveWindow.Selection.Range;
// 插入表格
let thisTable = await tables.Add(
range, // 位置信息
data.length, // 新增表格的行数
data[0].length, // 新增表格的列数
1, // 启用自动调整功能
1, // 根据表格中包含的内容自动调整表格的大小
);
for (let row = 0; row < data.length; row++) {
let rowObj = await thisTable.Rows.Item(row + 1);
for (let cell = 0; cell < data[row].length; cell++) {
let cellObj = await rowObj.Cells.Item(cell + 1);
try {
const range = await cellObj.Range;
range.Text = data[row][cell].text;
let start = 0;
let end = 0;

                                            if (range) {
                                                start = await range.Start;
                                                end = await range.End;
                                            }

                                            const font = await app.ActiveDocument.Range(start, end).Font;
                                            font.Size = data[row][cell].size;
                                            font.Bold = data[row][cell].bold;
                                        } catch (e) {
                                            console.log(e);
                                        }
                                    }
                                }
                                await app.ActiveDocument.ActiveWindow.Selection.MoveDown()
                                stack.End();
                            }
                        }