Try the fastest and simplest way to install ONLYOFFICE

Copy and Paste Header Between documents

Copy and Paste Header Between documents

Postby emer1310 » Tue Sep 04, 2018 8:14 pm

Hello,

I'm trying to copy a header that is in a documents saved in a forlder in order to paste it in another document that i create in runtime.

I use this code but it doesn't work.

builder.OpenFile("plantilla.docx");
var oDocument = Api.GetDocument();
var oSection1 = oDocument.GetFinalSection();
oHeader = oSection1.GetHeader("default", false);
GlobalVariable["header"] = oHeader;
builder.CloseFile();

builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oHeader = GlobalVariable["header"];
var oSection = oDocument.GetFinalSection();
var oHeader2 = oSection.GetHeader("default", true);
var oParagraph = Api.CreateParagraph();
oParagraph = oHeader2.GetElement(0);
oParagraph.AddElement(oHeader);
builder.SaveFile("docx", "documento1.docx");
builder.CloseFile;

Any idea?

Thanks.
emer1310
 
Posts: 1
Joined: Tue Sep 04, 2018 8:11 pm

Return to Documents

Who is online

Users browsing this forum: No registered users and 2 guests