XLSX-Workbook-Class icon indicating copy to clipboard operation
XLSX-Workbook-Class copied to clipboard

Recommendation

Open zulqasar opened this issue 2 years ago • 1 comments

I just started using this awesome class. I had a need for bestfit/auto fit for column. For some reason when this attribute is set, it never works. We need to calculate the width at design time.

*-- Added maxwidth N(16,9) field to xl_columns cursor in createWorkingCursors method

*-- in setCellValue method in the end between this.RestoreVFPSettings () and Catch to loException added this code

*-- line 1
lparameters tnWB, tnSheet, tnCellRow, txCellValue, tlAppend, tnBestFitFactor

*-- line 3
local llReturn, lcKey, lnWidth

*-- after line 151
lcKey = bintoc(tnWb)+bintoc(tnSheet)+bintoc(tnCellCol)
if seek(m.lcKey, 'xl_columns', 'col') and xl_columns.bestfit
    tnBestfitFactor = evl(m.tnBestfitFactor, 1.23)
    lnWidth = len(m.lcCellValue) * tnBestFitFactor
    lnWidth = max(m.lnWidth, xl_columns.maxwidth)
    replace width with m.lnWidth, maxwidth with m.lnWidth in xl_columns
endif

*-- add tnBestfitFactor as the last parameter in setCellValue method *. Also add lcKey and lnWidth to the locals on top

  • Usage: *- simply invoke setColumnBestFit method for the columns you want bestfit
setColumnBestfit(lnwb, lnSh, 3, .T.)   && set bestfit on col 3
setColumnBestfit(lnwb, lash, 5, .T.).  && set bestfit on col 5 

zulqasar avatar Aug 22 '22 09:08 zulqasar

I will have to review this more. The problem I had in trying to set the column to the best fit is how to account for long strings. This could result in a very wide column which is limited to 256 in Excel.

ggreen86 avatar Aug 23 '22 13:08 ggreen86

This method now works in Release 39.

ggreen86 avatar Jun 14 '23 21:06 ggreen86