Fala galera
Estou com um problema para gerar arquivos xlsx com o apache poi.
Conseguir gerar o xls de boa, porém necessito de muitas linhas e tenho que gerar em xlsx, porém não estou conseguindo.
Abaixo minha classe, se alguém souber me ajudar agradeço.
PreparedStatement ps;
ResultSet rs;
// CONVERTENDO NUMEROS PONTO POR VIRGULA
Locale ptBR = new Locale("pt", "BR");
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet sheet = workbook.createSheet("razao");
XSSFRow row = sheet.createRow(0);
XSSFCell cell;
//CRIANDO CABECALHO
cell = row.createCell(1);
cell.setCellValue("empresa");
cell = row.createCell(2);
cell.setCellValue("data_lanc");
cell = row.createCell(3);
cell.setCellValue("conta");
cell = row.createCell(4);
cell.setCellValue("lote");
cell = row.createCell(5);
cell.setCellValue("lote_sublote");
cell = row.createCell(6);
cell.setCellValue("usuario");
cell = row.createCell(7);
cell.setCellValue("lc_origem");
cell = row.createCell(8);
cell.setCellValue("sis_ger");
cell = row.createCell(9);
cell.setCellValue("tp_lanc");
cell = row.createCell(10);
cell.setCellValue("centro_custo");
cell = row.createCell(11);
cell.setCellValue("num_lp");
cell = row.createCell(12);
cell.setCellValue("val_lanc");
cell = row.createCell(13);
cell.setCellValue("historico");
cell = row.createCell(14);
cell.setCellValue("recno");
try {
String sql = "SELECT * FROM razao_contabil_web " + query;
ps = (PreparedStatement) con.prepareStatement(sql);
rs = ps.executeQuery();
int i = 1;
while (rs.next()) {
// VALORES DAS LINHAS
row = sheet.createRow(i);
cell = row.createCell(1);
cell.setCellValue(rs.getString("empresa"));
cell = row.createCell(2);
cell.setCellValue(rs.getString("data_lanc"));
cell = row.createCell(3);
cell.setCellValue(rs.getString("conta"));
cell = row.createCell(4);
cell.setCellValue(rs.getString("lote"));
cell = row.createCell(5);
cell.setCellValue(rs.getString("lote_sublote"));
cell = row.createCell(6);
cell.setCellValue(rs.getString("usuario"));
cell = row.createCell(7);
cell.setCellValue(rs.getString("lc_origem"));
cell = row.createCell(8);
cell.setCellValue(rs.getString("sis_ger"));
cell = row.createCell(9);
cell.setCellValue(rs.getString("tp_lanc"));
cell = row.createCell(10);
cell.setCellValue(rs.getString("centro_custo"));
cell = row.createCell(11);
cell.setCellValue(rs.getString("num_lp"));
cell = row.createCell(12);
cell.setCellValue(NumberFormat.getInstance(ptBR).format(rs.getFloat("val_lanc")));
cell = row.createCell(13);
cell.setCellValue(rs.getString("historico"));
cell = row.createCell(14);
cell.setCellValue(rs.getString("recno"));
i++;
} // fim do while
//FileOutputStream out = new FileOutputStream(new File("/home/elisandro/relatorios/razaoContabil.xlsx"));
FileOutputStream out = new FileOutputStream(new File("C:\\Users\\elisandro.nunes\\Desktop\\razaoContabil.xlsx"));
workbook.write(out);
out.close();
