Java_feuille excel

camile.Likotelo Messages postés 4 Date d'inscription jeudi 31 mars 2016 Statut Membre Dernière intervention 5 avril 2016 - 31 mars 2016 à 18:29
 Utilisateur anonyme - 11 avril 2016 à 12:05
Bonjour,
je m’appel Camile , juste je programme en java avec ID netbeans et je un soucis de crées une classe qui permet de prendre une feuille excel et de créer un fichier de cette feuille svp.
A voir également:

5 réponses

Utilisateur anonyme
31 mars 2016 à 18:45
Votre question n'est pas claire, j'ai pas compris "créer un fichier de cette feuille"
0
camile.Likotelo Messages postés 4 Date d'inscription jeudi 31 mars 2016 Statut Membre Dernière intervention 5 avril 2016
31 mars 2016 à 19:01
svp yassine,
juste une classe java qui prend la feuille1,feuille2,feuille3 d'un classeur excel et créer chaque feuille un fichier excel. donc voici comment je fait en vba "

Sub Splitbook()
'Updateby20140612
Dim xPath As String
xPath = Application.ActiveWorkbook.Path
Application.ScreenUpdating = False
Application.DisplayAlerts = False
For Each xWs In ThisWorkbook.Sheets
xWs.Copy
Application.ActiveWorkbook.SaveAs Filename:=xPath & "\" & xWs.Name & "__" & " " & xWs.Name & "- 30 - March 16" & ".xls"
Application.ActiveWorkbook.Close False
Next
Application.DisplayAlerts = True
Application.ScreenUpdating = True
End Sub
"
en java ca marche pas chez moi
0
Je suis dsl pour ce retard
1. Télécharger POI (une bib trés puissante développée par la fameuse Apache ) pour manipuler les fichiers excels
http://www.apache.org/dyn/closer.lua/poi/release/bin/poi-bin-3.12-20150511.zip
2.ajouter les jars à votre path

on supponse qu'on a un fichier qui contient 5 feuilles

Code :

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Iterator;

import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class Main {

public static void main(String[] args) throws IOException {
String Workbookpath="file.xlsx";
XSSFWorkbook XW =ReadWorkbook(Workbookpath);
//here you put how many sheet in your workbook
int sheetNumber=5;
for(int index=0; index<=sheetNumber;index++){
XSSFWorkbook wb = new XSSFWorkbook();
XSSFSheet sheet=CreateNewWorkBook(wb,"sheet"+index+".xlsx");
ReadDataFromSheet(index,XW,sheet);
FileOutputStream fileOut = new FileOutputStream("sheet"+index+".xlsx");
wb.write(fileOut);
fileOut.close();
}


}
//Lire le fichier mére le workbook en anglais
public static XSSFWorkbook ReadWorkbook(String Workbookpath) throws IOException{
File WorkSheet = new File(Workbookpath);
FileInputStream fis = new FileInputStream(WorkSheet);
XSSFWorkbook XW = new XSSFWorkbook(fis);
return XW;
}
//nice til here
public static void ReadDataFromSheet(int SheetNumber,XSSFWorkbook XW,XSSFSheet sheet){
XSSFSheet HS= XW.getSheetAt(SheetNumber);
Iterator <Row> rowIterator = HS.iterator();

while(rowIterator.hasNext()){

Row nextRow = rowIterator.next();
XSSFRow row = sheet.createRow(nextRow.getRowNum());
Iterator <Cell> cellIterator = nextRow.cellIterator();
while(cellIterator.hasNext()){
Cell cell = cellIterator.next();

switch (cell.getCellType()) {
case Cell.CELL_TYPE_NUMERIC :
//on copie la valeur contenu dans le champ dans le nouveau champ dans la nouvelle feuille
row.createCell(cell.getColumnIndex()).setCellValue(cell.getNumericCellValue());
break;
case Cell.CELL_TYPE_STRING :
row.createCell(cell.getColumnIndex()).setCellValue(cell.getStringCellValue());
break;
case Cell.CELL_TYPE_BLANK :
//blank
row.createCell(cell.getColumnIndex()).setCellValue("");

break;
case Cell.CELL_TYPE_FORMULA :
row.createCell(cell.getColumnIndex()).setCellValue(cell.getCellFormula());
break;
case Cell.CELL_TYPE_BOOLEAN :
row.createCell(cell.getColumnIndex()).setCellValue(cell.getBooleanCellValue());
break;

default :

}
}

}
}
//Une méthode pour creer un nouveau workbook pour chaque feuille (sheet)
public static XSSFSheet CreateNewWorkBook(XSSFWorkbook wb ,String WorkbookName) throws IOException{

XSSFSheet sheet = wb.createSheet();

return sheet;
}





}


Ce code est valide pour les fichiers .xlsx
pour le rendre compatible avec les fichiers .xls il suffit de changer XSSFxxx par HSSFxxx
#Fadhlaoui
0
camile.Likotelo Messages postés 4 Date d'inscription jeudi 31 mars 2016 Statut Membre Dernière intervention 5 avril 2016
5 avril 2016 à 09:18
salut Yassine Fadhlaoui ,

Merci pour le lien, je télécharger après l’exécution voici ce que je comme l'exception.

prière de m'aider svp!

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject
at createfileexcel.CreateFileExcel.ReadWorkbook(CreateFileExcel.java:65)
at createfileexcel.CreateFileExcel.main(CreateFileExcel.java:48)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 2 more
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

je dois faire quoi pour que ça marche?
0
camile.Likotelo Messages postés 4 Date d'inscription jeudi 31 mars 2016 Statut Membre Dernière intervention 5 avril 2016
2 avril 2016 à 19:53
salut Yassine Fadhlaoui

j' avais reçu les scripts,mais y a improbleme pour le telechargement de POI.

ça m’écris " Not Found

The requested URL /dist/poi/releasbin/poibin3.12-20150511.zipwas
not found on this server."

aide moi si tu on avais chez toi
0
Camile.likotelo
3 avril 2016 à 18:21
salut Yassine Fadhlaoui ,

Merci pour le lien, je télécharger après l’exécution voici ce que je comme l'exception.

prière de m'aider svp!

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlObject
at createfileexcel.CreateFileExcel.ReadWorkbook(CreateFileExcel.java:65)
at createfileexcel.CreateFileExcel.main(CreateFileExcel.java:48)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlObject
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:423)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
... 2 more
Java Result: 1
BUILD SUCCESSFUL (total time: 1 second)

je dois faire quoi pour que ça marche?
0

Vous n’avez pas trouvé la réponse que vous recherchez ?

Posez votre question
Utilisateur anonyme
11 avril 2016 à 12:05
Vous devez ajouter les bibliothéques POI à votre projet
cette erreur indique que java n'a pas pu trouver et charger les bibliothéques
la solution c'est ajouter ces bibs à votre projet .
je crois que vous utilisiez NetBeans comme IDE si oui vous devez ces étapes :
https://jsumon.wordpress.com/2009/11/24/adding-external-jar-or-library-to-netbeans-java-project/

si vous utilisez Eclipse ce lien est hyper utile :
http://www.oxfordmathcenter.com/drupal7/node/44


0
Rejoignez-nous