C# Класс Novacode.DocX

Represents a document.
Наследование: Container, IDisposable
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
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

Защищенные методы

Метод Описание
GetMD5HashFromStream ( Stream stream ) : string
clonePackagePart ( PackagePart pp ) : PackagePart
clonePackageRelationship ( DocX remote_document, PackagePart pp, System.Xml.Linq.XDocument remote_mainDoc ) : void

Приватные методы

Метод Описание
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

Описание методов

AddCoreProperty() публичный Метод

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.
Результат void

AddCustomProperty() публичный Метод

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.
Результат void

AddFooters() публичный Метод

Adds three new Footers to this document. One for the first page, one for odd pages and one for even pages.
public AddFooters ( ) : void
Результат void

AddHeaders() публичный Метод

Adds three new Headers to this document. One for the first page, one for odd pages and one for even pages.
public AddHeaders ( ) : void
Результат void

AddHyperlink() публичный Метод

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.
Результат Novacode.Hyperlink

AddImage() публичный Метод

Add an Image into this document from a Stream.
public AddImage ( Stream stream ) : Image
stream Stream A Stream stream.
Результат Image

AddImage() публичный Метод

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.
Результат Image

AddList() публичный Метод

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
Результат Novacode.List

AddListItem() публичный Метод

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
Результат Novacode.List

AddProtection() публичный Метод

Add editing protection to this document.
public AddProtection ( EditRestrictions er ) : void
er EditRestrictions The type of protection to add to this document.
Результат void

AddProtection() публичный Метод

public AddProtection ( EditRestrictions er, string strPassword ) : void
er EditRestrictions
strPassword string
Результат void

AddTable() публичный Метод

public AddTable ( int rowCount, int columnCount ) : Table
rowCount int
columnCount int
Результат Table

ApplyTemplate() публичный Метод

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.
Результат void

ApplyTemplate() публичный Метод

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.
Результат void

ApplyTemplate() публичный Метод

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.
Результат void

ApplyTemplate() публичный Метод

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.
Результат void

Copy() публичный Метод

Saves and copies the document into a new DocX object
public Copy ( ) : DocX
Результат DocX

Create() публичный статический Метод

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
Результат DocX

Create() публичный статический Метод

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
Результат DocX

Dispose() публичный Метод

Releases all resources used by this document.
public Dispose ( ) : void
Результат void

GetMD5HashFromStream() защищенный Метод

protected GetMD5HashFromStream ( Stream stream ) : string
stream Stream
Результат string

GetProtectionType() публичный Метод

Returns the type of editing protection imposed on this document.
public GetProtectionType ( ) : EditRestrictions
Результат EditRestrictions

GetSections() публичный Метод

public GetSections ( ) : List
Результат List

InsertChart() публичный Метод

Insert a chart in document
public InsertChart ( Novacode.Chart chart ) : void
chart Novacode.Chart
Результат void

InsertChartAfterParagraph() публичный Метод

Insert a chart in document after paragraph
public InsertChartAfterParagraph ( Novacode.Chart chart, Paragraph paragraph ) : void
chart Novacode.Chart
paragraph Paragraph
Результат void

InsertDefaultTableOfContents() публичный Метод

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
Результат Novacode.TableOfContents

InsertDocument() публичный Метод

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.
Результат void

InsertEquation() публичный Метод

Create an equation and insert it in the new paragraph
public InsertEquation ( String equation ) : Paragraph
equation String
Результат Paragraph

InsertList() публичный Метод

Insert list into the document.
public InsertList ( Novacode.List list ) : Novacode.List
list Novacode.List The list to insert into the document.
Результат Novacode.List

InsertList() публичный Метод

public InsertList ( Novacode.List list, Font fontFamily, double fontSize ) : Novacode.List
list Novacode.List
fontFamily Font
fontSize double
Результат Novacode.List

InsertList() публичный Метод

public InsertList ( Novacode.List list, double fontSize ) : Novacode.List
list Novacode.List
fontSize double
Результат Novacode.List

InsertList() публичный Метод

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.
Результат Novacode.List

InsertParagraph() публичный Метод

public InsertParagraph ( ) : Paragraph
Результат Paragraph

InsertParagraph() публичный Метод

public InsertParagraph ( Paragraph p ) : Paragraph
p Paragraph
Результат Paragraph

InsertParagraph() публичный Метод

public InsertParagraph ( int index, Paragraph p ) : Paragraph
index int
p Paragraph
Результат Paragraph

InsertParagraph() публичный Метод

public InsertParagraph ( int index, string text, bool trackChanges ) : Paragraph
index int
text string
trackChanges bool
Результат Paragraph

InsertParagraph() публичный Метод

public InsertParagraph ( int index, string text, bool trackChanges, Formatting formatting ) : Paragraph
index int
text string
trackChanges bool
formatting Formatting
Результат Paragraph

InsertParagraph() публичный Метод

public InsertParagraph ( string text ) : Paragraph
text string
Результат Paragraph

InsertParagraph() публичный Метод

public InsertParagraph ( string text, bool trackChanges ) : Paragraph
text string
trackChanges bool
Результат Paragraph

InsertParagraph() публичный Метод

public InsertParagraph ( string text, bool trackChanges, Formatting formatting ) : Paragraph
text string
trackChanges bool
formatting Formatting
Результат Paragraph

InsertParagraphs() публичный Метод

public InsertParagraphs ( string text ) : Novacode.Paragraph[]
text string
Результат Novacode.Paragraph[]

InsertTable() публичный Метод

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.
Результат Table

InsertTable() публичный Метод

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.
Результат Table

InsertTable() публичный Метод

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.
Результат Table

InsertTable() публичный Метод

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.
Результат Table

InsertTableOfContents() публичный Метод

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
Результат Novacode.TableOfContents

InsertTableOfContents() публичный Метод

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
Результат Novacode.TableOfContents

Load() публичный статический Метод

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.
Результат DocX

Load() публичный статический Метод

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.
Результат DocX

RemoveProtection() публичный Метод

Remove editing protection from this document.
public RemoveProtection ( ) : void
Результат void

Save() публичный Метод

Save this document back to the location it was loaded from.
public Save ( ) : void
Результат void

SaveAs() публичный Метод

Save this document to a Stream.
public SaveAs ( Stream stream ) : void
stream Stream The Stream to save this document to.
Результат void

SaveAs() публичный Метод

Save this document to a file.
public SaveAs ( string filename ) : void
filename string The filename to save this document as.
Результат void

SetContent() публичный Метод

public SetContent ( string>.Dictionary dict ) : void
dict string>.Dictionary
Результат void

SetContent() публичный Метод

public SetContent ( System.Xml.Linq.XDocument xmlDoc ) : void
xmlDoc System.Xml.Linq.XDocument
Результат void

SetContent() публичный Метод

public SetContent ( System.Xml.Linq.XElement el ) : void
el System.Xml.Linq.XElement
Результат void

SetContent() публичный Метод

public SetContent ( string path ) : void
path string
Результат void

clonePackagePart() защищенный Метод

protected clonePackagePart ( PackagePart pp ) : PackagePart
pp System.IO.Packaging.PackagePart
Результат System.IO.Packaging.PackagePart

clonePackageRelationship() защищенный Метод

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
Результат void