PlanetSquires Forums

Support Forums => General Board => Topic started by: Petrus Vorster on October 18, 2012, 12:24:58 PM

Title: Simple Excel Routines
Post by: Petrus Vorster on October 18, 2012, 12:24:58 PM
Very newby at this.
I need to open an existing excel xml file, change a few lines and print it.
Any examples here on simple MS Excel routines?
Title: Re: Simple Excel Routines
Post by: Paul Squires on October 18, 2012, 05:24:04 PM
Hi Peter,

If your application is such that it will be just as acceptable, then maybe you can simply recreate an entire new workbook rather than open an existing one, change lines, and print. I am working on a class in another thread that creates the xml workbook files.

If you need to open an existing workbook then COM automation is your best choice. Do a search on PowerBASIC's forum for something like "reading excel". You will get lots of hits.

http://www.powerbasic.com/support/pbforums/showthread.php?t=43734

http://www.powerbasic.com/support/pbforums/showthread.php?t=42548
Title: Re: Simple Excel Routines
Post by: Pat Dooley on October 19, 2012, 05:04:52 AM
You might be able to simply use text search and replace methods. It depends on how drastic are your changes.
Load a copy of your xml file into a text editor and give it a try.  You could find "Robert" and change it to "William"
and it probaby would work fine.  But major changes would be best done by rewriting the file as Paul suggested.
Title: Re: Simple Excel Routines (How about ODBC)
Post by: Mark Strickland on November 08, 2012, 04:37:59 PM
If you have a copy of SQLtools you can possibly open the Excel workbook with ODBC and handle changes just like it was a small SQL database.

I have done limited changed this way before but I don't have any current example without some digging around.

Of course SQLtools is not free.
Title: Re: Simple Excel Routines
Post by: Petrus Vorster on November 14, 2012, 07:37:08 AM
Thanks a million. Will give it a try!
Title: Re: Simple Excel Routines
Post by: Petrus Vorster on December 17, 2012, 09:16:49 AM
Hi All
I have come to a bit of a standstill on this matter. I am doing something wrong here.
The links on this page at Powerbasic leads back to the Powerbasic examples in the PB folder.
Those examples work fine if you EXCLUDE Firefly. The moment I try to ADD that EXCEL.inc to Firefly I run into many problems.
What must I include in my FF project and does the calls differ from the example in PB? Because they wont work if I run them from my FF project.
It would be quite a bummer if I cannot get it to work as this is an integral part of the program.
Title: Re: Simple Excel Routines
Post by: José Roca on December 17, 2012, 09:25:46 AM
Excel has many objects, e.g. Rectangle, that conflicts with API functions of the same name. Generate a new include file adding a prefix, e.g. "Excel_".
Title: Re: Simple Excel Routines
Post by: Petrus Vorster on December 17, 2012, 10:57:37 AM
Thanks Jose, but I fear I am too much of a newby to know where I must alter what, I am going to mess up that Include file.
What i need is a bit more elementary examples in Firefly on how to create a new Excel sheet and send data from my Listview over to Columns in Excel.
I am CLUELESS. :(
Title: Re: Simple Excel Routines
Post by: José Roca on December 17, 2012, 11:03:31 AM
I don't have Excel, so I can't help you with that. Sorry.
Title: Re: Simple Excel Routines
Post by: Paul Squires on December 17, 2012, 02:34:33 PM
Rather than use COM, maybe you can try my new SLL that creates Excel compatible files. It is incredibly easy to use and wrap your head around. There is a sample included in the package that shows how to create a file, output rows and columns, format cells, etc...

Check it out:  http://www.planetsquires.com/protect/forum/index.php?topic=3208.0

Title: Re: Simple Excel Routines
Post by: Petrus Vorster on December 17, 2012, 04:14:51 PM
Thanks a million Paul!
In just a few minutes i was already creating the XML files!!!
Now just to get the system to open them automatically!!!
This was an easy way around!!!! :)
Title: Re: Simple Excel Routines
Post by: Pat Dooley on December 17, 2012, 10:32:15 PM
see the last posts of this thread...

http://www.powerbasic.com/support/pbforums/showthread.php?t=45652 (http://www.powerbasic.com/support/pbforums/showthread.php?t=45652)

basically...

Local xptr As Long
Local b As String
b= "D:\my_excel.xml"
xptr=StrPtr(b)
ShellExecute 0, "open", ByVal xptr, $Nul , $Nul, %SW_SHOWMAXIMIZED


Works well and fast.  I use it mostly for pdf's.
Title: Re: Simple Excel Routines
Post by: Petrus Vorster on December 18, 2012, 05:36:48 PM
Thanks all.
I have made a function that will export any Listview to Excel, including column sizes and all data in one quick click.
Thanks to all of your help.
Title: Re: Simple Excel Routines
Post by: Mark Strickland on May 08, 2013, 11:16:43 PM
I had a very strange problem and thought it might help somebody else.

I have a computer at work with a separate license for FF and PB10.  I build a project with these Excel routines and the .SLL and everything worked fine.  I was using FF 3.61 and PB 10.03.

I started a new project on my home machine with FF 3.61 and PB 10.00 (never been patched).  When I compiled FF would hang with the "program has stopped" message.  Not PB but FF.  I tried to compile the sample project with PB 10.00 and got a strange error but no crash.

I updated to PB 10.04 and everything now works.  I am not sure how the PB compiler could crash FF but it did.

BTW --- These Excel routines are AWESOME!!!!!!