Autore Topic: Creare documenti Office da programma  (Letto 730 volte)

Offline ZioCrick

  • Gamberetto
  • *
  • Post: 31
    • Mostra profilo
Creare documenti Office da programma
« il: 17 Marzo 2013, 11:08:53 »
Salve,
come da oggetto avrei l'esigenza di creare e popolare documenti Word ed Excel, ovvero pilotare LibreWriter e LibreCalc da programma.
Da VB era fattibile.
Ho letto nella documentazione di Gambas (che pero' e' aggiornata alla versione 2) che tali funzionalita' sarebbero state presenti in versioni future.
Io ho installato la 3.4 ma non riesco a capire se esiste tale possibilta' o no.
Qualcuno l'ha scoperto?
Grazie.

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.276
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Creare documenti Office da programma
« Risposta #1 il: 01 Aprile 2013, 01:19:35 »
Non so  :-\ se in qualche modo questa discussione apparsa sulla Mailing List Internazionale può esserti d'aiuto:

« I don't know much about the capabilities of Gambas writing to Libre Office,
as I don't think I ever heard of it being done before.

I would like to read the names and addresses from an SQLite data base
and put them into a Libre Office Writer template(.ods).
Is this possible?

rocko
»


« I do that for my job.

I first creat a Write document (ods) where I put a special text
everywhere I want to replace something. For example: $(name),
$(address), $(town)...

Than I unzip the *.ods file, and modify the 'contents.xml' file by
replacing the special text by their associated value.

Beware that 'contents.xml' is XML, and so some characters have to be
quoted: & < > '

Once done, I zip the document back to an ods file. "Et voilà !".

--
Benoît Minisini
»


« Unzip the .ods file???
Ok you lost me.

rocko
»


« 'ods' is actually a zip file. If you unzip it, you will get a directory
with a bunch of XML files (and JPG or PNG if you embed images in your
documen). This the OpenOffice format.

--
Benoît Minisini
»


« I actually tried that after sending my response.
lo and behold! XML file woo hoo!

So I assume I can just do a search thru th XML file and change things
then re-save the file and re-zip it like you said.

So how do I unzip and re-zip a file in Gambas?, sorry  this is kinda new
to me.
Which kind of search functions does gambas have?? regex I assume, any
others??

rocko
»


« SHELL "zip ..." WAIT

SHELL "unzip ..." WAIT

That run the shell commands as if you typed them in a terminal.

There is a compression component that allows you to do the same thing
without running external process, but it is a more complex to explain.

> Which kind of search functions does gambas have?? regex I assume, any
> others??


I use Replace$(). No need for regexp. If your search pattern are like
"$(field name)", you won't mix up with any OpenOffice XML syntax.

Don't forget to look at XML format for correctly quoting characters that
must be quoted.

Regards,

--
Benoît Minisini
»


« Should there be a time after WAIT??

rocko
»


« No, "WAIT" at the end of a SHELL command just makes it synchronous... the
interpreter literally waits until the shell (and the program you're running
inside it) exits.

Rob
»


« unzip takes -d switch for defining folder to extract files.

Jussi
»
« Ultima modifica: 01 Aprile 2013, 22:48:01 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline ZioCrick

  • Gamberetto
  • *
  • Post: 31
    • Mostra profilo
Re: Creare documenti Office da programma
« Risposta #2 il: 01 Aprile 2013, 08:20:23 »
Ti ringrazio per la cortesia vuott.
In realta' io il documento calc lo dovrei creare da programma e riempirlo da zero, impostando tutte le caratteristiche di colonne e righe.
Da quel che capisco dall'intervento che hai riportato, Gambas non ha delle librerie predisposte per farlo, ma dovrei crearmi tutta la serie di file che vanno a costituire il file .ods.
Mi sembra un po macchinoso, comunque e' una traccia; non si sa mai.
Al momento sto studiando Java, ma se dovessi continuare con Gambas potrei averne bisogno.
Grazie di cuore.

Offline vuott

  • Moderatore globale
  • Senatore Gambero
  • *****
  • Post: 11.276
  • Ne mors quidem nos iunget
    • Mostra profilo
Re: Creare documenti Office da programma
« Risposta #3 il: 03 Aprile 2013, 19:45:08 »
...continua......

« I'm now having problems with zipping the files.
I "m naming the files dynamically with the first name of the
person from my database.

But the zip command sometimes saves the file as a zip not .odt.
Why it does this I don't know, actually it does this a lot/

I'm using this as my zip code:
zip -r " & sFirst & ".odt ." Wait

How do I get my files saved with the .odt extension all the time??
I tried renaming any .zip to a .odt with the rename command
  but thats not working either.

rocko
»


« zip -h2 in a terminal gives you more detailed instructions on use of zip

zip -r NameOfZipFile FileOrFolderToAdd

NameOfZipFile in your case is sFirst & ".odt"
FileOrFolderToAdd is the place you unzipped the original .odt to and
where you replaces some content.

------------------
Dim sCommand, sPath As String
sPath = User.Home & "place you unzipped and modified the content of odt"
sCommand = "zip -r " & sFirst & ".odt " & sPath
Shell sCommand
------------------

Watch the spaces in the strings as they are important!!

Some hints:
1. For command always try --help 0r -h and study the command before
coding. We have to do the same to help you. Bit strange don you think
2. Always try running your planned command in a terminal before coding
in Gambas
3. Study Gambas documentation on what to use best for getting the job
done. Read every word over and over as every detail is important.
4. When testing in Gambas add a Print sCommand before Shell sCommand so
that when running you see the string in the console of IDE.
5. If command doesn't work from Gambas try Copy/paste that string in
Gambas IDE console to a terminal and try it there. If it doesn't work
there, it will never work in Gambas, so back to terminal testing,
adapting your sCommand and test app again.

Keep doing this until it works..mind the details!!

Good luck..
>

Willy Raets
»
« Ultima modifica: 03 Aprile 2013, 20:26:37 da vuott »
« Chiunque, non ricorrendo lo stato di necessità, nel proprio progetto Gambas fa uso delle istruzioni Shell o Exec, è punito con la sanzione pecuniaria da euro 20,00 a euro 60,00. »

Offline ZioCrick

  • Gamberetto
  • *
  • Post: 31
    • Mostra profilo
Re: Creare documenti Office da programma
« Risposta #4 il: 04 Aprile 2013, 08:19:34 »
Grazie vuott, l'avevo letto  :)