WordDocGenerator
WordDocumentGenerator is an utility to generate Word documents from templates using Visual Studio 2017, .NET Framework 4.7 and DocumentFormat.OpenXml 2.8.1. WordDocumentGenerator helps generate Word documents both non-refresh-able as well as refresh-able based on predefined templates using minimum code changes. Content controls are used as placeholders for document generation.
Install / Use
/learn @atverma/WordDocGeneratorREADME
WordDocGenerator
Codeplex project @ https://archive.codeplex.com/?p=worddocgenerator has been moved to GitHub along with updating to latest .NET Framework and DocumentFormat.OpenXml.
WordDocumentGenerator is an utility to generate Word documents from templates using Visual Studio 2017, .NET Framework 4.7 and DocumentFormat.OpenXml 2.8.1. WordDocumentGenerator helps generate Word documents both non-refresh-able as well as refresh-able based on predefined templates using minimum code changes. Content controls are used as placeholders for document generation.
Document generation is quite easy as code changes required are very less. Mostly one just needs to override these five methods while coding a new generator class. Sample generators have been provided in utility's source code.
/// <summary>
/// Gets the place holder tag to type collection.
/// </summary>
/// <returns></returns>
protected abstract Dictionary<string, PlaceHolderType> GetPlaceHolderTagToTypeCollection();
/// <summary>
/// Ignore placeholder found.
/// </summary>
/// <param name="placeholderTag">The placeholder tag.</param>
/// <param name="openXmlElementDataContext">The open XML element data context.</param>
protected abstract void IgnorePlaceholderFound(string placeholderTag, OpenXmlElementDataContext openXmlElementDataContext);
/// <summary>
/// Non recursive placeholder found.
/// </summary>
/// <param name="placeholderTag">The placeholder tag.</param>
/// <param name="openXmlElementDataContext">The open XML element data context.</param>
protected abstract void NonRecursivePlaceholderFound(string placeholderTag, OpenXmlElementDataContext openXmlElementDataContext);
/// <summary>
/// Recursive placeholder found.
/// </summary>
/// <param name="placeholderTag">The placeholder tag.</param>
/// <param name="openXmlElementDataContext">The open XML element data context.</param>
protected abstract void RecursivePlaceholderFound(string placeholderTag, OpenXmlElementDataContext openXmlElementDataContext);
/// <summary>
/// Container placeholder found.
/// </summary>
/// <param name="placeholderTag">The placeholder tag.</param>
/// <param name="openXmlElementDataContext">The open XML element data context.</param>
protected abstract void ContainerPlaceholderFound(string placeholderTag, OpenXmlElementDataContext openXmlElementDataContext);
Development Status The functionalities that can be achieved are:
Document Generation Generate document from a Word template using content controls as place holders and populate controls with data(Object) e.g. [SampleDocumentGenerator, SampleRefreshableDocumentGenerator, SampleDocumentWithTableGenerator] Generate document from a Word template using content controls as place holders(data bound content controls) and populate controls with data(Object is serialized to Xml) e.g. [SampleDocumentGeneratorUsingDatabinding, SampleDocumentWithTableGeneratorUsingDatabinding, SampleDocumentGeneratorUsingXmlAndDatabinding] Refresh the document from within the document(e.g. right click on document and click Refresh) using document-level projects for Word 2007, Word 2010 and Word 2016 Generate document from a Word template using content controls as place holders and populate controls with data(XmlNode) e.g. [SampleDocumentGeneratorUsingXml] Generate document from a Word template using content controls as place holders(data bound content controls) and populate controls with data(XmlNode) e.g. [SampleDocumentGeneratorUsingXmlAndDatabinding] Generate document that can be Standalone: Once generated document cannot be refreshed. Refreshable: Once generated document can be refreshed. Content controls will be added/updated/deleted and content control's content will be refreshed as per data. Append documents using AltChunk Protect Document UnProtect Document Removal of Content Controls from a document while keeping contents Removal of Foot notes Ensuring the each content control has unique Id's by fixing the duplicate Id's if any for a document Serializing an Object to Xml using XmlSerializer(Used for document generation using data bound content controls as serialized object is written to CustomXmlPart)
Content Controls Set text of a content control(not applicable for data bound content controls) Get text from a content control(not applicable for data bound content controls) Set text of content control while keeping PermStart and PermEnd elements(not applicable for data bound content controls) Set Tag of a content control Get Tag of a content control Set data binding of a content control Set text of a data bound content control from CustomXmlPart manually. This is helpful in cases when CustomXmlPart needs to be removed and this copies the text from the CustomXmlPart node using XPath.
CustomXmlPart Adding a CustomXmlPart to a document Removing CustomXmlPart from a document Getting CustomXmlPart from a document Add/Update a Xml element node inside CustomXmlPart. This is required To keep Document related metadata e.g. Document type, version etc. To make the Document self-refreshable. In this case the container content control is persisted inside a Placeholder node, the first time document is generated from template. Onwards when refreshing document we fetch the container content control from CustomXmlPart Saving the Xml e.g. serialized object which will be the data store for data bound content controls
You can read more about it at https://appdevmusings.com/utility-to-generate-word-documents-from-templates-using-visual-studio-2017-and-documentformat-openxml-2-8/
Part 1: https://appdevmusings.com//utility-to-generate-word-documents-from-templates-using-visual-studio-2010-and-open-xml-2-0-sdk
Part 2: https://appdevmusings.com//utility-to-generate-word-documents-from-templates-using-visual-studio-2010-and-open-xml-2-0-sdk-part-2-samples-updated
Part 3: https://appdevmusings.com//utility-to-generate-word-documents-from-templates-using-visual-studio-2010-and-open-xml-2-0-sdk-part-3
Part 4: https://appdevmusings.com//utility-to-generate-word-documents-from-templates-using-visual-studio-2010-and-open-xml-2-0-sdk-part-4
Related Skills
qqbot-channel
345.4kQQ 频道管理技能。查询频道列表、子频道、成员、发帖、公告、日程等操作。使用 qqbot_channel_api 工具代理 QQ 开放平台 HTTP 接口,自动处理 Token 鉴权。当用户需要查看频道、管理子频道、查询成员、发布帖子/公告/日程时使用。
docs-writer
100.0k`docs-writer` skill instructions As an expert technical writer and editor for the Gemini CLI project, you produce accurate, clear, and consistent documentation. When asked to write, edit, or revie
model-usage
345.4kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
ddd
Guía de Principios DDD para el Proyecto > 📚 Documento Complementario : Este documento define los principios y reglas de DDD. Para ver templates de código, ejemplos detallados y guías paso
