C# Class Novacode.DocX

Represents a document.
Inheritance: Container, IDisposable
Afficher le fichier Open project: WordDocX/DocX Class Usage Examples

Méthodes publiques

Méthode 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

Méthodes protégées

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

Private Methods

Méthode 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 méthode

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.
Résultat void

AddCustomProperty() public méthode

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.
Résultat void

AddFooters() public méthode

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

AddHeaders() public méthode

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

AddHyperlink() public méthode

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.
Résultat Novacode.Hyperlink

AddImage() public méthode

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

AddImage() public méthode

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.
Résultat Image

AddList() public méthode

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
Résultat Novacode.List

AddListItem() public méthode

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
Résultat Novacode.List

AddProtection() public méthode

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

AddProtection() public méthode

public AddProtection ( EditRestrictions er, string strPassword ) : void
er EditRestrictions
strPassword string
Résultat void

AddTable() public méthode

public AddTable ( int rowCount, int columnCount ) : Table
rowCount int
columnCount int
Résultat Table

ApplyTemplate() public méthode

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.
Résultat void

ApplyTemplate() public méthode

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.
Résultat void

ApplyTemplate() public méthode

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.
Résultat void

ApplyTemplate() public méthode

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.
Résultat void

Copy() public méthode

Saves and copies the document into a new DocX object
public Copy ( ) : DocX
Résultat DocX

Create() public static méthode

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
Résultat DocX

Create() public static méthode

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
Résultat DocX

Dispose() public méthode

Releases all resources used by this document.
public Dispose ( ) : void
Résultat void

GetMD5HashFromStream() protected méthode

protected GetMD5HashFromStream ( Stream stream ) : string
stream Stream
Résultat string

GetProtectionType() public méthode

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

GetSections() public méthode

public GetSections ( ) : List
Résultat List

InsertChart() public méthode

Insert a chart in document
public InsertChart ( Novacode.Chart chart ) : void
chart Novacode.Chart
Résultat void

InsertChartAfterParagraph() public méthode

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

InsertDefaultTableOfContents() public méthode

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
Résultat Novacode.TableOfContents

InsertDocument() public méthode

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.
Résultat void

InsertEquation() public méthode

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

InsertList() public méthode

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

InsertList() public méthode

public InsertList ( Novacode.List list, Font fontFamily, double fontSize ) : Novacode.List
list Novacode.List
fontFamily Font
fontSize double
Résultat Novacode.List

InsertList() public méthode

public InsertList ( Novacode.List list, double fontSize ) : Novacode.List
list Novacode.List
fontSize double
Résultat Novacode.List

InsertList() public méthode

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.
Résultat Novacode.List

InsertParagraph() public méthode

public InsertParagraph ( ) : Paragraph
Résultat Paragraph

InsertParagraph() public méthode

public InsertParagraph ( Paragraph p ) : Paragraph
p Paragraph
Résultat Paragraph

InsertParagraph() public méthode

public InsertParagraph ( int index, Paragraph p ) : Paragraph
index int
p Paragraph
Résultat Paragraph

InsertParagraph() public méthode

public InsertParagraph ( int index, string text, bool trackChanges ) : Paragraph
index int
text string
trackChanges bool
Résultat Paragraph

InsertParagraph() public méthode

public InsertParagraph ( int index, string text, bool trackChanges, Formatting formatting ) : Paragraph
index int
text string
trackChanges bool
formatting Formatting
Résultat Paragraph

InsertParagraph() public méthode

public InsertParagraph ( string text ) : Paragraph
text string
Résultat Paragraph

InsertParagraph() public méthode

public InsertParagraph ( string text, bool trackChanges ) : Paragraph
text string
trackChanges bool
Résultat Paragraph

InsertParagraph() public méthode

public InsertParagraph ( string text, bool trackChanges, Formatting formatting ) : Paragraph
text string
trackChanges bool
formatting Formatting
Résultat Paragraph

InsertParagraphs() public méthode

public InsertParagraphs ( string text ) : Novacode.Paragraph[]
text string
Résultat Novacode.Paragraph[]

InsertTable() public méthode

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.
Résultat Table

InsertTable() public méthode

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.
Résultat Table

InsertTable() public méthode

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.
Résultat Table

InsertTable() public méthode

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.
Résultat Table

InsertTableOfContents() public méthode

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
Résultat Novacode.TableOfContents

InsertTableOfContents() public méthode

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
Résultat Novacode.TableOfContents

Load() public static méthode

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.
Résultat DocX

Load() public static méthode

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.
Résultat DocX

RemoveProtection() public méthode

Remove editing protection from this document.
public RemoveProtection ( ) : void
Résultat void

Save() public méthode

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

SaveAs() public méthode

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

SaveAs() public méthode

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

SetContent() public méthode

public SetContent ( string>.Dictionary dict ) : void
dict string>.Dictionary
Résultat void

SetContent() public méthode

public SetContent ( System.Xml.Linq.XDocument xmlDoc ) : void
xmlDoc System.Xml.Linq.XDocument
Résultat void

SetContent() public méthode

public SetContent ( System.Xml.Linq.XElement el ) : void
el System.Xml.Linq.XElement
Résultat void

SetContent() public méthode

public SetContent ( string path ) : void
path string
Résultat void

clonePackagePart() protected méthode

protected clonePackagePart ( PackagePart pp ) : PackagePart
pp System.IO.Packaging.PackagePart
Résultat System.IO.Packaging.PackagePart

clonePackageRelationship() protected méthode

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
Résultat void