1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188
| ////////Classe du boutton save
private boolean saveExcelFile(Context context, String fileName) {
/////////Activer le boutton excel quand un ordre a ete enregistrer
BTNExcel = (Button) findViewById(R.id.BouttonExcel);
//////Active le bouton apres la sauvegarde du premiere ordre
BTNExcel.setEnabled(true);
BTNDel = (Button) findViewById(R.id.del);
//////Active le bouton apres le choix de la catégorie
BTNDel.setEnabled(true);
/////////////////Variable
final int mois = d.getMonth() + 1;
final int annees = d.getYear() - 100;
final int jours = d.getDate();
final String datesok = jours + "." + mois + "." + annees;
Date date = new Date();
SimpleDateFormat f = new SimpleDateFormat("HH:mm");
String heureordre = f.format(date);
//récuperation de l'ordre au clique
//Récuperation ordre
Spinner spinner = (Spinner) findViewById(R.id.ordre_spinner);
String text = spinner.getSelectedItem().toString();
////////////////Création des variable
String Espace = " ";
String NameCI = NameChef + Espace;
String NameInterNew = Espace;
String NameCISpiner = Espace;
String NameType = Espace ;
String orderName = text + Espace ;
String NameDate = datesok + Espace;
String NameHeure = heureordre + Espace;
String NameDateNew =+day+"-"+month+"-"+year+ Espace;
String NameHeureNew = hour+"-"+minute;
year = 0;
month = 0;
day = 0;
hour = 0;
minute = 0;
/////////////////////////
// check if available and not read only
if (!isExternalStorageAvailable() || isExternalStorageReadOnly()) {
Log.w("FileUtils", "Storage not available or read only");
return false;
}
boolean success = false;
//New Workbook
// 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;
FileInputStream file = null;
try {
file = new FileInputStream(new File(context.getExternalFilesDir(null), fileName));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
HSSFWorkbook wb = null;
try {
wb = new HSSFWorkbook(file);
} catch (IOException e) {
e.printStackTrace();
}
// Workbook wb = new HSSFWorkbook();
Cell c = null;
//Cell pleine
CellStyle cs = wb.createCellStyle();
cs.setFillForegroundColor(HSSFColor.LIME.index);
cs.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
//Cell vide
CellStyle csvide = wb.createCellStyle();
csvide.setFillForegroundColor(HSSFColor.WHITE.index);
csvide.setFillPattern(HSSFCellStyle.SOLID_FOREGROUND);
// csvide.setUnderline(HSSFFont.U_SINGLE);
// my_style.setFont(my_font);
//New Sheet
HSSFSheet sheet1 = wb.getSheetAt(0);
//Sheet sheet1 = null;
//sheet1 = wb.createSheet("Intervention2");
/////////////////
/////////////////
// Generate column headings
////////////////////////////////////ICI a rajputer +1
//int rownum = sheet1.getLastRowNum();
int rownum = sheet1.getLastRowNum()+1;
Log.d("Debug", String.valueOf(rownum));
//////////////////////////////
//Update the value of cell
// Row row = sheet1.getRow(0);
// row.createCell(3).setCellValue("Value 2");
/////////////////////////////////
Row row = sheet1.createRow(rownum);
//Row row1 = sheet1.createRow(1);
c = row.createCell(0);
c.setCellValue(orderName);
c.setCellStyle(cs);
c = row.createCell(1);
c.setCellValue(NameDate);
c.setCellStyle(cs);
c = row.createCell(2);
c.setCellValue(NameHeure);
c.setCellStyle(cs);
c = row.createCell(3);
c.setCellValue("");
c.setCellStyle(cs);
c = row.createCell(4);
c.setCellValue("");
c.setCellStyle(cs);
c = row.createCell(5);
c.setCellValue("");
c.setCellStyle(cs);
c = row.createCell(6);
c.setCellValue(NameDateNew);
c.setCellStyle(cs);
c = row.createCell(7);
c.setCellValue(NameHeureNew);
c.setCellStyle(cs);
c = row.createCell(8);
c.setCellValue("");
c.setCellStyle(csvide);
c = row.createCell(9);
c.setCellValue("");
c.setCellStyle(csvide);
c = row.createCell(10);
c.setCellValue("");
c.setCellStyle(csvide);
c = row.createCell(11);
c.setCellValue("");
c.setCellStyle(csvide);
sheet1.setColumnWidth(0, (15 * 500));
sheet1.setColumnWidth(1, (15 * 250));
sheet1.setColumnWidth(2, (15 * 200));
sheet1.setColumnWidth(3, (15 * 250));
sheet1.setColumnWidth(4, (15 * 250));
sheet1.setColumnWidth(5, (15 * 200));
sheet1.setColumnWidth(6, (15 * 200));
sheet1.setColumnWidth(7, (15 * 200));
sheet1.setColumnWidth(8, (15 * 350));
sheet1.setColumnWidth(9, (15 * 300));
sheet1.setColumnWidth(10, (15 * 300));
sheet1.setColumnWidth(11, (15 * 300));
try {
// file = new FileInputStream(new File(context.getExternalFilesDir(null), fileName+2));
FileOutputStream outFile = new FileOutputStream(new File(context.getExternalFilesDir(null), fileName));
// workbook.write(outFile);
// os = new FileOutputStream(file);
wb.write(outFile);
Log.w("FileUtils", "Writing file" + file);
success = true;
} 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 success;
} |
Partager