private File saveExcelFile(Context context, String fileName, List<Urun> urunList, String sendEmail, String unvan) {
//New Workbook
Workbook wb = new HSSFWorkbook();
Cell c = null;
//Cell style for header row
CellStyle cs = wb.createCellStyle();
cs.setFillForegroundColor(HSSFColor.LIME.index);
cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//New Sheet
Sheet sheet1 = null;
sheet1 = wb.createSheet("New Order");
Row row = sheet1.createRow(0);
c = row.createCell(0);
c.setCellValue("Item Number");
c.setCellStyle(cs);
c = row.createCell(1);
c.setCellValue("Ürün adı");
c.setCellStyle(cs);
c = row.createCell(2);
c.setCellValue("Barkod numarası");
c.setCellStyle(cs);
c = row.createCell(3);
c.setCellValue("Birim fiyatı");
c.setCellStyle(cs);
c = row.createCell(4);
c.setCellValue("Adet");
c.setCellStyle(cs);
c = row.createCell(5);
c.setCellValue("Toplam");
c.setCellStyle(cs);
for (int i = 0; i < urunList.size(); i++) {
row = sheet1.createRow((i + 1));
c = row.createCell(0);
c.setCellValue((i + 1));
c.setCellStyle(cs);
c = row.createCell(1);
c.setCellValue(urunList.get(i).getName());
c.setCellStyle(cs);
c = row.createCell(2);
c.setCellValue(urunList.get(i).getBarcod());
c.setCellStyle(cs);
c = row.createCell(3);
c.setCellValue(urunList.get(i).getPrice());
c.setCellStyle(cs);
c = row.createCell(4);
c.setCellValue(urunList.get(i).getLsql_adet());
c.setCellStyle(cs);
c = row.createCell(5);
c.setCellValue((Integer.valueOf(urunList.get(i).getPrice()) * urunList.get(i).getLsql_adet()));
c.setCellStyle(cs);
}
row = sheet1.createRow((urunList.size() + 3));
c = row.createCell(0);
c.setCellValue(sendEmail);
c.setCellStyle(cs);
c = row.createCell(1);
c.setCellValue(unvan);
c.setCellStyle(cs);
sheet1.setColumnWidth(0, (15 * 400));
sheet1.setColumnWidth(1, (15 * 400));
sheet1.setColumnWidth(2, (15 * 400));
sheet1.setColumnWidth(3, (15 * 400));
sheet1.setColumnWidth(4, (15 * 400));
sheet1.setColumnWidth(5, (15 * 400));
// Create a path where we will place our List of objects on external storage
File file = new File(context.getExternalFilesDir(null), fileName);
FileOutputStream os = null;
try {
os = new FileOutputStream(file);
wb.write(os);
Log.w("FileUtils", "Writing file" + file);
} catch (IOException e) {
Log.w("FileUtils", "Error writing " + file, e);
} catch (Exception e) {
Log.w("FileUtils", "Failed to save file", e);
} finally {
try {
if (null != os)
os.close();
} catch (Exception ex) {
}
}
return file;
}