本文介绍如何使用Spire.XLS for Java在Excel文档中设置行高和列宽。
import com.spire.xls.*;
public class SetWidthAndHeight {
public static void main(String[] args) {
//创建Workbook对象
Workbook workbook = new Workbook();
//获取第一个工作表
Worksheet worksheet = workbook.getWorksheets().get(0);
//写入文本
worksheet.getCellRange("A1").setText("行高 = 30");
worksheet.getCellRange("D4").setText("列宽 = 20");
//将第一行的行高设为30
worksheet.setRowHeight(1,30);
//将第四列的列宽设为20
worksheet.setColumnWidth(4, 20);
//保存文档
workbook.saveToFile("SetWidthAndHeight.xlsx", ExcelVersion.Version2016);
}
}