Good afternoon,
i develop a java function for my application that, starting from a JTable, make the export in a formatted sheet in .xlsx
This is the code of the function that take jtable and the "excel file name" to export it:
public void toExcel(JTable table, String nome_resoconto) throws Exception{
try{
TableModel model = (my_table_model_class) table.getModel();
SXSSFWorkbook wb = new SXSSFWorkbook(100);
//wb.setCompressTempFiles(true);
SXSSFSheet sheet = wb.createSheet();
//sheet.setRandomAccessWindowSize(100);
SXSSFRow row = sheet.createRow(0);
CellStyle headercellStyle = wb.createCellStyle();
org.apache.poi.ss.usermodel.Font font = wb.createFont();
font.setColor(HSSFColor.HSSFColorPredefined.RED.getIndex());
headercellStyle.setAlignment(HorizontalAlignment.CENTER);
headercellStyle.setFont(font);
//
for (int i = 0; i < model.getColumnCount(); i++) {
SXSSFCell cell = row.createCell(i);
cell.setCellStyle(headercellStyle);
cell.setCellValue(model.getColumnName(i));
}
//
for (int i = 0; i < model.getRowCount(); i++) {
row = sheet.createRow(i + 1);
for (int j = 0; j < model.getColumnCount(); j++) {
SXSSFCell cell = row.createCell(j);
cell.setCellValue(model.getValueAt(i, j).toString());
}
}
sheet.setColumnWidth(0, 1); //Hide first column
//Adjust width
for(int i = 1; i < model.getColumnCount(); i++)
{
sheet.trackColumnForAutoSizing(i);
sheet.autoSizeColumn(i);
}
FileOutputStream fileOut = new FileOutputStream("stampe/"+nome_resoconto);
wb.write(fileOut);
fileOut.close();
}catch(IOException e){ System.out.println(e); }
}
The issue is that: When i run the application on my Windows 10 , it run very fast , but when i run it on costumer’s Windows Server 2016 , it run about 10/15 times slower…
Details:
- Costumer hardware is better than mine
- We have the same min/max heap configuration
- Java is the same build (the last) and has the same configuration
- I make test with high and low load
- I already use SXSSF instead of XSSF lib.
Thank you..
Source: Windows Questions