Question JAVA SVP ..

Fermé
scalabandri - Modifié par scalabandri le 13/06/2015 à 02:55
KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 - 13 juin 2015 à 16:03
Bonjour tout le monde,

SVP j'ai une question JAVA, Mon besoin c'est de faire un programme JAVA qui permet la lecture d'un fichier Excel donné.

J'ai arrivé à faire ce programme mais seulement si la version de fichier Excel 97-2003. ( c'est à dire avec l'extension xls)

alors que mon programme doit gérer aussi le cas d'un fichier Excel 2010 ( extension xlsx).

Je reçois l'erreur ci-dessous quand j'utilise fichier Excel 2010 :


Exception in thread "main" org.apache.poi.poifs.filesystem.OfficeXmlFileException: The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:131)
at org.apache.poi.poifs.storage.HeaderBlock.<init>(HeaderBlock.java:104)
at org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:138)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:327)
at org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:308).


qlq1 peut m'aider SVP ?

Merci d'avance pour vos retours.

Cordialement.
A voir également:

1 réponse

KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
13 juin 2015 à 11:10
Bonjour,

Le message d'erreur est pourtant extrêmement précis.
The supplied data appears to be in the Office 2007+ XML. You are calling the part of POI that deals with OLE2 Office Documents. You need to call a different part of POI to process this data (eg XSSF instead of HSSF)

Tu dois donc remplacer tes objets HSSF par des objets XSSF (voire SXSSF)
Cf. la documentation : http://poi.apache.org/components/spreadsheet/
0
scalabandri
13 juin 2015 à 15:42
Bonjour Monsieur,

Tout d'abord merci beaucoup pour votre retour.

Je reçois l'erreur ci-dessous quand je remplace mes objets HSSF par XSSF :

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xmlbeans/XmlException
at IT_ZY90.main(IT_ZY90.java:236)
Caused by: java.lang.ClassNotFoundException: org.apache.xmlbeans.XmlException
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:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

As-tu une idée Monsieur ?

Merci,

Cordialement.
0
KX Messages postés 16734 Date d'inscription samedi 31 mai 2008 Statut Modérateur Dernière intervention 24 avril 2024 3 015
13 juin 2015 à 16:03
Il manque une dépendance au projet. C'est à dire que le jar Apache POI a besoin pour fonctionner d'ajouter un ou plusieurs autres jars pour fonctionner.
Ici il manque xmlbeans, qui va peut-être avoir lui aussi d'une dépendance (stax), qu'il faudra rajouter pour que cela fonctionne.

Pour simplifier la gestion de dépendances, il y a Maven qui fait ça très bien (Débuter avec Maven), voici par exemple l'arbre de dépendance de Apache POI généré par Maven, il faut donc ajouter tout ces jar pour que cela fonctionne.

org.apache.poi:poi-ooxml:jar:3.12:compile
+- org.apache.poi:poi:jar:3.12:compile
| \- commons-codec:commons-codec:jar:1.9:compile
\- org.apache.poi:poi-ooxml-schemas:jar:3.12:compile
\- org.apache.xmlbeans:xmlbeans:jar:2.6.0:compile
\- stax:stax-api:jar:1.0.1:compile
0