Get Started
Usage API
More information

Api

new Api()

Base class

Methods

Name Description
AddComment

Adds a comment to the specifed element or array of Runs.

attachEvent

Subscribes to the specified event and calls the callback function when the event fires.

ConvertDocument

Converts a document to Markdown or HTML text.

CreateBlipFill

Creates a blip fill to apply to the object using the selected image as the object background.

CreateBlockLvlSdt

Creates a new block level container.

CreateBullet

Creates a bullet for a paragraph with the character or symbol specified with the sSymbol parameter.

CreateChart

Creates a chart with the parameters specified.

CreateGradientStop

Creates a gradient stop used for different types of gradients.

CreateHyperlink

Creates a new hyperlink text block to be inserted to the current paragraph or table.

CreateImage

Creates an image with the parameters specified.

CreateInlineLvlSdt

Creates a new inline container.

CreateLinearGradientFill

Creates a linear gradient fill to apply to the object using the selected linear gradient as the object background.

CreateNoFill

Creates no fill and removes the fill from the element.

CreateNumbering

Creates a bullet for a paragraph with the numbering character or symbol specified with the sType parameter.

CreateOleObject

Creates an OLE object with the parameters specified.

CreateParagraph

Creates a new paragraph.

CreatePatternFill

Creates a pattern fill to apply to the object using the selected pattern as the object background.

CreatePresetColor

Creates a color selecting it from one of the available color presets.

CreateRadialGradientFill

Creates a radial gradient fill to apply to the object using the selected radial gradient as the object background.

CreateRange

Creates an element range. If you do not specify the start and end positions, the range will be taken from the entire element.

CreateRGBColor

Creates an RGB color setting the appropriate values for the red, green and blue color components.

CreateRun

Creates a new smaller text block to be inserted to the current paragraph or table.

CreateSchemeColor

Creates a complex color scheme selecting from one of the available schemes.

CreateShape

Creates a shape with the parameters specified.

CreateSolidFill

Creates a solid fill to apply to the object using a selected solid color as the object background.

CreateStroke

Creates a stroke adding shadows to the element.

CreateTable

Creates a new table with a specified number of rows and columns.

CreateTextPr

Creates the empty text properties.

CreateWordArt

Creates a Text Art object with the parameters specified.

detachEvent

Unsubscribes from the specified event.

FromJSON

Converts the specified JSON object into the Document Builder object of the corresponding type.

GetDocument

Returns the main document.

GetMailMergeReceptionsCount

Returns the mail merge receptions count.

GetMailMergeTemplateDocContent

Returns the mail merge template document.

LoadMailMergeData

Loads data for the mail merge.

MailMerge

Starts the mail merge process.

ReplaceDocumentContent

Replaces the main document content with another document content.

ReplaceTextSmart

Replaces each paragraph (or text in cell) in the select with the corresponding text from an array of strings.

Save

Saves changes to the specified document.

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oParagraph = oDocument.GetElement(0);
var oRun = Api.CreateRun();
oRun.AddText("This is an example for base class methods.");
oParagraph.AddElement(oRun);
oRun = Api.CreateRun();
oRun.AddText(" A paragraph and a numbered list were created.");
oParagraph.AddElement(oRun);
oRun = Api.CreateRun();
oRun.AddText(" Then a chart, a shape and a table were created. The result was saved to the document.");
oParagraph.AddElement(oRun);
oParagraph = Api.CreateParagraph();
var oDrawing = Api.CreateChart("bar3D", [
  [200, 240, 280],
  [250, 260, 280]
], ["Projected Revenue", "Estimated Costs"], [2014, 2015, 2016], 4051300, 2347595, 24);
oParagraph.AddDrawing(oDrawing);
oDocument.Push(oParagraph);
oParagraph = Api.CreateParagraph();
var oGs1 = Api.CreateGradientStop(Api.CreateRGBColor(255, 224, 204), 0);
var oGs2 = Api.CreateGradientStop(Api.CreateRGBColor(255, 164, 101), 100000);
var oFill = Api.CreateLinearGradientFill([oGs1, oGs2], 5400000);
var oStroke = Api.CreateStroke(0, Api.CreateNoFill());
oDrawing = Api.CreateShape("rect", 5930900, 395605, oFill, oStroke);
oParagraph.AddDrawing(oDrawing);
oDocument.Push(oParagraph);
var oTableStyle = oDocument.CreateStyle("CustomTableStyle", "table");
oTableStyle.SetBasedOn(oDocument.GetStyle("Bordered - Accent 5"));
var oTable = Api.CreateTable(3, 3);
oTable.SetWidth("percent", 100);
oTable.SetStyle(oTableStyle);
oDocument.Push(oTable);
Api.Save();
builder.SaveFile("docx", "Api.docx");
builder.CloseFile();

Resulting document