A table is a common and often important addition to any word document. It’s sometimes easy to forget how complex these objects can be. A table is made up of individual rows and cells, each of which have their own numerous attributes and formatting which control appearance and behavior of each element.
In Aspose.Words, we strive to make working with tables through our API powerful but also as simple to use as possible. In recent versions for both Aspose.Words for .NET and Aspose.Words for Java we have:
- Improved the table API to allow greater access to table features such as auto fitting a table to window or to contents.
- Added complete documentation for working with tables, full of useful information and detailed code examples for many scenarios when working with tables.
- Starting in Aspose.Words 10.5, changed some defaults used when creating tables so they are more similar to the defaults used when creating a table in Microsoft Word.
An Improved API to Work with Tables in MS Word
Just recently, we further improved our table API to allow great features such as setting the preferred widths of a table cells or applying autofit on a table. Starting in Aspose.Words 10.5 you can apply the following Microsoft Word standard autofit to any table in the document:
- Autofit to Window
- Autofit to Contents
- Fixed Column Widths
Further details on these new features can be found in our previous post here.
New Documentation for Working with Tables in .NET and Java
We have also been hard at work working on the related documentation and we are proud to announce a brand new section in the documentation dedicated to working with tables in Aspose.Words.
This section is packed full of handy information and plenty of code examples for almost any common task that you might need to achieve when generating or modifying tables using Aspose.Words.
You can find the new section in the documentation under the Programmer’s Guide at:
This documentation provides both useful information and example code for common tasks, such as:
- An overview of tables in Microsoft Word and Aspose.Words.
- Creating tables and applying different types of formatting.
- Specifying cell width and height
- Working with table styles
- Extracting or replacing plain text from a table or cell
- Working with Columns
- Working with Merged Cells
- Using Header Rows and Keep with Next
- Joining and Splitting Tables
- And more.
Automatically Build a Table in a Word Document from a Data Source
In addition to the Working with Tables section, we also provide a new “How-to” article with example code which demonstrates how to build a richly formatted table in a document by simply passing data from a chosen data source.
- For .NET this input data comes from any data source that returns data in the form of a DataTable
- For Java this input comes from any data source which returns data in the form of a ResultSet.
We can run the simple example code in the following article on this data. By calling the given method and few lines of code we can import this data into a fully formatted table in a new document:
- How-to: Build a Table from a DataTable in Aspose.Words for .NET
- How-to: Build a Table from a ResultSet in Aspose.Words for Java
And the following output below is generated by running the code. A table style was applied to the table to effortlessly apply great formatting to the table with just two lines of code:
Changes to Table Defaults comes with a Handy Migration Guide
Lastly, with the introduction of the new table API, we also made a few changes to the defaults used when creating new tables using Aspose.Words. We did this so creating a new table in Aspose.Words more closely follows the formatting defaults used in Microsoft Word when performing the same task. We believe this behavior will be more intuitive and much easier for new users to work with.
If you have any existing code which generates tables you may find that after upgrading to Aspose.Words 10.5 they have started to look different because of these changes. Of course, we provide a handy migration article for you to port your code over. There are only a few changes and they are very simple.
This article explains all of the changes made to defaults in the new version of Aspose.Words and provides quick code changes to be made to revert to the old behavior.
You can find the migration article for your appropriate platform here: