我有現有的Java代碼,將抓住應用程序中生成的表並將其導出到Excel電子表格,但現在它正在寫入Excel電子表格,沒有任何格式。我希望能夠添加到Java代碼來擴展每列(如雙擊Excel中的列)以適應文本。我如何實現這一目標?Java代碼擴大每一列以適應文本(自動調整功能)
繼承人寫入到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(在我的代碼數據表變量)方法的代碼的一部分,它說它有一個名爲autoSizeColumn的方法,但是當我查看Eclipse中的下拉列表時,沒有可用的選項。有這個原因嗎?
那你到底要?請展示一些你已經出現的東西。 – Ravi
您是否使用Apache POI在Java中生成Excels? –
是的即時通訊使用Apache poi生成Excels – user974047