在渲染时自动调整列的行高
Contents
[
Hide
]
通常,当您想要在单元格中显示所有文本时,您可以在 Microsoft Excel 的普通视图中进行行高自动调整,放大到 100%。这样可以在普通视图中完全显示文本,甚至在打印或将文件保存为 PDF 时,文本也能正确显示。
但在一些情况下,自动调整行在普通视图中效果良好,但当切换到打印视图或将文件保存为 PDF 时,文本会被截断。请查看源文件 Book1.xlsx 和屏幕截图。
如果要防止保存的PDF文件中出现文本被裁剪,可以使用AutoFitterOptions.ForRendering 选项来自动调整行。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Init workbook instance. | |
Workbook workbook = new Workbook("Book1.xlsx"); | |
//Set autofit options for rendering. | |
AutoFitterOptions autoFitterOptions = new AutoFitterOptions(); | |
autoFitterOptions.setForRendering(true); | |
//Autofit rows with options. | |
workbook.getWorksheets().get(0).autoFitRows(autoFitterOptions); | |
//Save to pdf. | |
workbook.save("output.pdf", SaveFormat.PDF); |
现在,在输出的 PDF 文件中文本不再被截断。