1

我们正在尝试使用演示编辑器插件中的 ONLYOFFICE API 添加表格。我们可以使用文档编辑器轻松做到这一点,但无法找到演示方式。

我们尝试使用附加脚本插入表格,但它不起作用。我们也在 Document Builder 中尝试了相同的操作,但在创建文档时遇到了错误。

我们尝试了以下方法:

   oDocContent.InsertContent([oTable]); 

   oDocContent.Push(oTable);   

通过以下脚本,我们尝试在演示编辑器中插入一个表格。

脚本 1:

builder.CreateFile("pptx");
var oPresentation = Api.GetPresentation();
var oParagraphCell, oTable, oTableStyle, oCell, oTableRow, oParagraph;
var oSlide = oPresentation.GetSlideByIndex(0);
oSlide.RemoveAllObjects();
var oShape = Api.CreateShape("rect", 300 * 36000, 130 * 36000, oFill, oStroke);
oShape.SetPosition(608400, 1267200);
oDocContent = oShape.GetDocContent();
oParagraph = oDocContent.GetElement(0);
oParagraph.AddText("This is an example of the ppt.");
oParagraph = Api.CreateParagraph();
oDocContent.InsertContent([oParagraph]);
oTableStyle = oDocContent.CreateStyle("CustomTableStyle", "table");
oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered - Accent 5"));
oTable = Api.CreateTable(3, 3);
oTable.SetWidth("percent", 100);
oTableRow = oTable.GetRow(0);
oTableRow.SetHeight("atLeast", 1440);
oCell = oTable.GetRow(0).GetCell(0);
oCell.SetVerticalAlign("top");
oParagraphCell = oCell.GetContent().GetElement(0);
oParagraphCell.AddText("Align top");
oCell = oTable.GetRow(0).GetCell(1);
oCell.SetVerticalAlign("center");
oParagraphCell = oCell.GetContent().GetElement(0);
oParagraphCell.AddText("Align center");
oCell = oTable.GetRow(0).GetCell(2);
oCell.SetVerticalAlign("bottom");
oParagraphCell = oCell.GetContent().GetElement(0);
oParagraphCell.AddText("Align bottom");
oTable.SetStyle(oTableStyle);
oDocContent.InsertContent([oTable]);
oSlide.AddObject(oShape);
builder.SaveFile("pptx", "SampleText.pptx");
builder.CloseFile();

脚本 2:

builder.CreateFile("pptx");
var oPresentation = Api.GetPresentation();
var oParagraphCell, oTable, oTableStyle, oCell, oTableRow, oParagraph;
var oSlide = oPresentation.GetSlideByIndex(0);
oSlide.RemoveAllObjects();
oFill = Api.CreateSolidFill(Api.CreateRGBColor(61, 74, 107));
oStroke = Api.CreateStroke(0, Api.CreateNoFill());
var oShape = Api.CreateShape("rect", 300 * 36000, 130 * 36000, oFill, oStroke);
oShape.SetPosition(608400, 1267200);
oDocContent = oShape.GetDocContent();
oParagraph = oDocContent.GetElement(0);
oParagraph.AddText("This is an example of the ppt.");
oTableStyle = oDocContent.CreateStyle("CustomTableStyle", "table");
oTableStyle.SetBasedOn(oDocContent.GetStyle("Bordered - Accent 5"));
oTable = Api.CreateTable(3, 3);
oTable.SetWidth("percent", 100);
oTableRow = oTable.GetRow(0);
oTableRow.SetHeight("atLeast", 1440);
oCell = oTable.GetRow(0).GetCell(0);
oCell.SetVerticalAlign("top");
oParagraphCell = oCell.GetContent().GetElement(0);
oParagraphCell.AddText("Align top");
oCell = oTable.GetRow(0).GetCell(1);
oCell.SetVerticalAlign("center");
oParagraphCell = oCell.GetContent().GetElement(0);
oParagraphCell.AddText("Align center");
oCell = oTable.GetRow(0).GetCell(2);
oCell.SetVerticalAlign("bottom");
oParagraphCell = oCell.GetContent().GetElement(0);
oParagraphCell.AddText("Align bottom");
oTable.SetStyle(oTableStyle);
oDocContent.Push(oTable);
oSlide.AddObject(oShape);
builder.SaveFile("pptx", "SampleText.pptx");
builder.CloseFile();

如何使用 ONLYOFFICE API 在 Presentation 中添加表格?

4

1 回答 1

1

我们可以使用文档编辑器轻松做到这一点,但无法找到演示方式。

很快您也将能够在 ONLYOFFICE 演示文稿中添加表格。计划在下一个版本中。与 ONLYOFFICE 支持团队保持联系,他们会通知您。

于 2018-03-07T13:40:32.503 回答