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
WordprocessingDocumentwordprocessing 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
Telement 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
Tabletable
colWidthMM
doublecolumn 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
Tabletable
colWidthMM
doublecolumn 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
Tabletable which adds columns
columnCount
intnumber of columns to add
colWidthMM
doubleinitial 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
Paragraphparagraph which adds a field
field
FieldEnumfield 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
Paragraphparagraph which adds a field
field
stringfield 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
WordprocessingDocumentword processing document
imgPathfilename
stringimage 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
Paragraphparagraph which add image
imagePathfilename
stringpathfilename 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
Runrun which add image
imagePathfilename
stringpathfilename 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
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
OpenXmlElementelemento to which append custom paragraph
customParagraph
Paragraphcustom 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
stringparagraph 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
WordprocessingDocumentword 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
WordprocessingDocumentword processing document
txt
stringparagraph 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
WordprocessingDocumentWordprocessing wrapper
styleName
stringparagraph style name
runFontName
stringRUN font name
runFontColor
Color?RUN font color (if null "auto" will used)
runFontSizePt
double?RUN font size in pt
spacingBetweenLinesOpts
SpacingBetweenLinesOptionsparagrah line spacing options
indentationOpts
IndentationOptionsparagrah indentation options
justification
JustificationValues?paragrah justification
basedOn
Stylestyle which this is based on
styleId
stringparagraph 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
Returns
- Table
table row
AddRun(Paragraph, Run)
add given runs to this paragraph
public static Paragraph AddRun(this Paragraph paragraph, Run run)
Parameters
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
Paragraphparagraph 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
Paragraphparagraph which adds a new run
txt
stringrun 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
Paragraphparagraph 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
Paragraphparagraph 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
WordprocessingDocumentwordprocessing 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
Paragraphparagraph 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
Paragraphparagraph
textStr
stringtext 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
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
WordprocessingDocumentword processing document
tocTitle
stringtitle 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
Paragraphtoc will placed just after given paragraph
tocTitle
stringtitle 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
Bodydocument body
element
Telement 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
Indentationopts
IndentationOptions
Returns
ApplyOpts(SpacingBetweenLines, SpacingBetweenLinesOptions)
public static SpacingBetweenLines ApplyOpts(this SpacingBetweenLines spacingBetweenLines, SpacingBetweenLinesOptions opts)
Parameters
spacingBetweenLines
SpacingBetweenLinesopts
SpacingBetweenLinesOptions
Returns
CopyPropertiesTo(Run, Run)
copy (cloned) this run properties to given dst run
public static Run CopyPropertiesTo(this Run run, Run dstRun)
Parameters
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
Returns
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
Returns
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
Paragraphparagraph 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
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
Returns
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
Ttype
NumberFormatValues?default bullet
level
intstructured
bool
Returns
- T
Type Parameters
T
EnumStyles(WordprocessingDocument)
public static IEnumerable<Style> EnumStyles(this WordprocessingDocument doc)
Parameters
Returns
FactorToPct(double)
convert 0..1 factor to fithy-thousand percent
public static double FactorToPct(this double factor)
Parameters
factor
double
Returns
Finalize(WordprocessingDocument)
release Library related resources
public static void Finalize(this WordprocessingDocument doc)
Parameters
doc
WordprocessingDocumentwodprocessing 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
WordprocessingDocumentwordprocessing document
textToSearch
stringtext to search for
replaceWith
stringtext to replace on occurrences
splitAndCreateSingleRun
boolif 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
StringComparisonallow to match with case insensitive
Returns
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
WordprocessingDocumenttextToSearch
stringstringComparison
StringComparison
Returns
GetBody(OpenXmlElement)
retrieve body from OpenXmlElement walking through parent
public static Body GetBody(this OpenXmlElement element)
Parameters
element
OpenXmlElement
Returns
GetBody(WordprocessingDocument)
retrieve body associated with doc document of the main document part
public static Body GetBody(this WordprocessingDocument doc)
Parameters
Returns
GetCell(Table, int, int)
retrieve table cell zerobased index from given table
public static TableCell GetCell(this Table table, int row, int col)
Parameters
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
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
Tabletable
Returns
- int
number of columns
GetCurrentSectionWidthMM(Paragraph)
retrieve current section width (mm)
public static double GetCurrentSectionWidthMM(this Paragraph paragraph)
Parameters
paragraph
Paragraphparagraph 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
WordprocessingDocumentcreateIfNotExists
bool
Returns
GetDocument(WordprocessingDocument)
retrieve document associated with doc of the main document part
public static Document GetDocument(this WordprocessingDocument doc)
Parameters
Returns
GetDocumentSettingsPart(WordprocessingDocument)
retrieve or create document settings parts of the doc main document part
public static DocumentSettingsPart GetDocumentSettingsPart(this WordprocessingDocument doc)
Parameters
Returns
GetId(ImagePart, WordprocessingDocument)
retrieve id associated with given imagepart
public static string GetId(this ImagePart imagePart, WordprocessingDocument doc)
Parameters
imagePart
ImagePartimage part
doc
WordprocessingDocumentword processing document
Returns
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
WordprocessingDocumentwordprocessing doc
Returns
- OpenXmlElement
element
GetLastParagraph(WordprocessingDocument, bool)
retrieve document last paragraph
public static Paragraph? GetLastParagraph(this WordprocessingDocument doc, bool createIfNotExists = false)
Parameters
doc
WordprocessingDocumentcreateIfNotExists
bool
Returns
GetMainDocumentPart(OpenXmlElement)
public static MainDocumentPart GetMainDocumentPart(this OpenXmlElement element)
Parameters
element
OpenXmlElement
Returns
GetMainDocumentPart(WordprocessingDocument)
retrieve existing or create a new main document part with its document and body
public static MainDocumentPart GetMainDocumentPart(this WordprocessingDocument doc)
Parameters
Returns
GetMaxDocPrId(WordprocessingDocument)
retrieve max id of document properties
public static uint GetMaxDocPrId(this WordprocessingDocument doc)
Parameters
Returns
GetNextParagraphStyle(Paragraph, WordprocessingDocument?)
retrieve next paragraph style from this one
public static Style? GetNextParagraphStyle(this Paragraph paragraph, WordprocessingDocument? doc = null)
Parameters
paragraph
Paragraphparagraph 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
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
Paragraphparagraph 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
Returns
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
OpenXmlElementelement 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
GetParagraphs(WordprocessingDocument)
retrieve all document paragraphs
public static IEnumerable<Paragraph> GetParagraphs(this WordprocessingDocument doc)
Parameters
Returns
GetPredefinedStyle(WordprocessingDocument, LibraryStyleEnum)
retrieve on of available style from library
public static Style GetPredefinedStyle(this WordprocessingDocument doc, LibraryStyleEnum style)
Parameters
doc
WordprocessingDocumentwordprocessing document
style
LibraryStyleEnumstyle type
Returns
- Style
style
GetProperties(Paragraph, bool, int)
public static ParagraphProperties? GetProperties(this Paragraph paragraph, bool createIfNotExists = false, int insertAtIdx = 0)
Parameters
Returns
GetProperties(Run, bool, int)
public static RunProperties? GetProperties(this Run run, bool createIfNotExists = false, int insertAtIdx = 0)
Parameters
Returns
GetRow(Table, int)
retrieve table row zerobased index
public static TableRow GetRow(this Table table, int row)
Parameters
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
Tabletable
Returns
- int
number of rows
GetRows(Table)
retrieve table rows
public static IEnumerable<TableRow> GetRows(this Table table)
Parameters
table
Tabletable
Returns
- IEnumerable<TableRow>
enumerable of TableRow
GetRuns(WordprocessingDocument)
retrieve all document paragraphs runs
public static IEnumerable<Run> GetRuns(this WordprocessingDocument doc)
Parameters
Returns
GetRuns(Paragraph)
retrieve runs belonging this paragraph
public static IEnumerable<Run> GetRuns(this Paragraph paragraph)
Parameters
paragraph
Paragraphparagraph 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
ParagraphPropertiescreateIfNotExists
boolinsertAtIdx
int?
Returns
GetSpanCount(TableCell)
retrieve the quantity of span this cell belong to
public static int GetSpanCount(this TableCell cell)
Parameters
cell
TableCellcell
Returns
- int
nr. of span ( if not defined 1 will returned )
GetStyle(Paragraph)
public static Style? GetStyle(this Paragraph paragraph)
Parameters
paragraph
Paragraph
Returns
GetStyleById(WordprocessingDocument, string, bool)
retrieve style by given style id
public static Style? GetStyleById(this WordprocessingDocument doc, string styleId, bool integrateIfNotFound = true)
Parameters
doc
WordprocessingDocumentwordprocessing doc
styleId
stringstyle id
integrateIfNotFound
boolif true (default) searches for predefined styles
Returns
- Style
style
GetStyleByName(WordprocessingDocument, string?)
public static Style? GetStyleByName(this WordprocessingDocument doc, string? styleName)
Parameters
doc
WordprocessingDocumentstyleName
string
Returns
GetStyleDefinitionsPart(WordprocessingDocument)
retrieve or create style definitions parts of the doc main document part
public static StyleDefinitionsPart GetStyleDefinitionsPart(this WordprocessingDocument doc)
Parameters
Returns
GetStyleId(ParagraphProperties, bool, int?)
public static ParagraphStyleId? GetStyleId(this ParagraphProperties paragraphProperties, bool createIfNotExists = false, int? insertAtIdx = null)
Parameters
paragraphProperties
ParagraphPropertiescreateIfNotExists
boolinsertAtIdx
int?
Returns
GetStyleName(Paragraph)
public static string? GetStyleName(this Paragraph paragraph)
Parameters
paragraph
Paragraph
Returns
GetStyleName(ParagraphProperties)
public static string? GetStyleName(this ParagraphProperties paragraphProperties)
Parameters
paragraphProperties
ParagraphProperties
Returns
GetStyleName(Style)
public static string? GetStyleName(this Style style)
Parameters
style
Style
Returns
GetStyleRunProperties(ParagraphProperties, bool, int?)
public static StyleRunProperties? GetStyleRunProperties(this ParagraphProperties paragraphProperties, bool createIfNotExists = false, int? insertAtIdx = null)
Parameters
paragraphProperties
ParagraphPropertiescreateIfNotExists
boolinsertAtIdx
int?
Returns
GetStyleWithIds(WordprocessingDocument, StyleValues?)
public static IEnumerable<(Style style, string id)> GetStyleWithIds(this WordprocessingDocument doc, StyleValues? typeOfStyle = null)
Parameters
doc
WordprocessingDocumenttypeOfStyle
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
WordprocessingDocumenttypeOfStyle
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
WordprocessingDocumentcreateIfNotExists
bool
Returns
GetTable(TableRow)
public static Table GetTable(this TableRow tableRow)
Parameters
tableRow
TableRow
Returns
GetText(Run, bool, int?)
retrieve the text object
public static Text? GetText(this Run run, bool createIfNotExists = false, int? insertAtIdx = null)
Parameters
run
Runrun
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
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
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
WordprocessingDocumentwordprocessing 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
Returns
HasStyleId(WordprocessingDocument, string)
states if document contains given syle id
public static bool HasStyleId(this WordprocessingDocument doc, string styleId)
Parameters
doc
WordprocessingDocumentwordprocessing document
styleId
stringstyle 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
Returns
- T
Type Parameters
T
MainSectionProperties(WordprocessingDocument)
set the main section properties. see also: Paragraph.SectionProperties()
public static SectionProperties MainSectionProperties(this WordprocessingDocument doc)
Parameters
Returns
MaxNumberId(WordprocessingDocument)
public static int MaxNumberId(this WordprocessingDocument doc)
Parameters
Returns
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
OpenXmlElementelement 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
OpenXmlElementelement 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
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
Returns
SetBold(Paragraph, bool)
set bold to given value over all paragraph runs
public static Paragraph SetBold(this Paragraph paragraph, bool bold = true)
Parameters
Returns
- Paragraph
paragraph
SetBold(Run, bool)
public static Run SetBold(this Run run, bool bold = true)
Parameters
Returns
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
TableCellcell
action
Action<BorderType>action to apply to border selection
borderSelectionType
TableCellBorderSelectionborder 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
Tabletable 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
Tabletable
type
BorderValues?type of border (default: single)
Returns
SetBordersOutside(Table, BorderValues?)
set table borders for only outside borders mode
public static Table SetBordersOutside(this Table table, BorderValues? type = null)
Parameters
table
Tabletable
type
BorderValues?type of border (default: single)
Returns
SetColor(Run, Color?)
set color to the given run
public static Run SetColor(this Run run, Color? color = null)
Parameters
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
WordprocessingDocumentrunFontName
stringrunFontColor
Color?fontSizePt
double?spacingBetweenLinesOpts
SpacingBetweenLinesOptionsindentationOpts
IndentationOptionsjustification
JustificationValues?
Returns
SetFontName(Run, string)
public static Run SetFontName(this Run run, string fontName)
Parameters
Returns
SetFontSizePt(Run, double)
set font size of given run
public static Run SetFontSizePt(this Run run, double fontSizePt)
Parameters
Returns
- Run
run
SetFooter(SectionProperties, Footer, HeaderFooterValues?)
public static SectionProperties SetFooter(this SectionProperties sectionProperties, Footer footer, HeaderFooterValues? type = null)
Parameters
sectionProperties
SectionPropertiesfooter
Footertype
HeaderFooterValues?
Returns
SetFooter(SectionProperties, Action<Footer>)
public static SectionProperties SetFooter(this SectionProperties sectionProperties, Action<Footer> action)
Parameters
sectionProperties
SectionPropertiesaction
Action<Footer>
Returns
SetHeader(SectionProperties, Action<Header>)
public static SectionProperties SetHeader(this SectionProperties sectionProperties, Action<Header> action)
Parameters
sectionProperties
SectionPropertiesaction
Action<Header>
Returns
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
Paragraphparagraph
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
Returns
- Paragraph
paragraph
SetItalic(Run, bool)
public static Run SetItalic(this Run run, bool italic = true)
Parameters
Returns
SetJustification(Paragraph, JustificationValues?)
set paragraph justification
public static Paragraph SetJustification(this Paragraph paragraph, JustificationValues? justificationType = null)
Parameters
paragraph
Paragraphparagraph
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
Paragraphparagraph
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
SectionPropertiesmarginLeftMM
double?marginTopMM
double?marginRightMM
double?marginBottomMM
double?
Returns
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
Paragraphparagraph
levelIndex
intlevel of numbering
format
NumberFormatValues?type of numbering (default: bullet)
structured
boolif true previous level info reported in subsequent
restartNumbering
boolif 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
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
TableCelltable 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
SectionPropertiessize
PaperSizeorientation
PageOrientationValues?
Returns
SetParagraph(TableCell, string?, Action<Run>?)
public static Paragraph SetParagraph(this TableCell cell, string? text = null, Action<Run>? action = null)
Parameters
Returns
SetParagraphStyle(Paragraph, Style)
set paragraph style
public static Paragraph SetParagraphStyle(this Paragraph paragraph, Style style)
Parameters
Returns
- Paragraph
paragraph
SetProperties(Run, RunProperties?)
set run runProperties
public static Run SetProperties(this Run run, RunProperties? runProperties = null)
Parameters
run
Runrun which set run properties
runProperties
RunPropertiesrun 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
Paragraphparagraph 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
Runrun 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
TableCelltable 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
Returns
- Paragraph
paragraph
SetSpanCount(TableCell, int)
set table cell span count
public static TableCell SetSpanCount(this TableCell cell, int spanCount)
Parameters
Returns
SetSubscript(Run)
set run as subscript
public static Run SetSubscript(this Run run)
Parameters
run
Runrun which apply subscript
Returns
- Run
run
SetSuperscript(Run)
set run as superscript
public static Run SetSuperscript(this Run run)
Parameters
run
Runrun 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
Paragraphparagraph
textStr
stringnew 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
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
SetUnderline(Paragraph, UnderlineValues?)
set underline to given value over all paragraph runs
public static Paragraph SetUnderline(this Paragraph paragraph, UnderlineValues? type = null)
Parameters
paragraph
Paragraphparagraph
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
Runrun 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
Returns
- Paragraph
paragraph
SetVerticalAlign(TableCell, TableVerticalAlignmentValues)
set cell vertical align
public static TableCell SetVerticalAlign(this TableCell cell, TableVerticalAlignmentValues valign)
Parameters
cell
TableCellcell
valign
TableVerticalAlignmentValuestype of vertical alignment
Returns
- TableCell
cell
SetVerticalPosition(Run, VerticalPositionValues)
set run vertical position
public static Run SetVerticalPosition(this Run run, VerticalPositionValues pos)
Parameters
run
Runrun
pos
VerticalPositionValuespos
Returns
- Run
run with changed vertical position
ToWPColorString(Color)
public static string ToWPColorString(this Color color)
Parameters
color
Color
Returns
ToWPColorString(Color?)
public static string ToWPColorString(this Color? color)
Parameters
color
Color?
Returns
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