Adjust text overflow in cells
This article explains how to adjust text-overflow in cells when viewing Spreadsheets with GroupDocs.Viewer within your Java applications.
Introduction
When Spreadsheet is rendered overflowed text inside the cell overlays subsequent cells until it meets non-empty cell. GroupDocs.Viewer provides a setting to configure the mode which will be used for rendering overflowed text:
- To set the overflowed text to be hidden, set setTextOverflowMode(…) of SpreadsheetOptions class to TextOverflowMode.HIDE_TEXT as shown in the example below.
- To set the overflowed text to overlay subsequent cells until it meets non empty cell, set setTextOverflowMode(…) of SpreadsheetOptions object to TextOverflowMode.OVERLAY_IF_NEXT_IS_EMPTY. This is a default value.
- To set the overflowed text to overlay subsequent cells even they are not empty, set setTextOverflowMode(…) of SpreadsheetOptions object to TextOverflowMode.OVERLAY.
- To expand the cell width to fit overflowed text, set setTextOverflowMode(…) of SpreadsheetOptions object to TextOverflowMode.AUTO_FIT_COLUMN.
NOTE: The same workflow is applicable for JpgViewOptions, PngViewOptions, and PdfViewOptions classes;
How to adjust text overflow in cells
The following steps are required to manage text-overflow:
- Instantiate the HtmlViewOptions, JpgViewOptions, PngViewOptions or PdfViewOptions object;
- Set setTextOverflowMode(…) of SpreadsheetOptions to TextOverflowMode.HIDE_TEXT
- Call view(…) method.
The following code sample shows how to hide text in case it overflows cell.
Viewer viewer = new Viewer("sample.xlsx");
HtmlViewOptions viewOptions = HtmlViewOptions.forEmbeddedResources();
viewOptions.getSpreadsheetOptions().setTextOverflowMode(TextOverflowMode.HIDE_TEXT);
viewer.view(viewOptions);
viewer.close();
More resources
GitHub Examples
You may easily run the code above and see the feature in action in our GitHub examples:
- GroupDocs.Viewer for Java examples, plugins, and showcase
- Document Viewer for .NET App WebForms UI Modern Example
- Document Viewer for Java App Dropwizard UI Modern Example
- Document Viewer for Java Spring UI Example
- GroupDocs.Viewer for .NET samples, plugins and showcase
- Document Viewer for .NET MVC UI Example
Free Online App
Along with full-featured Java library we provide simple but powerful free Apps. You are welcome to view Word, PDF, Excel, PowerPoint documents with free to use online GroupDocs Viewer App.