我正在开发 OnlyOffice 服务器集成以使用自定义插件,该插件将用于在文档、电子表格和演示文稿中生成图表和表格。
添加表格时,我无法将格式应用于特定单元格,例如粗体和颜色。
我尝试了以下方法向单元格添加粗体设置,但没有运气......
选项1
sScript += 'var oTable,oTableStyle, oCell, oTableRow, oParagraph, oRun, oTableRowPr;';
sScript += 'oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");';
sScript += 'oTable = Api.CreateTable(4,' + rowCnt + ');';
sScript += 'oTable.SetWidth("percent", 100);';
for (var iRow = 0; iRow < rowCnt ; iRow++) {
sScript += 'oTableRow = oTable.GetRow(' + iRow + ');';
for (var iCol = 0; iCol < 4; iCol++) {
sScript += 'oCell = oTableRow.GetCell(' + iCol + ');';
sScript += 'oParagraph = oCell.GetContent().GetElement(0)';
sScript += 'oRun = Api.CreateRun();';
sScript += 'oRun.SetBold(true);';
sScript += 'oRun.AddText("Test Element");';
sScript += 'oParagraph.AddElement(oRun);';
}
}
选项 2
sScript += 'var oTable,oTableStyle, oCell, oTableRow, oParagraph, oRun, oTableRowPr;';
sScript += 'oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");';
sScript += 'oTable = Api.CreateTable(4,' + rowCnt + ');';
sScript += 'oTable.SetWidth("percent", 100);';
for (var iRow = 0; iRow < rowCnt ; iRow++) {
sScript += 'oTableRow = oTable.GetRow(' + iRow + ');';
for (var iCol = 0; iCol < 4; iCol++) {
sScript += 'oCell = oTableRow.GetCell(' + iCol + ');';
sScript += ' oCell.GetContent().GetElement(0).SetBold(true);';
sScript += 'oCell.GetContent().GetElement(0).AddText("Firm Name");';
}
}
请指导..