ONLYOFFICE / DocumentBuilder

ONLYOFFICE Document Builder is powerful text, spreadsheet, presentation and PDF generating tool
https://www.onlyoffice.com/document-builder.aspx
GNU Affero General Public License v3.0
111 stars 54 forks source link

Error when transferring `oTextPr` object via GlobalVariable #86

Open PaSen-pzk opened 2 years ago

PaSen-pzk commented 2 years ago

Integrate ONLYOFFICE Document Builder into my application on Node.js. Using globalvariable method to create paragraph object will cause errors. Steps to reproduce the problem: Exception Info:

Uncaught TypeError: Converting circular structure to JSON --> starting at object with constructor 'cb' --- property 'va' closes the circle

Script example:

builder.OpenFile("2022072-10000-81acb5fcd08244e3926c891263cfe168.docx");
var tempDocument = Api.GetDocument();
var tempDocumentParagraphs= tempDocument.GetElement(0);
GlobalVariable[ "CommentsReport" ] = tempDocumentParagraphs;
builder.CloseFile();
builder.OpenFile("2022072-10000-99c8b7f2ef844e97b6410eee0b0618c2.docx");
var curDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
var tempParagraph = global;
oParagraph.InsertParagraph(tempParagraph, "after" , true );
curDocument.Push(oParagraph); 
builder.SaveFile("docx", "Result4.docx");
builder.CloseFile();

Execution mode: Run the above script with the executable file of docbuilder under the onlyoffice installation directory. DocumentBuilder version: Version: 7.1.1 Installation method: Download and unpack on Windows . Operating system: Windows11

ShockwaveNN commented 2 years ago

Hi, I think we need both those files to correctly diagnose the situation "2022072-10000-81acb5fcd08244e3926c891263cfe168.docx" "2022072-10000-99c8b7f2ef844e97b6410eee0b0618c2.docx"

PaSen-pzk commented 2 years ago

2022072-10000-81acb5fcd08244e3926c891263cfe168.docx 2022072-10000-99c8b7f2ef844e97b6410eee0b0618c2.docx

l8556 commented 2 years ago

Hello @PaSen-pzk ! You are not using GlobalVariable correctly.

Example of correct usage:

builder.OpenFile("2022072-10000-81acb5fcd08244e3926c891263cfe168.docx");
var oDocument = Api.GetDocument();
GlobalVariable["CommentsReport"] = oDocument.GetElement(0).GetText();
builder.CloseFile();

builder.OpenFile("2022072-10000-99c8b7f2ef844e97b6410eee0b0618c2.docx");
var oCommentsReport = GlobalVariable["CommentsReport"];
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.InsertParagraph(oCommentsReport, "after", true);
builder.SaveFile("docx", "Result.docx");
builder.CloseFile();
PaSen-pzk commented 2 years ago

你好@PaSen-pzk! 您没有正确使用 GlobalVariable。

正确用法示例:

builder.OpenFile("2022072-10000-81acb5fcd08244e3926c891263cfe168.docx");
var oDocument = Api.GetDocument();
GlobalVariable["CommentsReport"] = oDocument.GetElement(0).GetText();
builder.CloseFile();

builder.OpenFile("2022072-10000-99c8b7f2ef844e97b6410eee0b0618c2.docx");
var oCommentsReport = GlobalVariable["CommentsReport"];
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.InsertParagraph(oCommentsReport, "after", true);
builder.SaveFile("docx", "Result.docx");
builder.CloseFile();

In this case, there is no guarantee that the merged content format is consistent with the source file. In the way you provided, I tried to get the text format, that is, apitextpr, and add it to the global variable, but the function contained in this apitextpr object cannot be serialized, so it is not available.

l8556 commented 2 years ago

你好@PaSen-pzk! 您没有正确使用 GlobalVariable。 正确用法示例:

builder.OpenFile("2022072-10000-81acb5fcd08244e3926c891263cfe168.docx");
var oDocument = Api.GetDocument();
GlobalVariable["CommentsReport"] = oDocument.GetElement(0).GetText();
builder.CloseFile();

builder.OpenFile("2022072-10000-99c8b7f2ef844e97b6410eee0b0618c2.docx");
var oCommentsReport = GlobalVariable["CommentsReport"];
var oDocument = Api.GetDocument();
var oParagraph = Api.CreateParagraph();
oParagraph.InsertParagraph(oCommentsReport, "after", true);
builder.SaveFile("docx", "Result.docx");
builder.CloseFile();

In this case, there is no guarantee that the merged content format is consistent with the source file. In the way you provided, I tried to get the text format, that is, apitextpr, and add it to the global variable, but the function contained in this apitextpr object cannot be serialized, so it is not available.

This is a bug. Issue 58126 in our private issue tracker.