If you're working with Microsoft Word documents in .NET Core , you’ll likely need to share private information (invoices, reports, or other sensitive documents) with other groups inside or outside of your organization. Typically, you'd use the Microsoft Office API; however, the Word API poses a limitation. In order to work with Word documents, you would need Microsoft Word installed on the system.
GrapeCity introduces Documents for Word (GcWord), a Word API that offers a complete solution for working with Word documents in .NET Core. With an object model based on the Microsoft Office API, Word JavaScript API, and OpenXML SDK, you can create, load, edit, save, and convert Word documents in .NET Core applications—with zero dependencies on Microsoft Word.
With a familiar and easy-to-use object model, GrapeCity Word's high-performance library includes an object model to create DOCX files through code; load DOCX files; access the object model and add, remove, and modify objects (and their properties); and then save to a .docx file or export to PDF.
If you're working in MS Word, you're likely performing some or all of the following functions:
With GcWord, you can accomplish all of this and more, including creating:
Let's look at several examples of what GcWord offers and how it differs from the MS Word API:
Input and Output: DOCX, DOTM, DOCM, DOTX
Input only: FlatOPC, FlatOpcMacroEnabled, FlatOpcTemplate, FlatOpcTemplateEnabled
Output: PDF, PDF/A
GcWord is a .NET Core library with no MS Office or platform specific dependencies. It can create Word documents from scratch, or load existing documents from streams or disk files. Documents can be analyzed and modified using an intuitive and efficient object model. All GcWord features are fully supported on Windows, Linux, and macOS
You can read existing Word documents from streams, bytes, and disks or add new pages to existing Word documents.
The GcWord API is fast and easy to use—it's a pure C# implementation of a useful subset of the MS Word object model on .NET Core. The GcWord demo displays the time taken to generate the Word document at the top. Check out the performance of GcWord while generating Word documents (or converting them to PDF).
A Word document contains one or more sections. GcWord provides access to sections, and allows to add or remove them, and modify their properties (such as page headers and footers). Properties are organized into classes in a way similar to the grouping of properties in the familiar MS Word UI, making the object model more intuitive and easier to understand.
Visit Demo | How to create sections in a Word document
When creating text and paragraphs, you can:
Visit Demo | Learn about paragraphs
Data visualization is essential. Using tables is a practical way to lay out data in rows and columns. Static and conditional formatting of table rows, columns and cells depending on their position in a table.
GcWord supports the following table features:
Visit Demo | How to create tables in a Word document using .NET
Add logos, author info, titles, and page numbers into your document headers and footers. GcWord supports all the header and footer types, including first page, odd page, and even page.
Visit Demo | Read about headers and footers
In addition to the content, you can also add notes, descriptions, or references (either at the end of each page or end of your document).
Visit Demo | Read about footnotes and endnotes
Team collaboration isn't complete without comments! Create and insert comments in any part of the document. You can:
Visit Demo | Read about adding comments
Lists and multilevel lists are vitally important for organizing information. With GcWord, you can create:
You can apply following list features:
Visit Demo | How to add, modify, and delete lists
When you're compiling a document in code that includes images, you can pull images from streams or disk files using GcWord. We support all common image formats, including PNG, BMP, JPEG, TIFF, GIF, EMF, WMF, and SVG.
GcWord together with GcImaging (another new GC component, currently in beta) allows you to access image properties such as size and resolution, for exact image positioning within a document.
Visit Demo | Work with images in a Word document
When you have large documents, you'll probably want to jump to specific locations. You can interact with your documents using the following features:
Visit Demo | How to work with links
When you're importing documents to your .NET app, you'll need to work with the existing objects in the document, or even preserve more advanced features like macros. Accessing ranges of content—for instance, a full paragraph, or even only a sentence— allows you to update the formatting or edit the text.
With GcWord, you can:
One of the major advantages of using GcWord is that you can load and modify Word documents. If your generated Word document is dependent on data changes at runtime or user input, you'll need to access document elements and edit them. You might need to change your company logo or brand colors in template documents.
GcWord can create documents from scratch, or load and modify existing Word documents. Via its object model, GcWord provides full programmatic control over the following types of Word objects, i.e., you can insert, modify, and remove these objects from a Word document:
There are some types of objects that GcWord does not yet support. This means that its object model does not provide access to the properties of those objects or means to add them to a document. However, GcWord preserves any objects that it does not recognize, so you can load a document containing such objects into GcWord, modify the document is some way and save it - any unknown to GcWord content will be preserved. Additionally, GcWord allows to programmatically remove objects that it does not support.
Every document has its own formatting guidelines, and when programming with Word documents, you'll need to access different elements of the Word document and apply formatting to it as needed. You modify the formatting of a Word document in following areas:
Create, extract and modify
Paragraph Formatting
Bulleted and numbered lists formatting
Table formatting
Page formatting
Section properties
Document objects
Document view types, zoom percent, and zoom types.
Create, modify and remove
Sometimes working with Word documents means you'll need to edit the document at a more fundamental level--attach an author to it, for instance, or work with page settings like page orientation or margins. GcWord helps you use the following features when working with page settings in Word Documents:
If you need to preserve formatting and the final document for a period of time, you’ll need to generate a PDF. Once you create Word documents using GcWord, you can convert them to PDF using a simple method of GcWord. Like all other features of GcWord, conversion to PDF is platform independent, and works on all supported platforms (Windows, Linux and macOS).
At this time, PDF conversion does not support footnotes/endnnotes, and shapes and other objects that are not yet supported by the GcWord object model (see 5.2 above). Visit this help file to view the limitations for Word to PDF conversion.
Visit Demo | How to convert a Word document to a PDF
In our GcWord article series, we'll build a .NET Core console application with GcWord in Visual Studio for Windows, MAC, and Linux and Generate a Word Document in Code.