如何使用 ONLYOFFICE API 在 Presentation 中添加表格?
Posted
技术标签:
【中文标题】如何使用 ONLYOFFICE API 在 Presentation 中添加表格?【英文标题】:How to Add a table in Presentation using ONLYOFFICE API? 【发布时间】:2018-03-07 07:07:54 【问题描述】:我们正在尝试使用演示编辑器插件中的 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();
【问题讨论】:
【参考方案1】:我们可以使用文档编辑器轻松做到这一点,但无法做到 找到一种演示方式。
很快您还可以在 ONLYOFFICE 演示文稿中添加表格。 计划在下一个版本中。 与 ONLYOFFICE 支持团队保持联系,他们会通知您。
【讨论】:
预计发布时间范围是多少?所以我们应该相应地安排!! 将包含在5.2版本中(预计2018年夏季发布)以上是关于如何使用 ONLYOFFICE API 在 Presentation 中添加表格?的主要内容,如果未能解决你的问题,请参考以下文章