跳到主要内容

Creating structured report

Create a document with structured sections, specific formatting, alignment, and page breaks:

let doc = Api.GetDocument();

// Section 1: Executive Summary
let executiveSummaryParagraph = doc.GetElement(0);
executiveSummaryParagraph.AddText("Executive Summary");
let heading1Style = doc.GetStyle("Heading 1");
executiveSummaryParagraph.SetStyle(heading1Style);
executiveSummaryParagraph.SetSpacingAfter(20 * 20); // 20pt converted to twentieths of a point

// Add Executive Summary content
let summaryContentParagraph = Api.CreateParagraph();
summaryContentParagraph.AddText("This report summarizes the key performance indicators for Q2 and outlines key strategic opportunities.");
doc.Push(summaryContentParagraph);

// Insert page break
let pageBreakParagraph = Api.CreateParagraph();
let pageBreakRun = Api.CreateRun();
pageBreakRun.AddPageBreak();
pageBreakParagraph.AddElement(pageBreakRun);
doc.Push(pageBreakParagraph);

// Section 2: Detailed Analysis with Heading 1 style
let detailedAnalysisParagraph = Api.CreateParagraph();
detailedAnalysisParagraph.AddText("Detailed Analysis");
detailedAnalysisParagraph.SetStyle(heading1Style);
detailedAnalysisParagraph.SetSpacingBefore(40 * 20); // 40pt converted to twentieths of a point
doc.Push(detailedAnalysisParagraph);

// Add Detailed Analysis content
let analysisContentParagraph = Api.CreateParagraph();
analysisContentParagraph.AddText("This section contains in-depth data, charts, and interpretations covering marketing performance, sales trends, and operational efficiency.");
doc.Push(analysisContentParagraph);