IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Java Discussion :

Fenêtre pour définir l'endroit où enregistrer un fichier Excel créé


Sujet :

Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Inscrit en
    Avril 2007
    Messages
    18
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 18
    Par défaut Fenêtre pour définir l'endroit où enregistrer un fichier Excel créé
    Salut,

    J'ai une application qui permet de créer un fichier Excel.
    le souci c'est que dans le code je précise que le fichier sera crée sur le disque dur comme suit:
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    WritableWorkbook workbook = Workbook.createWorkbook(new File("sortie.xls"));
    WritableSheet sheet = workbook.createSheet("Premier classeur", 0);
    or moi , je souhaiterais plutôt avoir la possibilité de déterminer moi même l'endroit où je souhaiterais créer mon fichier.

    Merci pour votre aide

  2. #2
    Membre Expert

    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2004
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 2 301

  3. #3
    Membre averti
    Inscrit en
    Avril 2007
    Messages
    18
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 18
    Par défaut
    Merci pour votre réponse:
    mon code est le suivant :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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;
    	             }
    	 }
     
    }
    comment est ce que je peux utiliser JFileChooser?

  4. #4
    Membre Expert

    Homme Profil pro
    Consultant informatique
    Inscrit en
    Janvier 2004
    Messages
    2 301
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Suisse

    Informations professionnelles :
    Activité : Consultant informatique
    Secteur : Finance

    Informations forums :
    Inscription : Janvier 2004
    Messages : 2 301
    Par défaut
    comme indiqué dans la doc...

Discussions similaires

  1. Réponses: 1
    Dernier message: 31/03/2014, 13h26
  2. [XL-2013] Une macro pour enregistrer un fichier excel en pdf
    Par petchy dans le forum Excel
    Réponses: 5
    Dernier message: 29/03/2014, 12h45
  3. [VBA]enregistrer en fichier excel en macro
    Par jazziestan dans le forum SDK
    Réponses: 12
    Dernier message: 29/12/2006, 10h07
  4. [Excel] Enregistrer un fichier Excel côté client
    Par scorpking dans le forum Bibliothèques et frameworks
    Réponses: 14
    Dernier message: 18/07/2006, 11h10
  5. Ouvrire ou Enregistrer un Fichier Excel
    Par jo281 dans le forum ASP
    Réponses: 1
    Dernier message: 13/12/2005, 18h55

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo