.xls file corrupted and without template with warning cannot read name?

50 Views Asked by At

After downloading my .xls file, it brings me data in column but Excel shows me a warning which is:

office has detected a problem with this file, Editing may harm your computer.

The main purpose that I have a file that I need to download based on a prepared template, the version of the jxl that I work with is 2.4.2; the code below works well. I have succeeded to download the file with data but already without the template which defined in my project directory.

public class CreaterFileExcel
{

    private static Connection connexion=null;
    private static PreparedStatement pstmt = null;
    private static PreparedStatement pstmt2 = null;
    public  static ArrayList<Date> listeDrmf = new ArrayList<Date>();
    public  static ArrayList<Date> listeJoursFeries = new ArrayList<Date>();
    public static void creerCalendrier(String annee, String versionFac, String versionPrel)
    {
        ResultSet rset = null;
        ResultSet rset2 = null;
        String groupeMen;
        String groupeBim;
        String lot;
        String vague;
        String jourDft;
        String jourDft1;
        String dateDft;
        String dateDft1;
        String jourDrmf;
        String dateDrmf;
        String jourExtraction;
        String dateExtraction;
        String jourPs2;
        String datePs2;
        String jourFacture;
        String dateFacture;

        int delai;
        int drmfType = 0;
        boolean reportPS2 = false;
        String apr = null;
        String bon = null;
        String col = null;
        String men = null;
        String mex = null;
        String idCalFac;
        int lineNumber;
        String groupe;

        String occurence;

    
        Date dateNom;

        Date datePorteFac;


        Date dateValeur;

        int delta;


        int result = 0; 
        String query ="";

        int k = 0;
        int i = 0;
        int w = 9;

        try {

            Locale.setDefault(Locale.FRANCE);
            
            String nomFichierExcel = "D:\\Calendrier"+annee+"-"+versionFac+"-"+versionPrel+".xls"; // Nom du calendrier de sortie
            String filePath = "D:\\IhmFac3107\\ihmfac-calender-war\\CALWAS\\template.xls";          
            WorkbookSettings ws = new WorkbookSettings() ;
            ws.setSuppressWarnings(true);
            Workbook workbook = Workbook.getWorkbook(new File(filePath),ws); 

            WritableWorkbook copy = Workbook.createWorkbook(new File(nomFichierExcel), workbook );

            WritableSheet sheet = copy.getSheet(0); 

            WritableSheet sheet2 = copy.getSheet(1);

            connexion = ServletCalendrier.getConnexion();
            pstmt= connexion.prepareStatement("SELECT idCalFac, groupeMen, groupeBim, dft, lot, vague, drmf, extraction, ps2, dateFacture, delai, drmfType FROM TgCalFac WHERE annee LIKE ? AND versionFac LIKE ? ORDER BY dft, vague");
            pstmt.setString(1, annee);
            pstmt.setString(2, versionFac);
            rset=pstmt.executeQuery();


            Utils.ecrire(sheet,0,3,"Version " + annee + "-" + versionFac + "-" + versionPrel,0,3);
            Utils.ecrire(sheet, 0, 0, annee, 0, 0);

            int j = 9;


            while(rset.next())
            {
                idCalFac = rset.getString("idCalFac");
                groupeMen = rset.getString("groupeMen");
                groupeBim = rset.getString("groupeBim");

                lot = rset.getString("lot");
                vague = rset.getString("vague");

                jourDft = OperationsSurDates.jourSemaine(rset.getDate("dft"));
                dateDft = OperationsSurDates.changeFormatDate(rset.getDate("dft"));

                jourDrmf = OperationsSurDates.jourSemaine(rset.getDate("drmf"));
                dateDrmf = OperationsSurDates.changeFormatDate(rset.getDate("drmf"));

                jourExtraction = OperationsSurDates.jourSemaine(rset.getDate("extraction"));
                dateExtraction = OperationsSurDates.changeFormatDate(rset.getDate("extraction"));

                jourPs2 = OperationsSurDates.jourSemaine(rset.getDate("ps2"));
                datePs2 = OperationsSurDates.changeFormatDate(rset.getDate("ps2"));

                jourFacture = OperationsSurDates.jourSemaine(rset.getDate("dateFacture"));
                dateFacture = OperationsSurDates.changeFormatDate(rset.getDate("dateFacture"));

                delai = rset.getInt("delai");

                drmfType = rset.getInt("drmfType");

                if(vague.equals("A")){
                    lineNumber = 7;
                }else{
                    lineNumber = 8;
                }

                Utils.ecrire(sheet,0,j,groupeMen,0,lineNumber);
                Utils.ecrire(sheet,1,j,annee,1,lineNumber);
                Utils.ecrire(sheet,2,j,groupeBim,2,lineNumber);
                Utils.ecrire(sheet,3,j,lot,3,lineNumber);


                Utils.ecrire(sheet,4,j,jourDft,4,lineNumber);
                Utils.ecrire(sheet,5,j,dateDft,5,lineNumber);


                Utils.ecrire(sheet,6,j,vague,6,lineNumber);

                             .
                             .
                             .
}
0

There are 0 best solutions below