Tables in Word Documents with Java
Tables in Word Documents with Java
Add or delete a table, add a row or a column, extract data from a table, - all this and much more you can do with Word documents in Java with Cloud API.
If you have worked in Microsoft Word, then you understand the main concept of working with tables to create text and graphics or showing data in a tabular
style (similar to a spreadsheet).
In a standard document page text, graphics and other content appear in a free-flowing way. The text and images wrap, and one item appears after the next. There is no way to control where items appear in the document, and this is where tables become useful. You can use a table to structure content, place text or images in one cell and align it accordingly. Furthermore, tables can be nested inside other tables up to any depth with Java API.
Creating and Formatting Tables with Word
A table is made up of rows and columns. The intersection of a row and column is called a cell.
You can use Cloud API in Java to create a table, format it, apply a style, modify a table in code, insert data into rows and cells.
A table is imported as a Table node from any document loaded into the Cloud Storage. Aspose.Words.Tables namespace contains classes that represent tables, rows, cells and their formatting.
Table manipulation in Java
You can perform the following tasks with tables in DOCX, DOC, RTF and document file formats using Java:
- Add or delete a table.
- Resize a table.
- Change columns width in a table.
- Change rows height in a table.
- Convert a table to text.
- Text wrap to surround a picture or a diagram with text.
- Add rows or columns to a Table.
- Delete rows or columns in a Table.
- Change properties of a table, a row or a cell.
Extract data from tables using Java
Java API allows you to extract text from tables. You can call API methods to get a row or to get a cell from a table.
Working with borders and margins
You can set border style, margins and cell padding in tables with Java API. You can use border property to set a border for a table. You can apply borders
to a table, to each cell or to a single cell.
Cell margin represents the number of blank spaces between the content of a cell and the border of a cell. Usually, all cells have the same margin in the table.
Working with margins, give you the right way to control spacing in a Word table.
Table properties with Java API
A table has the following properties:
Resize a table, a column or a row using AutoFit option.
Turn on AutoFit to adjust tables or columns to fit the size of your content automatically. Otherwise, turn it off for Fixed Column Width option.
You can align a table between page margins either right, left, or center with Java API.
Merge a table
Java API allows you to merge two or more tables into one larger table. After merging tables, you can also merge specific cells within the table.
Split a table
It allows you to split a table into two or more tables. It creates smaller tables or adds text between two tables.
How to work with tables in a DOCX document in Java
- Go to the Aspose Cloud Dashboard.
- Create a new Account to access all applications and services or Sign In to your account.
- Click on Applications in the left menu to get Client Id and Client Secret.
- Check API Reference page for the description of APIs parameters.
- Add Java dependency.
- Check Developer Guide to work with tables in a DOCX file in Java.