ggreen86 / XLSX-Workbook-Class

VFP Class to Create an XLSX Workbook without Excel Automation or Installed
45 stars 16 forks source link

Recommendation #71

Closed zulqasar closed 1 year ago

zulqasar commented 2 years ago

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

ggreen86 commented 2 years ago

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 commented 1 year ago

This method now works in Release 39.