How to Save Excel with JFileChooser?

0

I try to save an Excel using a JFileChooser , I have something of this style where I can easily create a Excel .

Workbook book = new XSSFWorkbook();
Sheet sheet = book.createSheet("EntregaRecepcion");
FileOutputStream fileOut;
try {            
    Connection con = null;
    con = getConection();
    PreparedStatement ps;
    ResultSet res;
    int numfilaDatos = 1;
    ps = con.prepareStatement("EXEC PA_ENTREGA " + quincena.getSelectedItem() + "," + ano.getSelectedItem());
    res = ps.executeQuery();
    int numCol = res.getMetaData().getColumnCount(); 

    while (res.next()) {  
        Row filaDatos = sheet.createRow(numfilaDatos);
        for (int a = 0; a < numCol; a++) {
            Cell celdaDatos = filaDatos.createCell(a);
            String zhy = res.getString(1);
            if (a == 9) {
                celdaDatos.setCellValue(res.getDouble(a + 1));
            } else {
                celdaDatos.setCellValue(res.getString(a + 1));
            }    
        }
        numfilaDatos++;                   
    }

    fileOut = new FileOutputStream("Entrega a Recepcion1.xlsx");
    book.write(fileOut);
    fileOut.close();   
} catch (SQLException ex) {  
    Logger.getLogger(prueba.class.getName()).log(Level.SEVERE, null, ex);
}
    
asked by Summer 27.07.2018 в 18:39
source

1 answer

0
Workbook wb = new XSSFWorkbook();
//tu código de XSSFWorkbook
JFileChooser fileChooser = new JFileChooser();
int option = fileChooser.showSaveDialog(null);
if(option == JFileChooser.APPROVE_OPTION){
      if(chooser.getSelectedFile()!=null){
          FileOutputStream out = new FileOutputStream( chooser.getSelectedFile() +".xls");
          wb.write(out);
       }      
    }
    
answered by 30.07.2018 / 17:34
source