0
這是我有:如何使用POI Excel以編程方式拉伸列以適應文本?
這就是我想要的:
我使用POIExcel創建一個Excel文檔和編程設置相應的頭文件,如你可以看到下面。然後在我的printSubnetInfo()
方法中添加下面的行。我想要做的是確保在打開文檔時將列拉伸以適應文本。忽略粗體!
String outputs = "\\outputs\\";
String filename = homepath + outputs + customer + ".xls";
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet sheet = workbook.createSheet("Subnet Information");
// Create Excel document header row
HSSFRow rowhead = sheet.createRow((short)0);
rowhead.createCell(0).setCellValue("Default Gateway");
rowhead.createCell(1).setCellValue("CIDR Signature");
rowhead.createCell(2).setCellValue("Netmask");
rowhead.createCell(3).setCellValue("Network Address");
rowhead.createCell(4).setCellValue("Broadcast Address");
rowhead.createCell(5).setCellValue("Lowest Address");
rowhead.createCell(6).setCellValue("Highest Address");
rowhead.createCell(7).setCellValue("# of Subnet Addresses");
// Add rows to Excel document
for (int rowNum = 1; rowNum < (defaultGWsList).size(); rowNum++) {
String defaultGWAddr = defaultGWsList.get(i);
printSubnetInfo(subnetInfo, defaultGWAddr, homepath, customer, sheet, rowNum);
}
// Create Excel file
FileOutputStream fileOut = new FileOutputStream(filename);
workbook.write(fileOut);
fileOut.close();
System.out.println("Your excel file has been generated!");
謝謝。這工作。我想大量的列你想循環通過它們。 (int colNumber = 0; colNumber <= 7; colNumber ++){sheet.autoSizeColumn(colNumber); }'' – santafebound
是的。你必須循環逐列。大數據集可能會很慢。 – arturro