This brief tutorial guides how to wrap text in Excel using Java. It has the details to set the development environment for performing this task, a list of steps defining the process, and a ready-to-run sample code to apply text wrapping in Excel using Java. You will learn different options to control the wrapping process.
Steps to Auto Wrap Text in Excel using Java
- Set the environment to use Aspose.Cells for Java for wrapping the text
- Create a workbook and select a sheet to wrap text
- Put some long sample text in a few cells
- Get style from one of the cells and set its flag for wrapping text
- Set the style back to the cell and call the autoFitRows() method for the sheet
- Save the output file with wrapped text
These steps depict how to wrap around text in Excel using Java. Access the cell style and set the text wrap property to true. Subsequently, call the autoFitRows() method to wrap text in all the cells whose isTextWrapped flag is true.
Code to Apply Wrap Text in Excel using Java
The above code demonstrates how to text wrap in Excel using Java. In this sample code, we updated the isTextWrapped property of the individual cell however, each row and column in a sheet has the style property. You can set the entire row/column wrap text flag to true for the complete row/column if required.
This tutorial guided us on how to apply text wrapping in Excel using Java. If you want to adjust the column width, refer to the article on how to adjust column width in Excel using Java.