Bom dia Pessoal,
Andei pesquisando, mas não achei algo relacionado. Quando exporto minha JTable para o excel, ele exporta em formato text, porém preciso de que uma coluna seja no formato date para aplicaro filtro.
Apliquei algumas regras, porém não obtive sucesso.
O código segue abaixo…
Só entra no formato date, quando abro o excel e do um F2 em cada célula, ai sim fica convertida para o formato desejado.
Alguma sugestão?
public void salvandoexcel(String saida) throws IOException {
HSSFWorkbook wb = new HSSFWorkbook();
HSSFSheet sheetDADOS = wb.createSheet(“Dados”);
HSSFCellStyle style = wb.createCellStyle();
style.setDataFormat(HSSFDataFormat.getBuiltinFormat(“m/d/yy”));
FileOutputStream fileOut = new FileOutputStream(saida + “.xls”);
try {
for (int i = 0; i < jTable1.getRowCount(); ++i) {
sheetDADOS.createRow(i);
//for (int j = 0; j < jTable1.getColumnCount(); ++j) {
int j = 12;
try {
String s = jTable1.getValueAt(i, j).toString();
sheetDADOS.getRow(i).createCell((short) j);
sheetDADOS.getRow(i).getCell((short) j).setCellValue(new java.util.Date());
sheetDADOS.getRow(i).getCell((short) j).setCellValue(s.trim());
//sheetDADOS.getRow(i).getCell((short) j).setCellValue(s);
sheetDADOS.getRow(i).getCell((short) j).setCellStyle(style);
} catch (Exception exc) {
exc.printStackTrace();
break;
}
//}
}
wb.write(fileOut);
fileOut.flush();
fileOut.close();
JOptionPane.showMessageDialog(null, “Salvo com sucesso!!”);
} catch (Exception ex) {
fileOut.close();
ex.printStackTrace();
JOptionPane.showMessageDialog(null, “Erro ao tentar salvar arquivo!!”);
}
}
Vlw!!