Table of Contents

Class DocXExt

Namespace
SearchAThing.DocX
Assembly
netcore-docx.dll

SearchAThing.DocX extension methods

public static class DocXExt
Inheritance
DocXExt
Inherited Members

Methods

AddBreak(WordprocessingDocument, BreakValues?)

add a break after last body element

public static void AddBreak(this WordprocessingDocument doc, BreakValues? type = null)

Parameters

doc WordprocessingDocument

wordprocessing doc

type BreakValues?

type of break (default:page)

AddBreak<T>(T, BreakValues?)

add a break ( page, column or textwrapping )

public static Paragraph AddBreak<T>(this T element, BreakValues? type = null) where T : OpenXmlElement

Parameters

element T

element after which apply the break

type BreakValues?

type of break (default page)

Returns

Paragraph

next paragraph with break applied

Type Parameters

T

AddColumn(Table, double, Action<GridColumn>?)

adds a column to the table

public static Table AddColumn(this Table table, double colWidthMM, Action<GridColumn>? action = null)

Parameters

table Table

table

colWidthMM double

column width (mm) ; note: if table is in % then column widths will normalized

action Action<GridColumn>

(optional) action on created GridColumn

Returns

Table

grid column

AddColumn(Table, double, out int, Action<GridColumn>?)

adds a column to the table outing colIdx var

public static Table AddColumn(this Table table, double colWidthMM, out int colIdx, Action<GridColumn>? action = null)

Parameters

table Table

table

colWidthMM double

column width (mm) ; note: if table is in % then column widths will normalized

colIdx int

(out) column index

action Action<GridColumn>

(optional) action on created GridColumn

Returns

Table

grid column

AddColumns(Table, int, double, Action<GridColumn>?)

add columns in bunch

public static Table AddColumns(this Table table, int columnCount, double colWidthMM, Action<GridColumn>? action = null)

Parameters

table Table

table which adds columns

columnCount int

number of columns to add

colWidthMM double

initial column width

action Action<GridColumn>

action to perform on added column

Returns

Table

table

AddField(Paragraph, FieldEnum, Action<Run>?)

add a standard field to this paragraph

public static Paragraph AddField(this Paragraph paragraph, FieldEnum field, Action<Run>? action = null)

Parameters

paragraph Paragraph

paragraph which adds a field

field FieldEnum

field type

action Action<Run>

(optional) action to apply at run which will contains the field

Returns

Paragraph

paragraph

AddField(Paragraph, string, Action<Run>?)

add a custom field to this paragraph

public static Paragraph AddField(this Paragraph paragraph, string field, Action<Run>? action = null)

Parameters

paragraph Paragraph

paragraph which adds a field

field string

field text

action Action<Run>

(optional) action to apply at run which will contains the field

Returns

Paragraph

paragraph

AddImage(WordprocessingDocument, string, double?, double?, PartTypeInfo?)

add image from file to the list of image parts

public static Paragraph AddImage(this WordprocessingDocument doc, string imgPathfilename, double? widthMM = null, double? heightMM = null, PartTypeInfo? type = null)

Parameters

doc WordprocessingDocument

word processing document

imgPathfilename string

image pathfilename

widthMM double?

width (mm)

heightMM double?

height (mm)

type PartTypeInfo?

type of image

Returns

Paragraph

imagepart associated with given image

AddImage(Paragraph, string, double?, double?, PartTypeInfo?, uint?, WordprocessingDocument?)

create a new paragraph after this and add image; if one of width, height specified other is computed maintaining aspect

public static Paragraph AddImage(this Paragraph paragraph, string imagePathfilename, double? widthMM = null, double? heightMM = null, PartTypeInfo? type = null, uint? docPrId = null, WordprocessingDocument? doc = null)

Parameters

paragraph Paragraph

paragraph which add image

imagePathfilename string

pathfilename of image

widthMM double?

(optional) image width mm

heightMM double?

(optional) image height mm

type PartTypeInfo?

(optional) image type

docPrId uint?

(optional) doc property id

doc WordprocessingDocument

(optional) if null WordprocessingDocument will retrieve from parent

Returns

Paragraph

new paragraph with image inside

AddImage(Run, string, double?, double?, PartTypeInfo?, uint?, WordprocessingDocument?)

add image to last run of this paragraph; if one of width, height specified other is computed maintaining aspect

public static Run AddImage(this Run run, string imagePathfilename, double? widthMM = null, double? heightMM = null, PartTypeInfo? type = null, uint? docPrId = null, WordprocessingDocument? doc = null)

Parameters

run Run

run which add image

imagePathfilename string

pathfilename of image

widthMM double?

(optional) image width mm

heightMM double?

(optional) image height mm

type PartTypeInfo?

(optional) image type

docPrId uint?

(optional) doc property id

doc WordprocessingDocument

(optional) if null WordprocessingDocument will retrieve from parent

Returns

Run

AddParagraph(OpenXmlElement, Paragraph)

add given customParagraph ( it will automatically detached from its parent if not already null )

public static Paragraph AddParagraph(this OpenXmlElement elementBefore, Paragraph customParagraph)

Parameters

elementBefore OpenXmlElement

elemento to which append custom paragraph

customParagraph Paragraph

custom paragraph

Returns

Paragraph

custom paragraph

AddParagraph(OpenXmlElement, string?, Style?, Paragraph?, Action<Run>?, WordprocessingDocument?)

add a new paragraph after given paragraphBefore or to end of document

public static Paragraph AddParagraph(this OpenXmlElement elementBefore, string? txt = null, Style? style = null, Paragraph? paragraphBefore = null, Action<Run>? action = null, WordprocessingDocument? doc = null)

Parameters

elementBefore OpenXmlElement

(optional) element before the new one

txt string

paragraph initial text

style Style

(optional) style to apply to new paragraph or if exists a previous one it will inherithed

paragraphBefore Paragraph

(optional) paragraph before the new one

action Action<Run>

(optional) execute action on run created with this paragrah if any

doc WordprocessingDocument

word processing document

Returns

Paragraph

new paragraph

AddParagraph(WordprocessingDocument, string?, Style?, Paragraph?, OpenXmlElement?, OpenXmlElement?, Action<Run>?)

add a new paragraph after given paragraphBefore or to end of document

public static Paragraph AddParagraph(this WordprocessingDocument doc, string? txt = null, Style? style = null, Paragraph? paragraphBefore = null, OpenXmlElement? elementBefore = null, OpenXmlElement? parent = null, Action<Run>? action = null)

Parameters

doc WordprocessingDocument

word processing document

txt string

paragraph initial text

style Style

(optional) style to apply to new paragraph or if exists a previous one it will inherithed

paragraphBefore Paragraph

(optional) paragraph before the new one

elementBefore OpenXmlElement

(optional) element before the new one

parent OpenXmlElement

(optional) specify parent element

action Action<Run>

(optional) execute action on run created with this paragrah if any

Returns

Paragraph

new paragraph

AddParagraphSyle(WordprocessingDocument, string, string?, Color?, double?, SpacingBetweenLinesOptions?, IndentationOptions?, JustificationValues?, Style?, string?)

Adds paragraph style

public static Style AddParagraphSyle(this WordprocessingDocument doc, string styleName, string? runFontName = null, Color? runFontColor = null, double? runFontSizePt = null, SpacingBetweenLinesOptions? spacingBetweenLinesOpts = null, IndentationOptions? indentationOpts = null, JustificationValues? justification = null, Style? basedOn = null, string? styleId = null)

Parameters

doc WordprocessingDocument

Wordprocessing wrapper

styleName string

paragraph style name

runFontName string

RUN font name

runFontColor Color?

RUN font color (if null "auto" will used)

runFontSizePt double?

RUN font size in pt

spacingBetweenLinesOpts SpacingBetweenLinesOptions

paragrah line spacing options

indentationOpts IndentationOptions

paragrah indentation options

justification JustificationValues?

paragrah justification

basedOn Style

style which this is based on

styleId string

paragraph style id ( if not specified name will given )

Returns

Style

new paragraph style

AddRow(Table, Action<TableRow>?)

add a row to the table initializing cells settings default empty paragraph

public static Table AddRow(this Table table, Action<TableRow>? action = null)

Parameters

table Table

table

action Action<TableRow>

action on row

Returns

Table

table row

AddRun(Paragraph, Run)

add given runs to this paragraph

public static Paragraph AddRun(this Paragraph paragraph, Run run)

Parameters

paragraph Paragraph

paragraph which adds runs

run Run

already allocated run (without parent)

Returns

Paragraph

paragraph

AddRun(Paragraph, Action<Run>?, int?)

add a new run to given paragraph

public static Paragraph AddRun(this Paragraph paragraph, Action<Run>? action = null, int? runIdx = null)

Parameters

paragraph Paragraph

paragraph which adds a new run

action Action<Run>

action to execute on new run

runIdx int?

(optional) index of run insertion

Returns

Paragraph

paragraph

AddRun(Paragraph, string, Action<Run>?, int?)

add a new run to given paragraph

public static Paragraph AddRun(this Paragraph paragraph, string txt, Action<Run>? action = null, int? runIdx = null)

Parameters

paragraph Paragraph

paragraph which adds a new run

txt string

run txt

action Action<Run>

action to execute on new run

runIdx int?

(optional) index of run insertion

Returns

Paragraph

paragraph

AddRuns(Paragraph, IEnumerable<Run>)

add given runs to this paragraph

public static Paragraph AddRuns(this Paragraph paragraph, IEnumerable<Run> runs)

Parameters

paragraph Paragraph

paragraph which adds runs

runs IEnumerable<Run>

already allocated run (without parent)

Returns

Paragraph

paragraph

AddSpace(Paragraph, Action<Run>?, int?)

add a new run with a single space to given paragraph

public static Paragraph AddSpace(this Paragraph paragraph, Action<Run>? action = null, int? runIdx = null)

Parameters

paragraph Paragraph

paragraph which adds a new run

action Action<Run>

action to execute on new run

runIdx int?

(optional) index of run insertion

Returns

Paragraph

paragraph

AddTable(WordprocessingDocument, double?, TableRowAlignmentValues?)

add table at end of body

public static Table AddTable(this WordprocessingDocument doc, double? tableWidthPercent = null, TableRowAlignmentValues? align = null)

Parameters

doc WordprocessingDocument

wordprocessing document

tableWidthPercent double?

table width percent (0..100)

align TableRowAlignmentValues?

table alignment

Returns

Table

table

AddTable(Paragraph, double?, TableRowAlignmentValues?)

add table

public static Table AddTable(this Paragraph paragraphBefore, double? tableWidthPercent = 100, TableRowAlignmentValues? align = null)

Parameters

paragraphBefore Paragraph

paragraph before the table

tableWidthPercent double?

table width percent (0..100) or null for auto

align TableRowAlignmentValues?

table alignment (default: left)

Returns

Table

table

AddText(Paragraph, string, Action<Run>?, int?)

add a text to the given paragraph creating a corresponding new run

public static Paragraph AddText(this Paragraph paragraph, string textStr, Action<Run>? action = null, int? runIdx = null)

Parameters

paragraph Paragraph

paragraph

textStr string

text to add the paragraph

action Action<Run>

action to apply to the new run containing added text

runIdx int?

(optional) index which insert the new run

Returns

Paragraph

paragraph

AddText(Run, string)

add a text to the given run

public static Run AddText(this Run run, string textStr)

Parameters

run Run

run

textStr string

text to add the run

Returns

Run

run

AddToc(WordprocessingDocument, string, Paragraph?, bool)

add toc ad end of body or after given paragraphBefore

public static SdtBlock AddToc(this WordprocessingDocument doc, string tocTitle = "Table of Contents", Paragraph? paragraphBefore = null, bool updateOnOpen = true)

Parameters

doc WordprocessingDocument

word processing document

tocTitle string

title of toc

paragraphBefore Paragraph

(optional) if not null toc will placed just after given paragraphBefore

updateOnOpen bool

(optional) if true, as default, toc marked dirty to allow rebuild dialog on open

Returns

SdtBlock

toc

AddToc(Paragraph, string, bool)

add toc after given paragraph

public static SdtBlock AddToc(this Paragraph paragraph, string tocTitle = "Table of Contents", bool updateOnOpen = true)

Parameters

paragraph Paragraph

toc will placed just after given paragraph

tocTitle string

title of toc

updateOnOpen bool

(optional) if true, as default, toc marked dirty to allow rebuild dialog on open

Returns

SdtBlock

toc

AppendBeforeMainSection<T>(Body, T, WordprocessingDocument?)

insert element into body before main sectionproperties

public static T AppendBeforeMainSection<T>(this Body body, T element, WordprocessingDocument? doc = null) where T : OpenXmlElement

Parameters

body Body

document body

element T

element to insert before man section properties

doc WordprocessingDocument

(optional) doc ref

Returns

T

element

Type Parameters

T

ApplyOpts(Indentation, IndentationOptions)

public static Indentation ApplyOpts(this Indentation indentation, IndentationOptions opts)

Parameters

indentation Indentation
opts IndentationOptions

Returns

Indentation

ApplyOpts(SpacingBetweenLines, SpacingBetweenLinesOptions)

public static SpacingBetweenLines ApplyOpts(this SpacingBetweenLines spacingBetweenLines, SpacingBetweenLinesOptions opts)

Parameters

spacingBetweenLines SpacingBetweenLines
opts SpacingBetweenLinesOptions

Returns

SpacingBetweenLines

CopyPropertiesTo(Run, Run)

copy (cloned) this run properties to given dst run

public static Run CopyPropertiesTo(this Run run, Run dstRun)

Parameters

run Run

this run

dstRun Run

destination run

Returns

Run

this run

CreateFooter(WordprocessingDocument)

create Footer element in the document; this could set section of paragraphs until the one where set .SectionProperties().SetFooter()

public static Footer CreateFooter(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

Footer

CreateHeader(WordprocessingDocument)

create Header element in the document; this could set section of paragraphs until the one where set .SectionProperties().SetHeader()

public static Header CreateHeader(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

Header

CurrentSectionProperties(Paragraph)

retrieve current section properties. it search for a section properties from current paragraph to latest; if not found main document section properties will returned

public static SectionProperties CurrentSectionProperties(this Paragraph paragraph)

Parameters

paragraph Paragraph

paragraph from which starts search

Returns

SectionProperties

section properties associated with current paragraph

DecAutoNumbering<T>(T, int, bool)

public static T DecAutoNumbering<T>(this T element, int level = 0, bool structured = false) where T : OpenXmlElement

Parameters

element T
level int
structured bool

Returns

T

Type Parameters

T

DisableAutoNumbering<T>(T)

public static T DisableAutoNumbering<T>(this T element) where T : OpenXmlElement

Parameters

element T

Returns

T

Type Parameters

T

DocumentOuterXML(WordprocessingDocument)

public static string DocumentOuterXML(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

string

EnableAutoNumbering<T>(T, NumberFormatValues?, int, bool)

enable auto numbering

public static T EnableAutoNumbering<T>(this T element, NumberFormatValues? type = null, int level = 0, bool structured = false) where T : OpenXmlElement

Parameters

element T
type NumberFormatValues?

default bullet

level int
structured bool

Returns

T

Type Parameters

T

EnumStyles(WordprocessingDocument)

public static IEnumerable<Style> EnumStyles(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

IEnumerable<Style>

FactorToPct(double)

convert 0..1 factor to fithy-thousand percent

public static double FactorToPct(this double factor)

Parameters

factor double

Returns

double

Finalize(WordprocessingDocument)

release Library related resources

public static void Finalize(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

wodprocessing document

FindAndReplace(WordprocessingDocument, string, string, bool, StringComparison)

search for given textToSearch in all document runs ( across run supported ) and replace from the first run at its matching offset ( it may not 0 ) consuming run text lengths until last run that will eventually expands text length.

public static List<IReadOnlyList<Run>> FindAndReplace(this WordprocessingDocument doc, string textToSearch, string replaceWith, bool splitAndCreateSingleRun = false, StringComparison stringComparison = StringComparison.InvariantCulture)

Parameters

doc WordprocessingDocument

wordprocessing document

textToSearch string

text to search for

replaceWith string

text to replace on occurrences

splitAndCreateSingleRun bool

if true matching inside run will removed and first/end matching run truncated to exclude the presence of textToSearch ; a new independent run will created inside with replaceWith text all in a single run.

stringComparison StringComparison

allow to match with case insensitive

Returns

List<IReadOnlyList<Run>>

FindText(WordprocessingDocument, string, StringComparison)

search for given textToSearch in all document runs ( across run supported ); result is a list of FindTextResult each describing a paragraph runs with the first run offset from where textToSearch.Length text spans across subsequent runs.

public static List<FindTextResult> FindText(this WordprocessingDocument doc, string textToSearch, StringComparison stringComparison = StringComparison.InvariantCulture)

Parameters

doc WordprocessingDocument
textToSearch string
stringComparison StringComparison

Returns

List<FindTextResult>

GetBody(OpenXmlElement)

retrieve body from OpenXmlElement walking through parent

public static Body GetBody(this OpenXmlElement element)

Parameters

element OpenXmlElement

Returns

Body

GetBody(WordprocessingDocument)

retrieve body associated with doc document of the main document part

public static Body GetBody(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

Body

GetCell(Table, int, int)

retrieve table cell zerobased index from given table

public static TableCell GetCell(this Table table, int row, int col)

Parameters

table Table

table

row int

zero-based index of row

col int

zero-based index of column

Returns

TableCell

cell at given zero-based index of row,col

GetCell(TableRow, int)

retrieve table cell zerobased index from given row; note: to set paragraph use SetParagraph() instead of AddParagraph() if want to set first one because initial cell have a dummy paragraph.

public static TableCell GetCell(this TableRow row, int col)

Parameters

row TableRow

row from which retrieve cell

col int

zero-based index of cell column

Returns

TableCell

table row column at given zero based index

GetColumnCount(Table)

retrieve the number of table columns

public static int GetColumnCount(this Table table)

Parameters

table Table

table

Returns

int

number of columns

GetCurrentSectionWidthMM(Paragraph)

retrieve current section width (mm)

public static double GetCurrentSectionWidthMM(this Paragraph paragraph)

Parameters

paragraph Paragraph

paragraph from where starts section properties search

Returns

double

current section width (mm)

GetDocDefaults(WordprocessingDocument, bool)

public static DocDefaults? GetDocDefaults(this WordprocessingDocument doc, bool createIfNotExists = false)

Parameters

doc WordprocessingDocument
createIfNotExists bool

Returns

DocDefaults

GetDocument(WordprocessingDocument)

retrieve document associated with doc of the main document part

public static Document GetDocument(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

Document

GetDocumentSettingsPart(WordprocessingDocument)

retrieve or create document settings parts of the doc main document part

public static DocumentSettingsPart GetDocumentSettingsPart(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

DocumentSettingsPart

GetId(ImagePart, WordprocessingDocument)

retrieve id associated with given imagepart

public static string GetId(this ImagePart imagePart, WordprocessingDocument doc)

Parameters

imagePart ImagePart

image part

doc WordprocessingDocument

word processing document

Returns

string

GetIndex(OpenXmlElement)

get idx of this element as child idx of its parent

public static int? GetIndex(this OpenXmlElement element)

Parameters

element OpenXmlElement

Returns

int?

GetLastElement(WordprocessingDocument)

retrieve last element that isn't main section property

public static OpenXmlElement? GetLastElement(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

wordprocessing doc

Returns

OpenXmlElement

element

GetLastParagraph(WordprocessingDocument, bool)

retrieve document last paragraph

public static Paragraph? GetLastParagraph(this WordprocessingDocument doc, bool createIfNotExists = false)

Parameters

doc WordprocessingDocument
createIfNotExists bool

Returns

Paragraph

GetMainDocumentPart(OpenXmlElement)

public static MainDocumentPart GetMainDocumentPart(this OpenXmlElement element)

Parameters

element OpenXmlElement

Returns

MainDocumentPart

GetMainDocumentPart(WordprocessingDocument)

retrieve existing or create a new main document part with its document and body

public static MainDocumentPart GetMainDocumentPart(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

MainDocumentPart

GetMaxDocPrId(WordprocessingDocument)

retrieve max id of document properties

public static uint GetMaxDocPrId(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

uint

GetNextParagraphStyle(Paragraph, WordprocessingDocument?)

retrieve next paragraph style from this one

public static Style? GetNextParagraphStyle(this Paragraph paragraph, WordprocessingDocument? doc = null)

Parameters

paragraph Paragraph

paragraph for which retrieve next paragraph style

doc WordprocessingDocument

(optional) if null WordprocessingDocument will retrieved by parent

Returns

Style

Style of next paragraph

GetNextParagraphStyleName(Style)

public static string? GetNextParagraphStyleName(this Style style)

Parameters

style Style

Returns

string

GetNextParagraphs(Paragraph, Func<Paragraph, bool>?)

retrieve next paragraphs of this

public static IEnumerable<Paragraph> GetNextParagraphs(this Paragraph paragraph, Func<Paragraph, bool>? condition = null)

Parameters

paragraph Paragraph

paragraph for which get the next

condition Func<Paragraph, bool>

if not null allow to search next paragraph iff meet given condition

Returns

IEnumerable<Paragraph>

next paragraphs

GetNumberingDefinitionsPart(WordprocessingDocument)

retrieve or create numbering definitions parts of the doc main document part

public static NumberingDefinitionsPart GetNumberingDefinitionsPart(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

NumberingDefinitionsPart

GetOrCreate<T>(OpenXmlElement, bool, int?, Action<T>?)

retrieve typed element type child from the given owner element. if createIfNotExists was true and child not exists a new child will inserted. by default new child will append or if insertAtIdx specified chilld will inserted at the given index.

public static T? GetOrCreate<T>(this OpenXmlElement element, bool createIfNotExists, int? insertAtIdx = null, Action<T>? onNew = null) where T : OpenXmlElement, new()

Parameters

element OpenXmlElement

element owner

createIfNotExists bool

(optional) if true and child not found a new one will created

insertAtIdx int?

(optional) if specified new child will inserted at given index

onNew Action<T>

(optional) custom action to apply to child if it is created because missing

Returns

T

existing or new child

Type Parameters

T

GetPageSize(SectionProperties)

public static PageSize? GetPageSize(this SectionProperties sectionProperties)

Parameters

sectionProperties SectionProperties

Returns

PageSize

GetParagraphs(WordprocessingDocument)

retrieve all document paragraphs

public static IEnumerable<Paragraph> GetParagraphs(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

IEnumerable<Paragraph>

GetPredefinedStyle(WordprocessingDocument, LibraryStyleEnum)

retrieve on of available style from library

public static Style GetPredefinedStyle(this WordprocessingDocument doc, LibraryStyleEnum style)

Parameters

doc WordprocessingDocument

wordprocessing document

style LibraryStyleEnum

style type

Returns

Style

style

GetProperties(Paragraph, bool, int)

public static ParagraphProperties? GetProperties(this Paragraph paragraph, bool createIfNotExists = false, int insertAtIdx = 0)

Parameters

paragraph Paragraph
createIfNotExists bool
insertAtIdx int

Returns

ParagraphProperties

GetProperties(Run, bool, int)

public static RunProperties? GetProperties(this Run run, bool createIfNotExists = false, int insertAtIdx = 0)

Parameters

run Run
createIfNotExists bool
insertAtIdx int

Returns

RunProperties

GetRow(Table, int)

retrieve table row zerobased index

public static TableRow GetRow(this Table table, int row)

Parameters

table Table

table

row int

row (0 is first)

Returns

TableRow

table row at given zero based index

GetRowCount(Table)

retrieve the number of table rows

public static int GetRowCount(this Table table)

Parameters

table Table

table

Returns

int

number of rows

GetRows(Table)

retrieve table rows

public static IEnumerable<TableRow> GetRows(this Table table)

Parameters

table Table

table

Returns

IEnumerable<TableRow>

enumerable of TableRow

GetRuns(WordprocessingDocument)

retrieve all document paragraphs runs

public static IEnumerable<Run> GetRuns(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

IEnumerable<Run>

GetRuns(Paragraph)

retrieve runs belonging this paragraph

public static IEnumerable<Run> GetRuns(this Paragraph paragraph)

Parameters

paragraph Paragraph

paragraph for which retrieve runs

Returns

IEnumerable<Run>

runs belonging this paragraph

GetSectionProperties(ParagraphProperties, bool, int?)

public static SectionProperties? GetSectionProperties(this ParagraphProperties paragraphProperties, bool createIfNotExists = false, int? insertAtIdx = null)

Parameters

paragraphProperties ParagraphProperties
createIfNotExists bool
insertAtIdx int?

Returns

SectionProperties

GetSpanCount(TableCell)

retrieve the quantity of span this cell belong to

public static int GetSpanCount(this TableCell cell)

Parameters

cell TableCell

cell

Returns

int

nr. of span ( if not defined 1 will returned )

GetStyle(Paragraph)

public static Style? GetStyle(this Paragraph paragraph)

Parameters

paragraph Paragraph

Returns

Style

GetStyleById(WordprocessingDocument, string, bool)

retrieve style by given style id

public static Style? GetStyleById(this WordprocessingDocument doc, string styleId, bool integrateIfNotFound = true)

Parameters

doc WordprocessingDocument

wordprocessing doc

styleId string

style id

integrateIfNotFound bool

if true (default) searches for predefined styles

Returns

Style

style

GetStyleByName(WordprocessingDocument, string?)

public static Style? GetStyleByName(this WordprocessingDocument doc, string? styleName)

Parameters

doc WordprocessingDocument
styleName string

Returns

Style

GetStyleDefinitionsPart(WordprocessingDocument)

retrieve or create style definitions parts of the doc main document part

public static StyleDefinitionsPart GetStyleDefinitionsPart(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

StyleDefinitionsPart

GetStyleId(ParagraphProperties, bool, int?)

public static ParagraphStyleId? GetStyleId(this ParagraphProperties paragraphProperties, bool createIfNotExists = false, int? insertAtIdx = null)

Parameters

paragraphProperties ParagraphProperties
createIfNotExists bool
insertAtIdx int?

Returns

ParagraphStyleId

GetStyleName(Paragraph)

public static string? GetStyleName(this Paragraph paragraph)

Parameters

paragraph Paragraph

Returns

string

GetStyleName(ParagraphProperties)

public static string? GetStyleName(this ParagraphProperties paragraphProperties)

Parameters

paragraphProperties ParagraphProperties

Returns

string

GetStyleName(Style)

public static string? GetStyleName(this Style style)

Parameters

style Style

Returns

string

GetStyleRunProperties(ParagraphProperties, bool, int?)

public static StyleRunProperties? GetStyleRunProperties(this ParagraphProperties paragraphProperties, bool createIfNotExists = false, int? insertAtIdx = null)

Parameters

paragraphProperties ParagraphProperties
createIfNotExists bool
insertAtIdx int?

Returns

StyleRunProperties

GetStyleWithIds(WordprocessingDocument, StyleValues?)

public static IEnumerable<(Style style, string id)> GetStyleWithIds(this WordprocessingDocument doc, StyleValues? typeOfStyle = null)

Parameters

doc WordprocessingDocument
typeOfStyle StyleValues?

Returns

IEnumerable<(Style style, string id)>

GetStyleWithNames(WordprocessingDocument, StyleValues?)

public static IEnumerable<(Style style, string name)> GetStyleWithNames(this WordprocessingDocument doc, StyleValues? typeOfStyle = null)

Parameters

doc WordprocessingDocument
typeOfStyle StyleValues?

Returns

IEnumerable<(Style style, string id)>

GetStyles(WordprocessingDocument, bool)

retrieve Styles associated with style definitions parts of the doc main document part

public static Styles? GetStyles(this WordprocessingDocument doc, bool createIfNotExists = false)

Parameters

doc WordprocessingDocument
createIfNotExists bool

Returns

Styles

GetTable(TableRow)

public static Table GetTable(this TableRow tableRow)

Parameters

tableRow TableRow

Returns

Table

GetText(Run, bool, int?)

retrieve the text object

public static Text? GetText(this Run run, bool createIfNotExists = false, int? insertAtIdx = null)

Parameters

run Run

run

createIfNotExists bool

(optional) if true create the run text child if not exists

insertAtIdx int?

(optional) insertion index for the new text run

Returns

Text

text object contained in the run

GetTextStr(Run, bool)

retrieve run text string

public static string? GetTextStr(this Run run, bool createIfNotExists = false)

Parameters

run Run

run

createIfNotExists bool

(optional) if true create the run text child if not exists

Returns

string

text contained in the run

GetWordprocessingDocument(OpenXmlElement)

retrieve WordprocessingDocument from openxmlelement walking to topmost document and from there to openxmlpackage (WordprocessingDocument) through MainDocumentPart

public static WordprocessingDocument GetWordprocessingDocument(this OpenXmlElement element)

Parameters

element OpenXmlElement

Returns

WordprocessingDocument

GetWrapperRef(WordprocessingDocument)

retrieve wrapper reference associated with this document. the wrapper contains some dynamic reference that need to be release with doc.Finalize()

public static WrapperManager GetWrapperRef(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

wordprocessing document

Returns

WrapperManager

wrapper reference associated with this document

HasSectionProperties(WordprocessingDocument)

states if document has a Section Properties in its body

public static bool HasSectionProperties(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

bool

HasStyleId(WordprocessingDocument, string)

states if document contains given syle id

public static bool HasStyleId(this WordprocessingDocument doc, string styleId)

Parameters

doc WordprocessingDocument

wordprocessing document

styleId string

style id

Returns

bool

true if style id present in the document styles

IncAutoNumbering<T>(T, int, bool)

Increment numbering

public static T IncAutoNumbering<T>(this T element, int level = 0, bool structured = false) where T : OpenXmlElement

Parameters

element T
level int
structured bool

Returns

T

Type Parameters

T

MainSectionProperties(WordprocessingDocument)

set the main section properties. see also: Paragraph.SectionProperties()

public static SectionProperties MainSectionProperties(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

SectionProperties

MaxNumberId(WordprocessingDocument)

public static int MaxNumberId(this WordprocessingDocument doc)

Parameters

doc WordprocessingDocument

Returns

int

NextSibling(OpenXmlElement, Func<OpenXmlElement, bool>?)

retrieve next element of this by optional condition

public static OpenXmlElement? NextSibling(this OpenXmlElement element, Func<OpenXmlElement, bool>? condition = null)

Parameters

element OpenXmlElement

element from where start search next

condition Func<OpenXmlElement, bool>

condition to eval next element as result candidate

Returns

OpenXmlElement

next element of this with optional condition

NextSibling<T>(OpenXmlElement, Func<OpenXmlElement, bool>?)

retrieve next element of this by specified given type T and optional condition

public static T? NextSibling<T>(this OpenXmlElement element, Func<OpenXmlElement, bool>? condition = null) where T : OpenXmlElement

Parameters

element OpenXmlElement

element from where start search next

condition Func<OpenXmlElement, bool>

condition to eval next element as result candidate

Returns

T

next element of this with type T and optional condition

Type Parameters

T

ReplaceParagraph(TableCell, Paragraph)

replace cell paragraph with given one

public static Paragraph ReplaceParagraph(this TableCell cell, Paragraph newParagraph)

Parameters

cell TableCell

cell

newParagraph Paragraph

new paragraph to set in place of existing cell paragraph

Returns

Paragraph

given new pragraph

SectionProperties(Paragraph, int?)

if this paragraph has already a section properties that will returned, else a new section property will returned.

note: if there isnt' a section property already defined in the paragraph itself, a section property will searched in next paragraph and if there isn't one then main section properties will used for the new created paragraph which want to set section properties, while a new clean main section property will assigned to the document body.

public static SectionProperties SectionProperties(this Paragraph paragraph, int? insertAtIdx = null)

Parameters

paragraph Paragraph
insertAtIdx int?

Returns

SectionProperties

SetBold(Paragraph, bool)

set bold to given value over all paragraph runs

public static Paragraph SetBold(this Paragraph paragraph, bool bold = true)

Parameters

paragraph Paragraph

paragraph

bold bool

bold mode

Returns

Paragraph

paragraph

SetBold(Run, bool)

public static Run SetBold(this Run run, bool bold = true)

Parameters

run Run
bold bool

Returns

Run

SetBorder(TableCell, Action<BorderType>, TableCellBorderSelection)

set a specific border ( left, top, right, bottom ) or all at once

public static TableCell SetBorder(this TableCell cell, Action<BorderType> action, TableCellBorderSelection borderSelectionType = TableCellBorderSelection.All)

Parameters

cell TableCell

cell

action Action<BorderType>

action to apply to border selection

borderSelectionType TableCellBorderSelection

border selection type

Returns

TableCell

cell

SetBorders(Table, Action<CustomBorderActionArgs>)

set table border by applying given action to each cell border ( see CustomBorderActionArgs )

public static Table SetBorders(this Table table, Action<DocXExt.CustomBorderActionArgs> action)

Parameters

table Table

table to which set borders

action Action<DocXExt.CustomBorderActionArgs>

custom user action to change border depending on conditions; this will invoked foreach cell border and in their arguments information about current cell location are available (see SetBordersOutside for an example)

Returns

Table

table

SetBordersAll(Table, BorderValues?)

set table borders all cell borders

public static Table SetBordersAll(this Table table, BorderValues? type = null)

Parameters

table Table

table

type BorderValues?

type of border (default: single)

Returns

Table

SetBordersOutside(Table, BorderValues?)

set table borders for only outside borders mode

public static Table SetBordersOutside(this Table table, BorderValues? type = null)

Parameters

table Table

table

type BorderValues?

type of border (default: single)

Returns

Table

SetColor(Run, Color?)

set color to the given run

public static Run SetColor(this Run run, Color? color = null)

Parameters

run Run

run which apply color

color Color?

color

Returns

Run

run

SetDocDefaults(WordprocessingDocument, string?, Color?, double?, SpacingBetweenLinesOptions?, IndentationOptions?, JustificationValues?)

public static WordprocessingDocument SetDocDefaults(this WordprocessingDocument doc, string? runFontName = null, Color? runFontColor = null, double? fontSizePt = null, SpacingBetweenLinesOptions? spacingBetweenLinesOpts = null, IndentationOptions? indentationOpts = null, JustificationValues? justification = null)

Parameters

doc WordprocessingDocument
runFontName string
runFontColor Color?
fontSizePt double?
spacingBetweenLinesOpts SpacingBetweenLinesOptions
indentationOpts IndentationOptions
justification JustificationValues?

Returns

WordprocessingDocument

SetFontName(Run, string)

public static Run SetFontName(this Run run, string fontName)

Parameters

run Run
fontName string

Returns

Run

SetFontSizePt(Run, double)

set font size of given run

public static Run SetFontSizePt(this Run run, double fontSizePt)

Parameters

run Run

run

fontSizePt double

font size ( in points )

Returns

Run

run

public static SectionProperties SetFooter(this SectionProperties sectionProperties, Footer footer, HeaderFooterValues? type = null)

Parameters

sectionProperties SectionProperties
footer Footer
type HeaderFooterValues?

Returns

SectionProperties
public static SectionProperties SetFooter(this SectionProperties sectionProperties, Action<Footer> action)

Parameters

sectionProperties SectionProperties
action Action<Footer>

Returns

SectionProperties

SetHeader(SectionProperties, Action<Header>)

public static SectionProperties SetHeader(this SectionProperties sectionProperties, Action<Header> action)

Parameters

sectionProperties SectionProperties
action Action<Header>

Returns

SectionProperties

SetIndentation(Paragraph, double?, double?, double?)

set indentation of paragraph

public static Paragraph SetIndentation(this Paragraph paragraph, double? startMM = null, double? endMM = null, double? hangingMM = null)

Parameters

paragraph Paragraph

paragraph

startMM double?

start indent (mm)

endMM double?

end indent (mm)

hangingMM double?

hanging (mm)

Returns

Paragraph

paragraph

SetItalic(Paragraph, bool)

set italic to given value over all paragraph runs

public static Paragraph SetItalic(this Paragraph paragraph, bool italic = true)

Parameters

paragraph Paragraph

paragraph

italic bool

italic mode

Returns

Paragraph

paragraph

SetItalic(Run, bool)

public static Run SetItalic(this Run run, bool italic = true)

Parameters

run Run
italic bool

Returns

Run

SetJustification(Paragraph, JustificationValues?)

set paragraph justification

public static Paragraph SetJustification(this Paragraph paragraph, JustificationValues? justificationType = null)

Parameters

paragraph Paragraph

paragraph

justificationType JustificationValues?

type of paragraph justification

Returns

Paragraph

paragraph

SetMargin(Paragraph, double?, double?, double?, double?)

mimic of margin using indentation(start:left, end:right) and spacing(before:top, after:bottom)

public static Paragraph SetMargin(this Paragraph paragraph, double? leftMM = null, double? topMM = null, double? rightMM = null, double? bottomMM = null)

Parameters

paragraph Paragraph

paragraph

leftMM double?

left margin (mm)

topMM double?

top margin (mm)

rightMM double?

right margin (mm)

bottomMM double?

bottom margin (mm)

Returns

Paragraph

paragraph

SetMargin(SectionProperties, double?, double?, double?, double?)

public static SectionProperties SetMargin(this SectionProperties sectionProperties, double? marginLeftMM = null, double? marginTopMM = null, double? marginRightMM = null, double? marginBottomMM = null)

Parameters

sectionProperties SectionProperties
marginLeftMM double?
marginTopMM double?
marginRightMM double?
marginBottomMM double?

Returns

SectionProperties

SetNumbering(Paragraph, int, NumberFormatValues?, bool, bool)

set paragraph numbering style

public static Paragraph SetNumbering(this Paragraph paragraph, int levelIndex = 1, NumberFormatValues? format = null, bool structured = false, bool restartNumbering = false)

Parameters

paragraph Paragraph

paragraph

levelIndex int

level of numbering

format NumberFormatValues?

type of numbering (default: bullet)

structured bool

if true previous level info reported in subsequent

restartNumbering bool

if true restart numbering from first number defined by related abstract numbering; this accomplished by allocating a new numbering instance

Returns

Paragraph

paragraph

SetPadding(TableCell, double?)

mimic of margin using indentation(start:left, end:right) and spacing(before:top, after:bottom) on cell paragraphs

public static TableCell SetPadding(this TableCell cell, double? paddingMM = null)

Parameters

cell TableCell

table cell

paddingMM double?

padding (mm)

Returns

TableCell

table cell

SetPadding(TableCell, double?, double?, double?, double?)

mimic of margin using indentation(start:left, end:right) and spacing(before:top, after:bottom) on cell paragraphs

public static TableCell SetPadding(this TableCell cell, double? leftMM = null, double? topMM = null, double? rightMM = null, double? bottomMM = null)

Parameters

cell TableCell

table cell

leftMM double?

left margin (mm)

topMM double?

top margin (mm)

rightMM double?

right margin (mm)

bottomMM double?

bottom margin (mm)

Returns

TableCell

table cell

SetPageSize(SectionProperties, PaperSize, PageOrientationValues?)

public static SectionProperties SetPageSize(this SectionProperties sectionProperties, PaperSize size, PageOrientationValues? orientation = null)

Parameters

sectionProperties SectionProperties
size PaperSize
orientation PageOrientationValues?

Returns

SectionProperties

SetParagraph(TableCell, string?, Action<Run>?)

public static Paragraph SetParagraph(this TableCell cell, string? text = null, Action<Run>? action = null)

Parameters

cell TableCell
text string
action Action<Run>

Returns

Paragraph

SetParagraphStyle(Paragraph, Style)

set paragraph style

public static Paragraph SetParagraphStyle(this Paragraph paragraph, Style style)

Parameters

paragraph Paragraph

paragraph

style Style

style to apply

Returns

Paragraph

paragraph

SetProperties(Run, RunProperties?)

set run runProperties

public static Run SetProperties(this Run run, RunProperties? runProperties = null)

Parameters

run Run

run which set run properties

runProperties RunProperties

run properties to set to run

Returns

Run

run

SetShading(Paragraph, Color?, ShadingPatternValues?)

set shading over paragraph extensions

public static Paragraph SetShading(this Paragraph paragraph, Color? color = null, ShadingPatternValues? pattern = null)

Parameters

paragraph Paragraph

paragraph which apply shading

color Color?

shading color

pattern ShadingPatternValues?

shading pattern type (default: clear)

Returns

Paragraph

paragraph

SetShading(Run, Color?, ShadingPatternValues?)

set shading over run extensions

public static Run SetShading(this Run run, Color? color = null, ShadingPatternValues? pattern = null)

Parameters

run Run

run which apply shading

color Color?

shading color

pattern ShadingPatternValues?

shading pattern type (default clear)

Returns

Run

run

SetShading(TableCell, Color?, ShadingPatternValues?)

set shading over table cell extensions

public static TableCell SetShading(this TableCell tableCell, Color? color = null, ShadingPatternValues? pattern = null)

Parameters

tableCell TableCell

table cell which apply shading

color Color?

shading color

pattern ShadingPatternValues?

shading pattern type (default:clear)

Returns

TableCell

paragraph

SetSpacingBetweenLines(Paragraph, double?, double?)

set spacing between lines of paragraph

public static Paragraph SetSpacingBetweenLines(this Paragraph paragraph, double? beforeMM = null, double? afterMM = null)

Parameters

paragraph Paragraph

paragraph

beforeMM double?

space before (mm)

afterMM double?

space after (mm)

Returns

Paragraph

paragraph

SetSpanCount(TableCell, int)

set table cell span count

public static TableCell SetSpanCount(this TableCell cell, int spanCount)

Parameters

cell TableCell

cell

spanCount int

nr of cell span this included

Returns

TableCell

SetSubscript(Run)

set run as subscript

public static Run SetSubscript(this Run run)

Parameters

run Run

run which apply subscript

Returns

Run

run

SetSuperscript(Run)

set run as superscript

public static Run SetSuperscript(this Run run)

Parameters

run Run

run which apply superscript

Returns

Run

run

SetText(Paragraph, string, Action<Run>?)

set text of given paragraph replacing existing if any

public static Paragraph SetText(this Paragraph paragraph, string textStr, Action<Run>? action = null)

Parameters

paragraph Paragraph

paragraph

textStr string

new text

action Action<Run>

action to execute on paragraph run child

Returns

Paragraph

paragraph

SetText(Run, string)

replace run text

public static Run SetText(this Run run, string newtext)

Parameters

run Run

run

newtext string

new run text

Returns

Run

run

SetType(BorderType, BorderValues?)

set border

public static BorderType SetType(this BorderType borderType, BorderValues? type = null)

Parameters

borderType BorderType

(default:single)

type BorderValues?

Returns

BorderType

SetUnderline(Paragraph, UnderlineValues?)

set underline to given value over all paragraph runs

public static Paragraph SetUnderline(this Paragraph paragraph, UnderlineValues? type = null)

Parameters

paragraph Paragraph

paragraph

type UnderlineValues?

underline type (default: single)

Returns

Paragraph

paragraph

SetUnderline(Run, UnderlineValues?)

set underline type to the given run

public static Run SetUnderline(this Run run, UnderlineValues? underline = null)

Parameters

run Run

run which apply underline

underline UnderlineValues?

underline type (default: single)

Returns

Run

run

SetUniformMargin(Paragraph, double)

mimic of margin using indentation(start:left, end:right) and spacing(before:top, after:bottom)

public static Paragraph SetUniformMargin(this Paragraph paragraph, double marginMM)

Parameters

paragraph Paragraph

paragraph

marginMM double

left margin (mm)

Returns

Paragraph

paragraph

SetVerticalAlign(TableCell, TableVerticalAlignmentValues)

set cell vertical align

public static TableCell SetVerticalAlign(this TableCell cell, TableVerticalAlignmentValues valign)

Parameters

cell TableCell

cell

valign TableVerticalAlignmentValues

type of vertical alignment

Returns

TableCell

cell

SetVerticalPosition(Run, VerticalPositionValues)

set run vertical position

public static Run SetVerticalPosition(this Run run, VerticalPositionValues pos)

Parameters

run Run

run

pos VerticalPositionValues

pos

Returns

Run

run with changed vertical position

ToWPColorString(Color)

public static string ToWPColorString(this Color color)

Parameters

color Color

Returns

string

ToWPColorString(Color?)

public static string ToWPColorString(this Color? color)

Parameters

color Color?

Returns

string

TwipToMM(UInt32Value)

convert twip to mm
mm = 1440/25.4 twip
twip = 25.4/1440 mm

public static double TwipToMM(this UInt32Value twip)

Parameters

twip UInt32Value

Returns

double