RBLibrary: ExcelWriter

Nothing to really solve. The proper extension for Excel 2003/4 XML is .xml not .xls and because of the risks of extension spoofing Windows will warn the user that the file format does not match the extension. I’ve been using is for quite a few years now. Just use the .xml extension and if the user has Excel 2003 or newer it will open just fine.

Sorry Bob, that does not work for me, it does not automatically find Excel.
If I double-click it, Internet Explorer does the honours.

Using Office Excel 2007

xlsx does not work either.

Lennox

I took a look at the plug in. Excel 2010 refused to open it because the styles are defined in uppercase and used as mixed case. That is not allowed in XML formats.

Once I fixed the case it was able to open the file but like you was not able to get it to double click and open. I then logged in remotely to my work machine and was able to open it fine by double-clicking the file named as .xml. I suspect that there is an issue with the type of installation on my home machine.

Hi Bob,

These are the styles that I use “SBS000001” and “SBS000000”

Lennox

Even without the styles Internet Explorer does the honours.

Lennox.

[quote=82887:@Norman Palardy]It write the older Excel 2004 XML format so yes it supported formatting & styling - but new versions of Excel don’t open it properly any more :frowning:
I have to revamp it to write the newer office XML format[/quote]
Let me correct my self :stuck_out_tongue:
I just ran the latest version of this (updated in Nov 2013) and the ONLY thing that is not set right is the extension so Excel is the default owner of the file
Everything in it works as always - styles formulas etc - if you tell Excel to open the file

[quote=83083:@Lennox Jacob]Even without the styles Internet Explorer does the honours.

Lennox.[/quote]
The styles was a separate issue that triggered the following error when I tried to load the demo in Excel 2010 directly.

XML ERROR in Table REASON: Bad Value FILE: C:\\Users\\bcoleman\\Desktop\\Untitled.xml GROUP: Row TAG: Cell ATTRIB: StyleID VALUE: stHead (repeated many times)

I have fixed the test project to utilise the correct formulas now.

Download latest here:
https://dl.dropboxusercontent.com/u/10747116/RealStudioClasses/SimonsExcel.zip

Works great on Mac but gets this on PC…

https://www.mediafire.com/?aavpw156y0xx3i1

…Clicking “Yes” displays the file correctly.

Is there a way to prevent that message?

Thanks.

Lennox

Simon,
Could you help in removing the message that Windows OS displays while opening the excel file.

[quote=83611:@S Abraham]Simon,
Could you help in removing the message that Windows OS displays while opening the excel file.[/quote]
Unfortunately not. This is a function of later release Excel ‘seeing’ that the xls file is actually an xml file.

If I change the extension to ‘xml’ and not ‘xls’ then many different applications can now attempt to open it. The last installed application that uses xml will then become the default, this is not acceptable.

Just clicking on the Yes button and the message goes away.

[quote=45088:@Simon Berridge]I had the same need a while ago and created a set of classes to produce a raw Excel file with formatting. This set of classes creates XML with an XLS extension that it directly readable by Excel. This was a lot of effort but I really wanted to create a good-looking Esxcel file and the XML format allowed me to incorporate styles and Conditional Formatting.

You can download a complete package of my classes and sample project here:
https://dl.dropboxusercontent.com/u/10747116/RealStudioClasses/SimonsExcel.zip

Included inside the zip file is a program that I wrote that will take a created Excel file (saved in XML format) and create the Xojo code to create the file (called RBSourceFromXLS). Both the Mac and Windows versions are included. Create an Excel sheet that looks exactly like the result you want. Save As an XML file (ensure you use XLS as the extension) and load it into the program. Select the sheet that you want to create and go.

If you have any problems contact me.

Oh, by the way, this is free code![/quote]
Hi Simon!

I notice that There is a folder Called “Source Code Generator”, a Mac and a Windows Version.
What exactly does this?

I think that is a Tool that convert a xls Spreadsheet to source code to apply it on Xojo.
Is that True?
So, I choose an Excel File (XLS) not XLSX, but nothing happens, the Process Worksheet is disabled.

Hi Simon.

I have a Listbox and I want to export it to Excel.
I was thinking to walk through the Listbox with loops and then Write each cell on the EXECUTEXLS Method, like this:

for i as integer=0 to lista.listcount-1 //this loops through all of the rows
for j as integer=0 to lista.columncount-1 ///this loops through all of the columns for each row
'Where i = rows
'Where j = columns
Dim celdaActual As String
celdaActual = lista.cell(i,j)

  'SINTAXIS of     xl.SetCellValue((Column,Row, "Text to write")
  
  
  xl.SetCellValue(1, 4, celdaActual)
  xl.SetCellStyleID(1, 4, celdaActual)
  
next

But Gives me an error :frowning:

What Am I wrong?

This is the code:

for i as integer=0 to lista.listcount-1 //this loops through all of the rows
for j as integer=0 to lista.columncount-1 ///this loops through all of the columns for each row
'Donde i = filas
'Donde j = columnas
Dim celdaActual As String
celdaActual = lista.cell(i,j)

  'SINTAXIS xl.SetCellValue((Columna,Fila, Texto)
  
  
  xl.SetCellValue(j, i, celdaActual)
  xl.SetCellStyleID(j, i, celdaActual)
  
next

next

I note that the first error was:

xl.SetCellStyleID(j, i, celdaActual)

Must be: xl.SetCellStyleID(j, i, “SBS000001”)
For set Text Style.

The Second Error: add 1 to j and i to get all columns and rows
xl.SetCellValue(j+1, i+1, celdaActual)
xl.SetCellStyleID(j+1, i+1, “SBS000001”)

But already I’m getting error

The titles of the column starts from row number 3

I Probe to put:
xl.SetCellValue(j+1, i+5, celdaActual).

It doesn’t show me error,but Display all the data like a waterfall.
Help please :frowning:

Yeah it works:
xl.SetCellValue(j+1, i+5, celdaActual)

I realize that made a mistake putting j+i

[quote=196455:@Gerardo García]Hi Simon!

I notice that There is a folder Called “Source Code Generator”, a Mac and a Windows Version.
What exactly does this?

I think that is a Tool that convert a xls Spreadsheet to source code to apply it on Xojo.
Is that True?
So, I choose an Excel File (XLS) not XLSX, but nothing happens, the Process Worksheet is disabled.[/quote]
The idea of RBSourceFromXLS is to access a spreadsheet that you have prepared and create the source code that you can just copy into a Xojo project. However, the XLS file MUST be saved in the XML format. This is made in Excel by utilising the ‘Save As …’ option and selecting the XML format. Please ensure that you change the default extension from XML to XLS.

It will then be readable by RBSourceFromXLS.

Simon.

[quote=196559:@Simon Berridge]The idea of RBSourceFromXLS is to access a spreadsheet that you have prepared and create the source code that you can just copy into a Xojo project. However, the XLS file MUST be saved in the XML format. This is made in Excel by utilising the ‘Save As …’ option and selecting the XML format. Please ensure that you change the default extension from XML to XLS.

It will then be readable by RBSourceFromXLS.

Simon.[/quote]
Oooooooooo Woow perfect!