[]
Represents a Word document.
Contains one or more sections, content controls, and body representing the content of the document.
public class GcWordDocument : DocumentBase
Creates a new instance of the GcWordDocument class, optionally specifying a license key.
public GcWordDocument(string licenseKey = null)
licenseKey
stringThe license key to use. If null, and SetLicenseKey(string) has been called, the key set with that method is used.
Gets the main body of the document.
public Body Body { get; }
Gets the collection of CustomXmlPart objects.
public CustomXmlPartCollection CustomXmlParts { get; }
There are two default parts that are always created with a document. These are doc properties, and app properties.
Gets the DataTemplate object that provides properties and methods used to manage template data sources and process data templates.
public DataTemplate DataTemplate { get; }
Gets a supplementary document storage which stores the definition and content for content that shall be carried with the document for future insertion and/or use, but which shall not be visible within the contents of the main document story.
public GlossaryDocument GlossaryDocument { get; }
Gets or sets whether to hide linked character styles.
public bool HideLinkedCharacterStyles { get; set; }
Gets or sets the malformed URI rewriter that can be used to implement a custom strategy for rewriting malformed URIs.
By default this property is null (i.e. no rewriting takes place).
Set this to an instance of the DefaultMalformedUriRewriter class to use the default rewriting strategy, or use a custom IMalformedUriRewriter implementation.
public IMalformedUriRewriter MalformedUriRewriter { get; set; }
Gets the theme that holds all formatting options available to a document through a theme.
public Theme Theme { get; }
Gets the source of a formatting property.
This method finds and returns the object in the inheritance chain that determines the actual current value of the specified formatting property.
For example, to find the object that determines the font size of the first run in the document body:
var o = GetPropertyValueSource(() => document.Body.Runs.First.Font.Size);
In this example, if the Heading 1 style was applied to the paragraph containing that run, this method would return that style.
public static object GetPropertyValueSource<T>(Expression<Func<T>> property)
property
System.Linq.Expressions.Expression<TDelegate><Func<T>>An expression that returns a property derived from the FormattingBag class.
If the property is inheritable, the object in the inheritance chain that explicitly specifies the property value, or null if the property value is not specified and the property has the default value.
If the property is not inheritable, the property owner is returned.
T
Loads a System.IO.Stream that contains OpenXml formatted data into the document.
public void Load(Stream stream)
stream
System.IO.StreamThe OpenXml formatted data System.IO.Stream to load.
Loads an OpenXml formatted file into the document.
public void Load(string fileName)
fileName
stringThe OpenXML formatted file to load.
Merges several source documents into a single new GcWordDocument.
public static GcWordDocument MergeDocuments(FormattingCopyStrategy copyStrategy, params GcWordDocument[] mergedDocuments)
copyStrategy
FormattingCopyStrategySpecifies how formatting of the source documents is handled.
mergedDocuments
GcWordDocument[]The source documents to merge.
The newly created GcWordDocument consisting of the merged Body ranges of the source documents.
Merges several source documents into a single new GcWordDocument, using Copy to preserve formatting of the source documents.
public static GcWordDocument MergeDocuments(params GcWordDocument[] mergedDocuments)
mergedDocuments
GcWordDocument[]The source documents to merge.
The newly created GcWordDocument consisting of the merged Body ranges of the source documents.
Merges several source documents into a single new GcWordDocument.
public static GcWordDocument MergeDocuments(params (GcWordDocument, FormattingCopyStrategy)[] mergedDocuments)
mergedDocuments
(GcWordDocument, FormattingCopyStrategy)[]An array of pairs of source documents and corresponding formatting copy strategies.
The newly created GcWordDocument consisting of the merged Body ranges of the source documents.
Saves the document to a System.IO.Stream.
public void Save(Stream stream, DocumentType type = DocumentType.Document)
stream
System.IO.StreamThe System.IO.Stream where to save document.
type
DocumentTypeThe document type to save to.
Saves the document to an OpenXml formatted file.
public void Save(string fileName, DocumentType type = DocumentType.Document)
fileName
stringThe file path to save to.
type
DocumentTypeThe document type to save to.
Sets the license key.
public static void SetLicenseKey(string key)
key
stringThe license key to set.
Splits the current document into several documents based on specified ranges and a common formatting copy strategy.
public IEnumerable<GcWordDocument> SplitDocument(FormattingCopyStrategy copyStrategy, params RangeBase[] splitRanges)
copyStrategy
FormattingCopyStrategyThe formatting copy strategy to use.
splitRanges
RangeBase[]An array of ranges in the current document.
A collection of documents created according to the specified splitRanges
.
Splits the current document into several documents based on specified ranges, using Copy to preserve formatting of the source document.
public IEnumerable<GcWordDocument> SplitDocument(params RangeBase[] splitRanges)
splitRanges
RangeBase[]An array of ranges in the current document.
A collection of documents created according to the specified splitRanges
.
Splits the current document into several documents based on specified ranges and formatting copy strategies.
public IEnumerable<GcWordDocument> SplitDocument(params (RangeBase splitRange, FormattingCopyStrategy copyStrategy)[] splitRanges)
splitRanges
(RangeBase splitRange, FormattingCopyStrategy copyStrategy)[]An array of pairs of ranges in the current document, and corresponding formatting copy strategies.
A collection of documents created according to the specified splitRanges
.