我有现有的java代码,它将获取在应用程序中生成的表并将其导出到Excel电子表格,但是现在它正在按原样写入Excel电子表格,没有任何格式。我希望能够添加到java代码以扩展每一列(例如双击Excel中的列)以适合文本。我如何实现这一目标?
下面是写入excel电子表格的代码部分
/**
* This method writes data to the row.
*
* @param header The header row for the data to be written.
*
* @param data The data rows to be written.
*
* @param rowIndex The starting index for the row.
*
* @param columnIndex The starting index for the column.
*
* @throws IOException The file cannot be written to.
*
* @throws FileNotFoundException The file cannot be found or open.
*/
private HSSFSheet dataSheet;
private int processDataToSheet(List<Excel_o> header, List<List<Excel_o>> data, int rowIndex, int columnIndex)
throws IOException, FileNotFoundException
{
//process header data
processRowData(dataSheet, rowIndex, header, columnIndex);
//write data to sheet
for(List<Excel_o> singleList: data){
//process data for the whole row.
processRowData(dataSheet, ++rowIndex, singleList, columnIndex);
}
return rowIndex;
}
我查找了apachi.poi.hssf.usermodel.HSSFSheet(我的代码中的datasheet变量)可用的方法,它说它有一个名为autoSizeColumn的方法,但当我查看Eclipse中的下拉列表时,那里没有这样的选择。有这样的原因吗?