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
| package telnet;
import java.io.File;
import java.io.IOException;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.Vector;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import jxl.Sheet;
import jxl.Workbook;
import jxl.format.Colour;
import jxl.format.UnderlineStyle;
import jxl.read.biff.BiffException;
import jxl.write.*;
import jxl.write.biff.RowsExceededException;
/**
*
* @author wassila
*/
public class xls1 {
private int ind;
public xls1(){
}
public int GetInd(){
return ind;
}
public void XLS_Export(ArrayList<Etat> liste){
JFrame controllingFrame = new JFrame();
ArrayList<Etat> etat;
ind = 0;
try {
Workbook workbook = null;
int i,m;
boolean bool = false;
String stringa1 = null;
String version = null;
try {
workbook = Workbook.getWorkbook(new File("model/Model.xls"));
} catch (BiffException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Sheet sheet = workbook.getSheet(0);
WritableWorkbook copy = Workbook.createWorkbook(new File("Diagnostic/Route Diag.xls"), workbook);
WritableSheet Add = copy.getSheet(0);
WritableCellFormat formatRed = new WritableCellFormat(new WritableFont(WritableFont.TIMES,10,
WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.RED));
WritableCellFormat formatBlack = new WritableCellFormat(new WritableFont(WritableFont.ARIAL,10,
WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK));
System.out.println("Export XLS");
Label label2;
for(int n=0,ligne=0;n<liste.size();n++){
etat = new ArrayList<Etat>(liste.get(n).GetListe());
System.out.println(n+"/"+liste.size());
for(i=0;i<etat.size();i++){
if(etat.get(i).getDiag().equals("NOK")){
ind++;
}
label2 = new Label(1,ligne+2, etat.get(i).getAdresseip(),formatBlack);
Add.addCell(label2);
label2 = new Label(2,ligne+2, etat.get(i).getHostname(),formatBlack);
Add.addCell(label2);
label2 = new Label(3,ligne+2, etat.get(i).getEtat(),formatRed);
Add.addCell(label2);
ligne++;
}
}
workbook.close();
copy.write();
copy.close();
} catch (WriteException ex) {
Logger.getLogger(xls1.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(xls1.class.getName()).log(Level.SEVERE, null, ex);
}
/*try {
Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler Diagnostic.xls");
} catch (Exception ee) {JOptionPane.showMessageDialog(controllingFrame, "there is a problem, "
+ "the Excel File can not be opened");}// afficher le fichier avec l'execution
*/
}
} |
Partager