I have to create an excel file programatically. Is there is any API to create an excel file or some other ways?
EDIT on 7th Nov 2011
I tried example Create an
First You have to go to this link, from which you can download latest library:
http://www.apache.org/dyn/closer.cgi/poi/release/bin/poi-bin-3.9-20121203.tar.gz
After that Put below code on onCreate or onResume Mehod:
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet firstSheet = workbook.createSheet("Sheet No: 1");
HSSFSheet secondSheet = workbook.createSheet("Sheet No: 2");
HSSFRow rowA = firstSheet.createRow(0);
HSSFCell cellA = rowA.createCell(0);
cellA.setCellValue(new HSSFRichTextString("Sheet One"));
HSSFRow rowB = secondSheet.createRow(0);
HSSFCell cellB = rowB.createCell(0);
cellB.setCellValue(new HSSFRichTextString("Sheet two"));
FileOutputStream fos = null;
try {
String str_path = Environment.getExternalStorageDirectory().toString();
File file ;
file = new File(str_path, getString(R.string.app_name) + ".xls");
fos = new FileOutputStream(file);
workbook.write(fos);
} catch (IOException e) {
e.printStackTrace();
} finally {
if (fos != null) {
try {
fos.flush();
fos.close();
} catch (IOException e) {
e.printStackTrace();
}
}
Toast.makeText(MainActivity.this, "Excel Sheet Generated", Toast.LENGTH_SHORT).show();
}
// To see this excel file go to File Explorer in eclipse -> SDCard Path -> Excel.xls -> Pull it -> See it.