AutoFit can change the width or height automatically to fit the content.
AutoFit Width
since 5.7.0
Manually
End users can autofit one column width by double-clicking a column header’s border to make its width. Or you can select multiple columns to auto-fit them at once.
By API
- AutoFit 1 column:
Spreadsheet.setAutofitColumnWidth(SSheet sheet, int column)
- AutoFit multiple columns:
Spreadsheet.setAutofitColumnWidth(SSheet sheet, int fromColumn, int toColumn)
AutoFit Height
To let keikai automatically resize a row height, please enable “wrap text”.
By API
since 5.9.0
For those cases that wrap text can’t resize the height e.g. a merged cell, call CellOperationUtil.getAutoFitHeight() and apply the height to one or multiple cells.
int currentHeight = range.getSheet().getRowHeight(range.getRow());
int autofitHeight = CellOperationUtil.getAutoFitHeight(spreadsheet.getSelectedSheet(),
range.getRow(), range.getColumn());
if (autofitHeight != currentHeight) {
range.setRowHeight(autofitHeight);
}
Comments