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
|
package iodasweb.report.action;
import iodasweb.fondation.types.Comparator;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Locale;
import javax.swing.JFileChooser;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.format.Colour;
import jxl.format.ScriptStyle;
import jxl.format.UnderlineStyle;
import jxl.write.Label;
import jxl.write.WritableCellFormat;
import jxl.write.WritableFont;
import jxl.write.WritableSheet;
import jxl.write.WritableWorkbook;
import jxl.write.WriteException;
public class Report {
public Report(){}
public void doReport(ArrayList<ArrayList<String>> liste)
{
OuvertureFichier of = new OuvertureFichier();
// String filename ="";
try
{
String filename = "c:\\input.xls";
WorkbookSettings ws = new WorkbookSettings();
ws.setLocale(new Locale("en", "EN"));
WritableWorkbook workbook =
Workbook.createWorkbook(new File(filename), ws);
WritableSheet s = workbook.createSheet("Sheet1", 0);
writeDataSheet(s, liste);
workbook.write();
workbook.close();
// }
}
catch (IOException e)
{
e.printStackTrace();
}
catch (WriteException e)
{
e.printStackTrace();
}
}
private void writeDataSheet(WritableSheet s, ArrayList<ArrayList<String>> liste )
throws WriteException
{ int indexRow=1 ,indexCol =0;
int index=0;
for (ArrayList<String> data : liste) {
for (String element : data) {
if (Comparator.getInstance().isNotBlank(element)) {
if ((element.contentEquals("&39;")) || (element.contentEquals("&32;"))){
element = element.replaceAll("&39;", "'");
element = element.replaceAll("&32;", " ");
data.set(index, element);
}
}
index++;
}
index = 0;
}
//format des cellules du nom des colonnes
WritableFont arial10font = new WritableFont(WritableFont.ARIAL, 14,WritableFont.BOLD, true, UnderlineStyle.NO_UNDERLINE,Colour.BLUE, ScriptStyle.NORMAL_SCRIPT);
WritableCellFormat arial10format = new WritableCellFormat(arial10font);
//noms de colonnes à la ligne 0 avec le format spécifique
for ( String colNom : liste.get(liste.size()-1)) {
Label label = new Label(indexCol, 0, colNom, arial10format);
s.addCell(label);
indexCol++;
}
indexCol = 0;
for (ArrayList<String> data : liste.subList(0, (liste.size()-1))) {
for (String element : data) {
//
Label label = new Label(indexCol, indexRow,element);
s.addCell(label);
indexCol++;
}
indexRow++;
indexCol = 0;
}
}
} |
Partager