Skip to content

Instantly share code, notes, and snippets.

@chukitow
Created December 26, 2013 07:08
Show Gist options
  • Save chukitow/8130742 to your computer and use it in GitHub Desktop.
Save chukitow/8130742 to your computer and use it in GitHub Desktop.
try
{
File archivo = new File("datos.xls");
TableModel modelo = jTable1.getModel();
FileWriter excel = new FileWriter(archivo);
for(int i = 0; i < modelo.getColumnCount(); i++)
{
excel.write(modelo.getColumnName(i) + "/t");
}
excel.write("\n");
for(int i=0; i< modelo.getRowCount(); i++)
{
for(int j=0; j < modelo.getColumnCount(); j++)
{
String data = (String)modelo.getValueAt(i, j);
if(data == "null")
{
data="";
}
excel.write(data+"/t");
}
excel.write("\n");
}
excel.close();
JOptionPane.showMessageDialog(null, "Archivo Creado");
} catch (IOException ex)
{
Logger.getLogger(Alumnos_view.class.getName()).log(Level.SEVERE, null, ex);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment