PlanetSquires Forums

Please login or register.

Login with username, password and session length
Advanced search  
Pages: 1 2 [3]

Author Topic: Creating Excel WorkBooks without Automation  (Read 6112 times)

Nathan Durland

  • FireFly3 Registered User
  • Junior FireFly Member
  • *
  • Posts: 81
Re: Creating Excel WorkBooks without Automation
« Reply #30 on: March 25, 2014, 12:07:28 PM »

I've come across a difficulty that as far as I can tell, looks like I'm bumping up against something in the SLL, although I'm probably doing something dumb.  I'm attempting to create a pretty wide spreadsheet (211 columns in all), but get a crash not too far in.  Here's relevant code; if the bits between the #IF 0/#ENDIF are added, it runs OK, otherwise it crashes after 50 iterations of the xLoop.  The SLL file I'm using is dated 1/17/2014.

Code: [Select]

  local xLoop   as long
  local xlRow, xlCol   as long
  local FirstDate   as string

  For xLoop = 104 To 1 Step -1

#IF 0
    If xLoop > 55 Then
      xlRow += 2
      xlCol = 3
    End If

    If xLoop > 5 Then
      xlRow += 2
      xlCol = 3
    End If
#endif

    FF_StatusBar_SetText HWND_MAINFORM_STATUSBAR, 1, "XLoop: " + Format$(xLoop) + " Row: " + Format$(xlRow) + " Col: " + Format$(XLCol)
    FF_DoEvents
    Sleep 10
 
    xlCol += 1
    iCell = ws.AddCell( xlRow, xlCol, FirstDate)
    iCell.AlignCenter = %True
    iCell.MergeAcross = 1
    iCell.CellColor = fnMakeExcelColor(%RGB_KHAKI)
   
    iCell = ws.AddCell( xlRow+1, xlCol, "Orders")
    iCell.AlignRight = %True
    iCell.CellColor = fnMakeExcelColor(%RGB_KHAKI)

    xlCol += 1
    iCell = ws.AddCell( xlRow+1, xlCol, "Qty")
    iCell.AlignRight = %True
    iCell.CellColor = fnMakeExcelColor(%RGB_KHAKI)
   
    FirstDate = SQLDateMath(FirstDate, 7)   
 
  Next xLoop

Any insight appreciated.
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8090
  • Windows 10
    • PlanetSquires Software
Re: Creating Excel WorkBooks without Automation
« Reply #31 on: March 25, 2014, 02:47:15 PM »

I am having a hard time following why you are using a STEP -1 loop and then using that value to determine how to set the row value. If you comment out the "Orders" and "Qty" lines then it will compile and run with no problems. That would lead me to believe that the problem would be the xlRow + 1 being used. Maybe the loop counting backwards and then adding to the rows is causing some type of overflow error or something. Not sure at this point.

The library is designed to build the spreadsheet from low row/col numbers to high. Any reason why you are using a backwards stepping loop with incrementing rows? Could the logic be reversed?
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Nathan Durland

  • FireFly3 Registered User
  • Junior FireFly Member
  • *
  • Posts: 81
Re: Creating Excel WorkBooks without Automation
« Reply #32 on: March 25, 2014, 03:09:31 PM »

I am having a hard time following why you are using a STEP -1 loop and then using that value to determine how to set the row value. If you comment out the "Orders" and "Qty" lines then it will compile and run with no problems. That would lead me to believe that the problem would be the xlRow + 1 being used. Maybe the loop counting backwards and then adding to the rows is causing some type of overflow error or something. Not sure at this point.

The library is designed to build the spreadsheet from low row/col numbers to high. Any reason why you are using a backwards stepping loop with incrementing rows? Could the logic be reversed?

The backward loop is because the objective is a rolling 2 year weekly data dump (i.e. the previous 104 weeks).  I used the negative step planning on adding some other code once I have this sorted out.  The variable 'FirstDate' comes in seeded with the oldest date, then as the loop progresses gets closer and closer to today. The loop variable (xLoop) value is not used to calculate the rows or columns; that's what xlRow and xlCol are for.   Each of those starts with a small value and are then incremented as needed.  I've been tinkering, as it occurred to me also that the problem was with writing a cell will the (xlRow+1).  I changed the code to the following (including losing the negative step loop).  This code will go successfully through the first loop, then fail on the first pass of the second.  It fails on the ws.AddCell call.

Code: [Select]
  xlCol = 4
  LOGIT "--> row " + Format$(xlRow)
  For xLoop = 1 to 104

    FF_StatusBar_SetText HWND_MAINFORM_STATUSBAR, 1, "XLoop: " + Format$(xLoop) + " Row: " + Format$(xlRow) + " Col: " + Format$(XLCol)
    FF_DoEvents
    Sleep 10
    If gUserCancel Then GoTo ExitFunc

    iCell = ws.AddCell( xlRow, xlCol, FirstDate)
    iCell.AlignCenter = %True
    iCell.MergeAcross = 1
    xlCol += 2

    FirstDate = SQLDateMath(FirstDate, 7)   
  Next xLoop
 
  xlRow += 1
  LOGIT "--> row " + Format$(xlRow)
 
  '//-  We really created 208 columns in the first loop
  '     So, now we do 208; even numbered are for orders, odd ar for quantity for that week
  For xLoop = 1 To 208 

    xlCol = 3 + xLoop
    tLong1 = (xlCol Mod 2)
    tStr1 = IIF$(tLong1 = 0, "Ords", "Qty")
    If gUserCancel Then GoTo ExitFunc
    LOGIT "XLoop: " + Format$(xLoop) + " Row: " + Format$(xlRow) + " Col: " + Format$(xlCol) + " " + tStr1
    LOGIT "--> add cell"
    iCell = ws.AddCell( xlRow, xlCol, tStr1)
 
  Next xLoop
Logged

Wilko Verweij

  • FireFly3 Registered User
  • Junior FireFly Member
  • *
  • Posts: 147
  • PB10 - FF3.7 User; Win 10
    • CHEAQS
Re: Creating Excel WorkBooks without Automation
« Reply #33 on: December 07, 2014, 08:19:04 AM »

As John noticed some time ago, this class is for writing XML-files. But there is a GetCell option. I tried to use that to read data from an .XML-file but could not get it working. Does anybody have a simple example? Or is it just impossible?

Thanks for help
Wilko
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8090
  • Windows 10
    • PlanetSquires Software
Re: Creating Excel WorkBooks without Automation
« Reply #34 on: December 07, 2014, 09:57:36 AM »

The GetCell option is just for retrieving data that you have already created in memory prior to writing the file to disk.
GetCell does not read from an existing xml file. Sorry.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Wilko Verweij

  • FireFly3 Registered User
  • Junior FireFly Member
  • *
  • Posts: 147
  • PB10 - FF3.7 User; Win 10
    • CHEAQS
Re: Creating Excel WorkBooks without Automation
« Reply #35 on: December 07, 2014, 01:26:51 PM »

Thank for your quick reply. It's a pity, but the option to create XML-files was very useful in other projects already, so thanks.
Wilko
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8090
  • Windows 10
    • PlanetSquires Software
Re: Creating Excel WorkBooks without Automation
« Reply #36 on: May 19, 2015, 06:53:13 PM »

Original post in thread has been updated with a new download to address a memory load issue. Internally, the class destructor for the spreadsheet class was not ERASE'ing an array allocated that held the cell data. Simply setting the Spreadsheet class to NOTHING was not enough. The array held references to the cells as well.
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Jean-pierre Leroy

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 460
  • expect nothing, be prepared for everything ...
Re: Creating Excel WorkBooks without Automation
« Reply #37 on: May 20, 2015, 08:29:54 AM »

Thank you Paul for this update I use your SLL every day in my projects.

Regards,
JEan-Pierre
Logged

Petrus Vorster

  • FireFly3 Registered User
  • Senior FireFly Member
  • *
  • Posts: 346
Re: Creating Excel WorkBooks without Automation
« Reply #38 on: May 22, 2015, 04:44:44 PM »

I use this tool extensively but haven't used the function to draw borders between cells.
This function :  iCell = ws.AddCell( 5, 2, "Box" )
   iCell.BorderLeft   = %TRUE
   iCell.BorderTop    = %TRUE
   iCell.BorderRight  = %TRUE
   iCell.BorderBottom = %TRUE
I assume it draws a border around a cell? I haven't tried this yet.
Can the Sll help me change line thickness and color of borders as well?
It would make my reports look SO MUCH better!!!

Finally, i want the Excel sheet have CUSTOM FILTER on the page so the user can only select the dropdowns in the sheet without having to go through the whole process of setting up the Custom Filter. Some of the users are not really Excel Savvy.
Logged

Ian Vincent

  • FireFly3 Registered User
  • Little Newbie FireFly
  • *
  • Posts: 25
  • FF3 User
Re: Creating Excel WorkBooks without Automation
« Reply #39 on: July 19, 2017, 10:47:09 AM »

Just started using this today. It is going to be very useful.

Paul, I know you have moved on from PB, but if you ever get the urge to look at this class again:

If the requested output file is already open when writing the file with wb.WriteXML an error 70 occurs that
I can't seem to trap, presumably because it occurs in code in the SLL.
I can of course check if the file is open before using the class, but it is not exactly elegant.

It would be nice if there was something like wb.GetLastError that could be examined and any errors trapped within the SLL and reported by wb.GetLastError.

And, if you have the time and energy, could you include the NumberFormat tag?

As always, thanks for your great work.
Logged

Paul Squires

  • Administrator
  • Master FireFly Member
  • *****
  • Posts: 8090
  • Windows 10
    • PlanetSquires Software
Re: Creating Excel WorkBooks without Automation
« Reply #40 on: July 19, 2017, 09:40:33 PM »

Hi Ian,

I have attached the source code the first post in this thread. It's been a very long time since I looked at the code so it may be good or it may be able to be improved on a lot.

Good luck!  :)
Logged
Paul Squires
PlanetSquires Software
FireFly Visual Designer, WinFBE Editor

Ian Vincent

  • FireFly3 Registered User
  • Little Newbie FireFly
  • *
  • Posts: 25
  • FF3 User
Re: Creating Excel WorkBooks without Automation
« Reply #41 on: July 19, 2017, 11:19:06 PM »

Thanks Paul.


Hi Ian,

I have attached the source code the first post in this thread. It's been a very long time since I looked at the code so it may be good or it may be able to be improved on a lot.

Good luck!  :)
Logged
Pages: 1 2 [3]