Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VFPX WORKBOOKS Column totals #93

Open
brett39 opened this issue Jul 26, 2023 · 9 comments
Open

VFPX WORKBOOKS Column totals #93

brett39 opened this issue Jul 26, 2023 · 9 comments

Comments

@brett39
Copy link

brett39 commented Jul 26, 2023

Hi Greg,

I love using this class as it is a powerful tool. Congratulation on a great piece of coding.

I have made some amendments to your copy (Release 39) that I downloaded so that we can do a couple of additional things. One of them is to add another passed parameter to the SAVEGRIDTOWORKBOOK and SAVETABLETOWORKBOOK methods called TLSUM. If we call these methods in the class and set the TLSUM field to true, it indicates that we want to automatically sum the numeric columns that may exist in the grid and create a total line in the exported grid. I have copied in some code snippets that show this amendment. (see Snippet 1 and 2).

The other change was to put in an option to have the actual fields names of the grid put in as the column headers rather than the column titles. We used another passed parameter called TLHEADERNAME. (see Snippet 1 and 3).

Anyway, if you think that these are worthy additions to your existing code, please feel free to add them in.

Snippet 1. The passed parameters to the methods showing the TLSUM parameter.

LPARAMETERS togrid, txwb, tlfreeze, tlsavewb, tcsheetname, tlinclhiddencols, tlshowgridlines, tnsheet, tnbegrow, tnbegcol, tlsum, tlheadername

Snippet 2. Showing the code to build up the summed columns using TLSUM..

- Freeze the first row if specified
IF tlfreeze
THIS.freezepanes(lnwb, lnsh, 1, 0)
ENDIF
*


  •   																											*
    
  • bch added 8.11.2017 To add in a total for the numeric type columns. Also added code for tlsum flag setting.
  •   																											*
    

  •   IF tlsum
      	FOR lncol = 1 TO lncolcount
      		lcdatatype = THIS.getcelldatatype(lnwb, lnsh, 2, lncol)
      		IF INLIST(lcdatatype, data_type_currency, data_type_float, data_type_int)
      			lccolumn = THIS.columnindextoascii(lncol)
      			THIS.setcellformula(lnwb, lnsh, lnrow + 2, lncol, "=SUM(" + lccolumn + ALLTRIM(STR(tnbegrow+1)) + ":" + lccolumn + ALLTRIM(STR(lnrow))+")")
      			lnstylecell = THIS.getcellstyle(lnwb, lnsh, lnrow, lncol)
      			THIS.setcellstyle(lnwb, lnsh, lnrow + 2, lncol, lnstylecell)
      			THIS.setcellborder(lnwb, lnsh, lnrow + 2, lncol, border_top, border_style_double)
      		ENDIF
      	ENDFOR
      ENDIF
    

  •   																											*
    
  • bch end 8.11.2017
  •   																											*
    

Snippet 3. Using the grid field names rather than the grid titles for the column headers using TLHEADERNAME.
*

- Add the header row if defined and set the column widths; get the column font info
IF togrid.HEADERHEIGHT > 0 && Change recommendation by Doug Hennig (if no headers, start in first row)
lnrow = tnbegrow
FOR lncol=1 TO lncolcount
locolumn = togrid.COLUMNS(lacolorder[lnCol, 2])
*


  •   																											*
    
  • bch added 29.10.20 Put in code to optionallty put in the control field name rather than the grid heading name *
  •   																											*
    

  •   		IF tlheadername
      			THIS.setcellvalue(lnwb, lnsh, 1, lncol, UPPER(locolumn.CONTROLSOURCE))
      		ELSE
      			THIS.setcellvalue(lnwb, lnsh, lnrow, lncol+tnbegcol-1, locolumn.header1.CAPTION)
      		ENDIF
    

  •   																											*
    
  • bch end 29.10.20 *
  •   																											*
    

  •   		THIS.setcellstyle(lnwb, lnsh, lnrow, lncol+tnbegcol-1, logrid.COLUMNS(lacolorder[lnCol, 2]).headerstyleid)
      		THIS.setcolumnwidth(lnwb, lnsh, lncol+tnbegcol-1, THIS.convertpixelstoexcelunits(locolumn.WIDTH))
      	ENDFOR
      ELSE
      	lnrow = tnbegrow - 1
      	FOR lncol=1 TO lncolcount
      		locolumn = togrid.COLUMNS(lacolorder[lnCol, 2])
      		THIS.setcolumnwidth(lnwb, lnsh, lncol+tnbegcol-1, THIS.convertpixelstoexcelunits(locolumn.WIDTH))
      	ENDFOR
      ENDIF
    
@ggreen86
Copy link
Owner

ggreen86 commented Jul 27, 2023 via email

@brett39
Copy link
Author

brett39 commented Jul 27, 2023 via email

@ggreen86
Copy link
Owner

ggreen86 commented Jul 27, 2023 via email

@brett39
Copy link
Author

brett39 commented Jul 27, 2023 via email

@brett39
Copy link
Author

brett39 commented Jul 27, 2023 via email

@brett39
Copy link
Author

brett39 commented Jul 27, 2023 via email

@ggreen86
Copy link
Owner

Brett--

I have corrected a bug in the SaveTableToWorkbookEx() method that was causing the error when trying to add a new sheet. Please review the Beta 9 release for the corrections. This method would be the preferred method for writing out a workbook as it is faster than the SaveTableToWorkbook() method. The first writes directly to the file output; whereas, the latter writes to the internal cursors first and then creates the workbook. The SaveTableToWorkbook() was actually written first and the 'Ex' method was written to increase the speed output. The SaveTableToWorkbook() allows you to write to the workbook and not save it which allows you to further make changes.

Greg

@brett39
Copy link
Author

brett39 commented Jul 30, 2023 via email

@brett39
Copy link
Author

brett39 commented Jul 31, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants