Introducing Word library for .NET Core
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 Documents for Word API
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.
Working with Microsoft Word documents
If you're working in MS Word, you're likely performing some or all of the following functions:
- Generate, load, modify, and save Word documents
- Insert formatted text, paragraphs, images, tables, hyperlinks, document sections, headers and footers, footnotes, endnotes, and comments
- Find and replace text
- Convert Word documents to PDF
With GcWord, you can accomplish all of this and more, including creating:
- Pay slips
- Receipts
- Project plans
- Resumes
- Shopping store printing label
- To-do lists
- Journals
- Research papers
- Flyers
- Newsletters
- Brochures
- and more...
GcWord features
Let's look at several examples of what GcWord offers and how it differs from the MS Word API:
- 1. Supported file formats
- 2. Generate, load, analyze, modify, and save Word documents
- 3. Fast, efficient, and modern API
- 4. Document elements
- 5. Work with document content
- 6. Conversion to PDF
1. Supported file formats
Input and Output: DOCX, DOTM, DOCM, DOTX
Input only: FlatOPC, FlatOpcMacroEnabled, FlatOpcTemplate, FlatOpcTemplateEnabled
Output: PDF, PDF/A
2. Generate, load, analyze, modify, and save Word documents in .NET
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.
3. Fast, efficient, and modern API for Microsoft Word
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).
4. Document elements
4.1. Create sections in a Word document
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
4.2 Text and paragraph formatting
When creating text and paragraphs, you can:
- Add text and paragraphs to Word documents
- Align text to center, left, right, and justify
- Format text and paragraphs
- Apply styles
Visit Demo | Learn about paragraphs
4.3 Create tables in a Word document
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:
- Format rows of a table
- Insert page breaks
- Insert graphic elements inside the table
- Insert tables in the header
- Edit table formatting properties
- Autofit contents of cell
Visit Demo | How to create tables in a Word document using .NET
4.4 Headers and footers
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
4.5 Footnotes and endnotes
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
4.6 Comments
Team collaboration isn't complete without comments! Create and insert comments in any part of the document. You can:
- Add comment text
- Add reply comment
- Add date/time
- Add author
- Add initials
Visit Demo | Read about adding comments
4.7 Add bullet and numbered lists to Word documents
Lists and multilevel lists are vitally important for organizing information. With GcWord, you can create:
- Multilevel lists
- Numbered lists
- Bulleted lists
You can apply following list features:
- Styles
- List Level properties
- List templates
Visit Demo | How to add, modify, and delete lists
4.8 Add images to Word documents from streams and disk files
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
4.9 Insert bookmarks and hyperlinks in Word docs
When you have large documents, you'll probably want to jump to specific locations. You can interact with your documents using the following features:
- Configure bookmarks for the objects in the document
- Link to an object in the same document
- Hyperlink to Web URLs
- Hyperlink to other external files
Visit Demo | How to work with links
5. Work with document content
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:
- Get and set built-in document properties like author and title
- Manipulate text objects
- Preserve or remove VBA macros, or VBA digital signatures when loading and saving Word documents
- Access a range of objects in the document
- Access all content within a range
- Insert objects before or after range objects
5.1 Insert, modify, and remove document elements in .NET
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:
- Paragraphs
- Text
- Sections
- Images
- Tables
- Rows
- Cells
- Headers
- Footers
- Footnotes
- Endnotes
- Comments
- Bullets
- Numbered lists
- Fields
- Hyperlinks
- Bookmarks
- Page breaks
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.
- Shapes
- Drawing objects
- OLEObjects
- Charts
- Diagrams
- Textboxes
5.2 Document formatting
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
- Character formatting
- Fonts
- Colors
- Borders
- Shading
Paragraph Formatting
- Indents
- Spacing
- Borders
- Shading
- Tab stops
Bulleted and numbered lists formatting
- Numbering level
- List level
Table formatting
- Cell alignment
- Orientation
- Cell borders
- Shading
- Cell width/row height setting.
- Cell fonts and colors
- Cell background color
- Padding
Page formatting
- Page setup
- Page size
- Margins
- Page numbering
- Line numbering
- Multipage printing
Section properties
- Paper size
- Margins
- Orientation
Document objects
- Images
Document view types, zoom percent, and zoom types.
Create, modify and remove
- Document Styles
- Apply 375 in-built styles and apply custom styles
- Apply 21 in-built List templates
5.3 Edit document and page settings
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:
- Create multiple sections with different page size and orientation
- Set document properties like author name, creation date, and keywords
- Setting page margins in the document
6. Convert Word docs to PDF in .NET
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.