C# Class Novacode.DocX

Represents a document.
Inheritance: Container, IDisposable
Exibir arquivo Open project: WordDocX/DocX Class Usage Examples

Public Methods

Method Description
AddCoreProperty ( string propertyName, string propertyValue ) : void

Add a core property to this document. If a core property already exists with the same name it will be replaced. Core property names are case insensitive.

AddCustomProperty ( CustomProperty cp ) : void

Add a custom property to this document. If a custom property already exists with the same name it will be replace. CustomProperty names are case insensitive.

AddFooters ( ) : void

Adds three new Footers to this document. One for the first page, one for odd pages and one for even pages.

AddHeaders ( ) : void

Adds three new Headers to this document. One for the first page, one for odd pages and one for even pages.

AddHyperlink ( string text, Uri uri ) : Novacode.Hyperlink

Adds a hyperlink to a document and creates a Paragraph which uses it.

AddImage ( Stream stream ) : Image

Add an Image into this document from a Stream.

AddImage ( string filename ) : Image

Add an Image into this document from a fully qualified or relative filename.

AddList ( string listText = null, int level, ListItemType listType = ListItemType.Numbered, int startNumber = null, bool trackChanges = false, bool continueNumbering = false ) : Novacode.List

Create a new list with a list item.

AddListItem ( Novacode.List list, string listText, int level, ListItemType listType = ListItemType.Numbered, int startNumber = null, bool trackChanges = false, bool continueNumbering = false ) : Novacode.List

Add a list item to an already existing list.

AddProtection ( EditRestrictions er ) : void

Add editing protection to this document.

AddProtection ( EditRestrictions er, string strPassword ) : void
AddTable ( int rowCount, int columnCount ) : Table
ApplyTemplate ( Stream templateStream ) : void

Applies document template to the document. Document template may include styles, headers, footers, properties, etc. as well as text content.

ApplyTemplate ( Stream templateStream, bool includeContent ) : void

Applies document template to the document. Document template may include styles, headers, footers, properties, etc. as well as text content.

ApplyTemplate ( string templateFilePath ) : void

Applies document template to the document. Document template may include styles, headers, footers, properties, etc. as well as text content.

ApplyTemplate ( string templateFilePath, bool includeContent ) : void

Applies document template to the document. Document template may include styles, headers, footers, properties, etc. as well as text content.

Copy ( ) : DocX

Saves and copies the document into a new DocX object

Create ( Stream stream, DocumentTypes documentType = DocumentTypes.Document ) : DocX

Creates a document using a Stream.

Create ( string filename, DocumentTypes documentType = DocumentTypes.Document ) : DocX

Creates a document using a fully qualified or relative filename.

Dispose ( ) : void

Releases all resources used by this document.

GetProtectionType ( ) : EditRestrictions

Returns the type of editing protection imposed on this document.

GetSections ( ) : List
InsertChart ( Novacode.Chart chart ) : void

Insert a chart in document

InsertChartAfterParagraph ( Novacode.Chart chart, Paragraph paragraph ) : void

Insert a chart in document after paragraph

InsertDefaultTableOfContents ( ) : Novacode.TableOfContents

Inserts a default TOC into the current document. Title: Table of contents Swithces will be: TOC \h \o '1-3' \u \z

InsertDocument ( DocX remote_document, bool append = true ) : void

Insert the contents of another document at the end of this document.

If the document being inserted contains Images, CustomProperties and or custom styles, these will be correctly inserted into the new document. In the case of Images, new ID's are generated for the Images being inserted to avoid ID conflicts. CustomProperties with the same name will be ignored not replaced.

InsertEquation ( String equation ) : Paragraph

Create an equation and insert it in the new paragraph

InsertList ( Novacode.List list ) : Novacode.List

Insert list into the document.

InsertList ( Novacode.List list, Font fontFamily, double fontSize ) : Novacode.List
InsertList ( Novacode.List list, double fontSize ) : Novacode.List
InsertList ( int index, Novacode.List list ) : Novacode.List

Insert a list at an index location in the document.

InsertParagraph ( ) : Paragraph
InsertParagraph ( Paragraph p ) : Paragraph
InsertParagraph ( int index, Paragraph p ) : Paragraph
InsertParagraph ( int index, string text, bool trackChanges ) : Paragraph
InsertParagraph ( int index, string text, bool trackChanges, Formatting formatting ) : Paragraph
InsertParagraph ( string text ) : Paragraph
InsertParagraph ( string text, bool trackChanges ) : Paragraph
InsertParagraph ( string text, bool trackChanges, Formatting formatting ) : Paragraph
InsertParagraphs ( string text ) : Novacode.Paragraph[]
InsertTable ( Table t ) : Table

Insert a Table into this document. The Table's source can be a completely different document.

InsertTable ( int index, Table t ) : Table

Insert a Table into this document. The Table's source can be a completely different document.

InsertTable ( int rowCount, int columnCount ) : Table

Insert a new Table at the end of this document.

InsertTable ( int index, int rowCount, int columnCount ) : Table

Insert a new Table at the end of this document.

InsertTableOfContents ( Paragraph reference, string title, TableOfContentsSwitches switches, string headerStyle = null, int maxIncludeLevel = 3, int rightTabPos = null ) : Novacode.TableOfContents

Inserts at TOC into the current document before the provided reference

InsertTableOfContents ( string title, TableOfContentsSwitches switches, string headerStyle = null, int maxIncludeLevel = 3, int rightTabPos = null ) : Novacode.TableOfContents

Inserts a TOC into the current document.

Load ( Stream stream ) : DocX

Loads a document into a DocX object using a Stream.

Load ( string filename ) : DocX

Loads a document into a DocX object using a fully qualified or relative filename.

RemoveProtection ( ) : void

Remove editing protection from this document.

Save ( ) : void

Save this document back to the location it was loaded from.

SaveAs ( Stream stream ) : void

Save this document to a Stream.

SaveAs ( string filename ) : void

Save this document to a file.

SetContent ( string>.Dictionary dict ) : void
SetContent ( System.Xml.Linq.XDocument xmlDoc ) : void
SetContent ( System.Xml.Linq.XElement el ) : void
SetContent ( string path ) : void

Protected Methods

Method Description
GetMD5HashFromStream ( Stream stream ) : string
clonePackagePart ( PackagePart pp ) : PackagePart
clonePackageRelationship ( DocX remote_document, PackagePart pp, System.Xml.Linq.XDocument remote_mainDoc ) : void

Private Methods

Method Description
AddHeadersOrFooters ( bool b ) : void

Adds a Header to a document. If the document already contains a Header it will be replaced.

AddHyperlinkStyleIfNotPresent ( ) : void
AddImage ( object o, string contentType = "image/jpeg" ) : Image
AddStylesForList ( ) : System.Xml.Linq.XDocument
ComputeMD5HashString ( Stream stream ) : string
DeleteHeadersOrFooters ( bool b ) : void
DocX ( DocX document, System.Xml.Linq.XElement xml ) : System
GetCollectiveText ( List list ) : string
GetFooterByType ( string type ) : Footer
GetHeaderByType ( string type ) : Header
GetHeaderOrFooterByType ( string type, bool isHeader ) : object
GetNextFreeRelationshipID ( ) : string
PopulateDocument ( DocX document, Package package ) : void
PostCreation ( Package package, DocumentTypes documentType = DocumentTypes.Document ) : void
PostLoad ( Package &package ) : DocX
UpdateCorePropertyValue ( DocX document, string corePropertyName, string corePropertyValue ) : void
UpdateCustomPropertyValue ( DocX document, string customPropertyName, string customPropertyValue ) : void

Update the custom properties inside the document

Different version of Word create different Document XML.

concatByteArrays ( byte array1, byte array2 ) : byte[]
getMarginAttribute ( System.Xml.Linq.XName name ) : float
getMirrorMargins ( System.Xml.Linq.XName name ) : bool

Mirror Margins boolean value. True when margins has to be mirrored.

merge_customs ( PackagePart remote_pp, PackagePart local_pp, System.Xml.Linq.XDocument remote_mainDoc ) : void
merge_endnotes ( PackagePart remote_pp, PackagePart local_pp, System.Xml.Linq.XDocument remote_mainDoc, DocX remote, System.Xml.Linq.XDocument remote_endnotes ) : void
merge_fonts ( PackagePart remote_pp, PackagePart local_pp, System.Xml.Linq.XDocument remote_mainDoc, DocX remote ) : void
merge_footnotes ( PackagePart remote_pp, PackagePart local_pp, System.Xml.Linq.XDocument remote_mainDoc, DocX remote, System.Xml.Linq.XDocument remote_footnotes ) : void
merge_images ( PackagePart remote_pp, DocX remote_document, System.Xml.Linq.XDocument remote_mainDoc, String contentType ) : void
merge_numbering ( PackagePart remote_pp, PackagePart local_pp, System.Xml.Linq.XDocument remote_mainDoc, DocX remote ) : void
merge_styles ( PackagePart remote_pp, PackagePart local_pp, System.Xml.Linq.XDocument remote_mainDoc, DocX remote, System.Xml.Linq.XDocument remote_footnotes, System.Xml.Linq.XDocument remote_endnotes ) : void
setMarginAttribute ( System.Xml.Linq.XName xName, float value ) : void
setMirrorMargins ( System.Xml.Linq.XName name, bool value ) : void

Method Details

AddCoreProperty() public method

Add a core property to this document. If a core property already exists with the same name it will be replaced. Core property names are case insensitive.
public AddCoreProperty ( string propertyName, string propertyValue ) : void
propertyName string The property name.
propertyValue string The property value.
return void

AddCustomProperty() public method

Add a custom property to this document. If a custom property already exists with the same name it will be replace. CustomProperty names are case insensitive.
public AddCustomProperty ( CustomProperty cp ) : void
cp CustomProperty The CustomProperty to add to this document.
return void

AddFooters() public method

Adds three new Footers to this document. One for the first page, one for odd pages and one for even pages.
public AddFooters ( ) : void
return void

AddHeaders() public method

Adds three new Headers to this document. One for the first page, one for odd pages and one for even pages.
public AddHeaders ( ) : void
return void

AddHyperlink() public method

Adds a hyperlink to a document and creates a Paragraph which uses it.
public AddHyperlink ( string text, Uri uri ) : Novacode.Hyperlink
text string The text as displayed by the hyperlink.
uri System.Uri The hyperlink itself.
return Novacode.Hyperlink

AddImage() public method

Add an Image into this document from a Stream.
public AddImage ( Stream stream ) : Image
stream Stream A Stream stream.
return Image

AddImage() public method

Add an Image into this document from a fully qualified or relative filename.
public AddImage ( string filename ) : Image
filename string The fully qualified or relative filename.
return Image

AddList() public method

Create a new list with a list item.
public AddList ( string listText = null, int level, ListItemType listType = ListItemType.Numbered, int startNumber = null, bool trackChanges = false, bool continueNumbering = false ) : Novacode.List
listText string The text of the first element in the created list.
level int The indentation level of the element in the list.
listType ListItemType The type of list to be created: Bulleted or Numbered.
startNumber int The number start number for the list.
trackChanges bool Enable change tracking
continueNumbering bool Set to true if you want to continue numbering from the previous numbered list
return Novacode.List

AddListItem() public method

Add a list item to an already existing list.
public AddListItem ( Novacode.List list, string listText, int level, ListItemType listType = ListItemType.Numbered, int startNumber = null, bool trackChanges = false, bool continueNumbering = false ) : Novacode.List
list Novacode.List The list to add the new list item to.
listText string The run text that should be in the new list item.
level int The indentation level of the new list element.
listType ListItemType Numbered or Bulleted list type.
startNumber int The number start number for the list.
trackChanges bool Enable change tracking
continueNumbering bool Set to true if you want to continue numbering from the previous numbered list
return Novacode.List

AddProtection() public method

Add editing protection to this document.
public AddProtection ( EditRestrictions er ) : void
er EditRestrictions The type of protection to add to this document.
return void

AddProtection() public method

public AddProtection ( EditRestrictions er, string strPassword ) : void
er EditRestrictions
strPassword string
return void

AddTable() public method

public AddTable ( int rowCount, int columnCount ) : Table
rowCount int
columnCount int
return Table

ApplyTemplate() public method

Applies document template to the document. Document template may include styles, headers, footers, properties, etc. as well as text content.
public ApplyTemplate ( Stream templateStream ) : void
templateStream Stream The stream of the document template file.
return void

ApplyTemplate() public method

Applies document template to the document. Document template may include styles, headers, footers, properties, etc. as well as text content.
public ApplyTemplate ( Stream templateStream, bool includeContent ) : void
templateStream Stream The stream of the document template file.
includeContent bool Whether to copy the document template text content to document.
return void

ApplyTemplate() public method

Applies document template to the document. Document template may include styles, headers, footers, properties, etc. as well as text content.
The document template file not found.
public ApplyTemplate ( string templateFilePath ) : void
templateFilePath string The path to the document template file.
return void

ApplyTemplate() public method

Applies document template to the document. Document template may include styles, headers, footers, properties, etc. as well as text content.
The document template file not found.
public ApplyTemplate ( string templateFilePath, bool includeContent ) : void
templateFilePath string The path to the document template file.
includeContent bool Whether to copy the document template text content to document.
return void

Copy() public method

Saves and copies the document into a new DocX object
public Copy ( ) : DocX
return DocX

Create() public static method

Creates a document using a Stream.
public static Create ( Stream stream, DocumentTypes documentType = DocumentTypes.Document ) : DocX
stream Stream The Stream to create the document from.
documentType DocumentTypes
return DocX

Create() public static method

Creates a document using a fully qualified or relative filename.
public static Create ( string filename, DocumentTypes documentType = DocumentTypes.Document ) : DocX
filename string The fully qualified or relative filename.
documentType DocumentTypes
return DocX

Dispose() public method

Releases all resources used by this document.
public Dispose ( ) : void
return void

GetMD5HashFromStream() protected method

protected GetMD5HashFromStream ( Stream stream ) : string
stream Stream
return string

GetProtectionType() public method

Returns the type of editing protection imposed on this document.
public GetProtectionType ( ) : EditRestrictions
return EditRestrictions

GetSections() public method

public GetSections ( ) : List
return List

InsertChart() public method

Insert a chart in document
public InsertChart ( Novacode.Chart chart ) : void
chart Novacode.Chart
return void

InsertChartAfterParagraph() public method

Insert a chart in document after paragraph
public InsertChartAfterParagraph ( Novacode.Chart chart, Paragraph paragraph ) : void
chart Novacode.Chart
paragraph Paragraph
return void

InsertDefaultTableOfContents() public method

Inserts a default TOC into the current document. Title: Table of contents Swithces will be: TOC \h \o '1-3' \u \z
public InsertDefaultTableOfContents ( ) : Novacode.TableOfContents
return Novacode.TableOfContents

InsertDocument() public method

Insert the contents of another document at the end of this document.
If the document being inserted contains Images, CustomProperties and or custom styles, these will be correctly inserted into the new document. In the case of Images, new ID's are generated for the Images being inserted to avoid ID conflicts. CustomProperties with the same name will be ignored not replaced.
public InsertDocument ( DocX remote_document, bool append = true ) : void
remote_document DocX The document to insert at the end of this document.
append bool If true, document is inserted at the end, otherwise document is inserted at the beginning.
return void

InsertEquation() public method

Create an equation and insert it in the new paragraph
public InsertEquation ( String equation ) : Paragraph
equation String
return Paragraph

InsertList() public method

Insert list into the document.
public InsertList ( Novacode.List list ) : Novacode.List
list Novacode.List The list to insert into the document.
return Novacode.List

InsertList() public method

public InsertList ( Novacode.List list, Font fontFamily, double fontSize ) : Novacode.List
list Novacode.List
fontFamily Font
fontSize double
return Novacode.List

InsertList() public method

public InsertList ( Novacode.List list, double fontSize ) : Novacode.List
list Novacode.List
fontSize double
return Novacode.List

InsertList() public method

Insert a list at an index location in the document.
public InsertList ( int index, Novacode.List list ) : Novacode.List
index int Index in document to insert the list.
list Novacode.List The list that was inserted into the document.
return Novacode.List

InsertParagraph() public method

public InsertParagraph ( ) : Paragraph
return Paragraph

InsertParagraph() public method

public InsertParagraph ( Paragraph p ) : Paragraph
p Paragraph
return Paragraph

InsertParagraph() public method

public InsertParagraph ( int index, Paragraph p ) : Paragraph
index int
p Paragraph
return Paragraph

InsertParagraph() public method

public InsertParagraph ( int index, string text, bool trackChanges ) : Paragraph
index int
text string
trackChanges bool
return Paragraph

InsertParagraph() public method

public InsertParagraph ( int index, string text, bool trackChanges, Formatting formatting ) : Paragraph
index int
text string
trackChanges bool
formatting Formatting
return Paragraph

InsertParagraph() public method

public InsertParagraph ( string text ) : Paragraph
text string
return Paragraph

InsertParagraph() public method

public InsertParagraph ( string text, bool trackChanges ) : Paragraph
text string
trackChanges bool
return Paragraph

InsertParagraph() public method

public InsertParagraph ( string text, bool trackChanges, Formatting formatting ) : Paragraph
text string
trackChanges bool
formatting Formatting
return Paragraph

InsertParagraphs() public method

public InsertParagraphs ( string text ) : Novacode.Paragraph[]
text string
return Novacode.Paragraph[]

InsertTable() public method

Insert a Table into this document. The Table's source can be a completely different document.
public InsertTable ( Table t ) : Table
t Table The Table to insert.
return Table

InsertTable() public method

Insert a Table into this document. The Table's source can be a completely different document.
public InsertTable ( int index, Table t ) : Table
index int The index to insert this Table at.
t Table The Table to insert.
return Table

InsertTable() public method

Insert a new Table at the end of this document.
public InsertTable ( int rowCount, int columnCount ) : Table
rowCount int The number of rows to create.
columnCount int The number of columns to create.
return Table

InsertTable() public method

Insert a new Table at the end of this document.
public InsertTable ( int index, int rowCount, int columnCount ) : Table
index int The index to insert this Table at.
rowCount int The number of rows to create.
columnCount int The number of columns to create.
return Table

InsertTableOfContents() public method

Inserts at TOC into the current document before the provided reference
public InsertTableOfContents ( Paragraph reference, string title, TableOfContentsSwitches switches, string headerStyle = null, int maxIncludeLevel = 3, int rightTabPos = null ) : Novacode.TableOfContents
reference Paragraph The paragraph to use as reference
title string The title of the TOC
switches TableOfContentsSwitches Switches to be applied, see: http://officeopenxml.com/WPtableOfContents.php
headerStyle string Lets you set the style name of the TOC header
maxIncludeLevel int Lets you specify how many header levels should be included - default is 1-3
rightTabPos int Lets you override the right tab position - this is not common
return Novacode.TableOfContents

InsertTableOfContents() public method

Inserts a TOC into the current document.
public InsertTableOfContents ( string title, TableOfContentsSwitches switches, string headerStyle = null, int maxIncludeLevel = 3, int rightTabPos = null ) : Novacode.TableOfContents
title string The title of the TOC
switches TableOfContentsSwitches Switches to be applied, see: http://officeopenxml.com/WPtableOfContents.php
headerStyle string Lets you set the style name of the TOC header
maxIncludeLevel int Lets you specify how many header levels should be included - default is 1-3
rightTabPos int Lets you override the right tab position - this is not common
return Novacode.TableOfContents

Load() public static method

Loads a document into a DocX object using a Stream.
public static Load ( Stream stream ) : DocX
stream Stream The Stream to load the document from.
return DocX

Load() public static method

Loads a document into a DocX object using a fully qualified or relative filename.
public static Load ( string filename ) : DocX
filename string The fully qualified or relative filename.
return DocX

RemoveProtection() public method

Remove editing protection from this document.
public RemoveProtection ( ) : void
return void

Save() public method

Save this document back to the location it was loaded from.
public Save ( ) : void
return void

SaveAs() public method

Save this document to a Stream.
public SaveAs ( Stream stream ) : void
stream Stream The Stream to save this document to.
return void

SaveAs() public method

Save this document to a file.
public SaveAs ( string filename ) : void
filename string The filename to save this document as.
return void

SetContent() public method

public SetContent ( string>.Dictionary dict ) : void
dict string>.Dictionary
return void

SetContent() public method

public SetContent ( System.Xml.Linq.XDocument xmlDoc ) : void
xmlDoc System.Xml.Linq.XDocument
return void

SetContent() public method

public SetContent ( System.Xml.Linq.XElement el ) : void
el System.Xml.Linq.XElement
return void

SetContent() public method

public SetContent ( string path ) : void
path string
return void

clonePackagePart() protected method

protected clonePackagePart ( PackagePart pp ) : PackagePart
pp System.IO.Packaging.PackagePart
return System.IO.Packaging.PackagePart

clonePackageRelationship() protected method

protected clonePackageRelationship ( DocX remote_document, PackagePart pp, System.Xml.Linq.XDocument remote_mainDoc ) : void
remote_document DocX
pp System.IO.Packaging.PackagePart
remote_mainDoc System.Xml.Linq.XDocument
return void