Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

Format Excel - conversion automatique

7 réponses
Avatar
Fabien LE LEZ
Bonjour,

J'aurais besoin, sur un serveur web (Debian Etch), de lire et écrire
des fichiers au format XLS (Excel 97). J'ai bien dit XLS, pas CSV.
Le tout, de façon complètement automatique.

Pour l'instant, la seule piste que je vois, c'est de lire et écrire en
XML (ou plus précisément Opendocument), et utiliser Openoffice pour
convertir.

Est-ce faisable de façon automatique ? Y a-t-il d'autres pistes à
explorer ?

Merci d'avance.

7 réponses

Avatar
Pierre Maurette
Fabien LE LEZ, le 04/12/2008 a écrit :
Bonjour,

J'aurais besoin, sur un serveur web (Debian Etch), de lire et écrire
des fichiers au format XLS (Excel 97). J'ai bien dit XLS, pas CSV.
Le tout, de façon complètement automatique.

Pour l'instant, la seule piste que je vois, c'est de lire et écrire en
XML (ou plus précisément Opendocument), et utiliser Openoffice pour
convertir.

Est-ce faisable de façon automatique ? Y a-t-il d'autres pistes à
explorer ?



Il existe le module python "Python XLS Reader":
<URL:http://pyxlreader.sourceforge.net/>

Le readme.txt donne des liens vers des solutions en Perl, PHP et Java,
je le colle pour info:

<pyxlreader - readme.txt>
pyXLReader
================= pyXLReader is a Python library for reading Excel compatible
spreadsheets.
It's a port of JAVA jexcelapi and PHP Spreadsheet-Excel-Reader to
Python.
It allows reading of Excel compatible spreadsheets without the Windows.

Requires Python 2.2+

Authors, copyright, and license
==============================
pyXLReader was ported by Ilia Harlamov from
jexcelapi and Spreadsheet-Excel-Reader (URL see below)

Copyright (c) 2005 Ilia Harlamov
Copyright (c) 2004 Vadim Tkachenko
(Spreadsheet-Excel-Reader)
Copyright (c) ???? Andy Khan (jexcelapi)

Distribution's license is GNU LGPL. The included LICENSE.txt file
describes
this in detail.


Useful links
===========
Perl Spreadsheet::ParseExcel
http://search.cpan.org/search?dist=Spreadsheet-ParseExcel

OpenOffice's Spreadsheet Project
http://sc.openoffice.org/
http://sc.openoffice.org/excelfileformat.pdf

POIFS (OLE2) format documentation
http://jakarta.apache.org/poi/poifs/fileformat.html
http://jakarta.apache.org/poi/poifs/fileformat.pdf

PHP Pear Spreadsheet-Excel-Reader (Vadim Tkachenko)
http://pear.php.net/package/Spreadsheet_Excel_Reader/

Java API for reading, writing and modifying the contents of Excel
spreadsheets
http://www.andykhan.com/jexcelapi/index.html

PHP Spreadsheet Excel Reader
http://sourceforge.net/projects/phpexcelreader/


--
Ilia Harlamov
</pyxlreader - readme.txt>

--
Pierre Maurette
Avatar
Stephan Peccini
Le Thu, 04 Dec 2008 05:39:51 +0100, Fabien LE LEZ a écrit :

J'aurais besoin, sur un serveur web (Debian Etch), de lire et écrire des
fichiers au format XLS (Excel 97). J'ai bien dit XLS, pas CSV. Le tout,
de façon complètement automatique.



Est-ce faisable de façon automatique ? Y a-t-il d'autres pistes à
explorer ?



Oui et ce directement à partir du format natif MS Office avec unoconv et
en utilisant openoffice en headless sous forme de service.

Je n'ai pas sous la main la configuration exacte que j'ai mise en place au
boulot, mais si tu souhaites, je te la donnerai.

--
Stéphan Peccini
Les photos : <URL:http://photonature.fr>
Les Pyrénées : <URL:http://photonature.fr/pyrenees>
Le blog : <URL:http://pyrenees.peccini.fr>
Avatar
Fabien LE LEZ
On 4 Dec 2008 06:34:17 GMT, Stephan Peccini :

Je n'ai pas sous la main la configuration exacte que j'ai mise en place au
boulot, mais si tu souhaites, je te la donnerai.



Je veux bien. Merci.
Avatar
Fabien LE LEZ
On Thu, 04 Dec 2008 06:23:06 +0100, Pierre Maurette
:

Le readme.txt donne des liens vers des solutions en Perl, PHP et Java,
je le colle pour info:



Merci.

Je suis en train de regarder tout ça. Pour lire le contenu d'un
fichier Excel, ça a l'air prometteur. Pour créer un fichier, je suis
plus dubitatif.
Avatar
stephan
On Dec 4, 7:53 am, Fabien LE LEZ wrote:
On 4 Dec 2008 06:34:17 GMT, Stephan Peccini :

>Je n'ai pas sous la main la configuration exacte que j'ai mise en place au
>boulot, mais si tu souhaites, je te la donnerai.

Je veux bien. Merci.



Tu a besoin de Xvfb, openoffice avec pyuno et headless et unoconv :

http://dag.wieers.com/home-made/unoconv/

Le fichier unoconvd pour lancer le service :

#!/bin/sh
#
# openofficeorg This shell script takes care of starting and stopping
# openoffice server.
#
# chkconfig: 2345 99 35
# description: unoconv listener for converting documents with OOo


. /etc/rc.d/init.d/functions

# See how we were called.
case "$1" in
start)
printf "Starting unoconvd: "
/usr/bin/Xvfb :8101 -ac &
sleep 5
su - apache -c "export DISPLAY=:8101.0;/usr/bin/unoconv --listener
&"
echo
;;
stop)
printf "Shutting down unoconvd: "
killall soffice.bin
echo
;;
restart)
$0 stop
$0 start
;;
*)
printf "Usage: unoconvd {start|stop|restart}n"
exit 1
;;
esac

exit 0
###################

Et pour convertir un fichier Excel en CSV tu lances la commande :

/usr/bin/unoconv -d spreadsheet -f csv fichier.xls

Je te laisse voir toutes les possibilités :

http://linux.die.net/man/1/unoconv
Avatar
Arol
Le Thu, 04 Dec 2008 00:52:12 -0800, stephan a écrit:

Et pour convertir un fichier Excel en CSV tu lances la commande :

/usr/bin/unoconv -d spreadsheet -f csv fichier.xls



Merci beaucoup.

Grâce à toi, je viens de gagner 600 euros pour 4h de boulot.
Avatar
Fabien LE LEZ
On Thu, 4 Dec 2008 00:52:12 -0800 (PST), :

Tu a besoin de Xvfb, openoffice avec pyuno et headless et unoconv :



Merci. J'ai un peu transformé ton script, car les versions plus
récentes de Openoffice ont une option "-headless" qui leur permet de
se passer de X.

Installation :

http://www.backports.org/dokuwiki/doku.php?id=instructions

apt-get -t etch-backports install python-uno
openoffice.org-headless openoffice.org-calc

# unoconv version Lenny

cd /tmp
wget
http://ftp.fr.debian.org/debian/pool/main/u/unoconv/unoconv_0.3-3_all.deb
dpkg -i unoconv_0.3-3_all.deb && rm unoconv_0.3-3_all.deb


Grâce à "-headless", mon fichier /etc/init.d/unoconv-listen est un
poil plus simple que le tien (cf plus bas). Ne pas oublier de
l'activer :
chmod u+x /etc/init.d/unoconv-listen
update-rc.d unoconv-listen defaults




J'ai perdu du temps sur un problème tout con : par défaut sous Debian,
www-data n'a pas accès en écriture à son propre répertoire home,
empêchant Openoffice de créer son répertoire de config. Du coup,
soffice.bin se lance, mais est inactif.

Il faut donc créer un sous-répertoire ".openoffice.org2", et le donner
à www-data :
chown www-data .openoffice.org2

Enfin bon, ça a l'air de fonctionner. Je vais donc enfin pouvoir filer
des .xls à mes visiteurs :-)

Par contre, dans l'autre sens (un visiteur m'envoie un .xls), je vais
plutôt utiliser
<http://pear.php.net/package/Spreadsheet_Excel_Reader/>. En effet,
même si Openoffice est moins troué que MS Office, c'est quand même une
usine à gaz, et je ne suis pas très chaud pour lui faire ouvrir un
fichier peut-être uploadé par un attaquant.










Fichier /etc/init.d/unoconv-listen :

#!/bin/sh
#
# openofficeorg This shell script takes care of starting and stopping
# openoffice server.
# description: unoconv listener for converting documents with OOo


. /lib/lsb/init-functions

# See how we were called.
case "$1" in
start)
printf "Starting unoconvd: "
su - www-data -c "/usr/bin/unoconv --listener&"
echo
;;
stop)
printf "Shutting down unoconvd: "
killall soffice.bin
echo
;;
restart)
$0 stop
$0 start
;;
*)
printf "Usage: unoconvd {start|stop|restart}n"
exit 1
;;
esac

exit 0