From dcbbb0c0a13af29692b1d0c62eeb6fb6daccf64e Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Wed, 24 Sep 2014 13:59:51 +0000 Subject: [PATCH] fpspreadsheet: Cells for which the OnWriteCellData event handler returns null are skipped in virtual mode if they don't carry a format. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3603 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/other/demo_virtualmode_write.lpr | 3 +++ components/fpspreadsheet/xlscommon.pas | 27 ++++++++++++------- components/fpspreadsheet/xlsxooxml.pas | 20 +++++++++----- 3 files changed, 34 insertions(+), 16 deletions(-) diff --git a/components/fpspreadsheet/examples/other/demo_virtualmode_write.lpr b/components/fpspreadsheet/examples/other/demo_virtualmode_write.lpr index ca5e30d1e..3608f0606 100644 --- a/components/fpspreadsheet/examples/other/demo_virtualmode_write.lpr +++ b/components/fpspreadsheet/examples/other/demo_virtualmode_write.lpr @@ -44,6 +44,9 @@ var // formatting of all virtual cells in row 0. // Important: The template cell must be an existing cell in the worksheet. end else + if (ACol = 0) then + AData := NULL // Let's skip the column #0 + else if odd(random(10)) then begin AData := Format('R=%d-C=%d', [ARow, ACol]); end else diff --git a/components/fpspreadsheet/xlscommon.pas b/components/fpspreadsheet/xlscommon.pas index 3c4db063e..9c89b005f 100644 --- a/components/fpspreadsheet/xlscommon.pas +++ b/components/fpspreadsheet/xlscommon.pas @@ -2869,10 +2869,10 @@ var lCell: TCell; value: variant; styleCell: PCell; - begin - for r := 0 to Workbook.VirtualRowCount-1 do begin - for c := 0 to Workbook.VirtualColCount-1 do begin + for r := 0 to Workbook.VirtualRowCount-1 do + for c := 0 to Workbook.VirtualColCount-1 do + begin InitCell(lCell); value := varNull; styleCell := nil; @@ -2881,21 +2881,29 @@ begin lCell.Row := r; lCell.Col := c; if VarIsNull(value) then - lCell.ContentType := cctEmpty - else - if VarIsNumeric(value) then begin + begin // ignore empty cells that don't have a format + if styleCell <> nil then + lCell.ContentType := cctEmpty + else + Continue; + end else + if VarIsNumeric(value) then + begin lCell.ContentType := cctNumber; lCell.NumberValue := value; end else - if VarType(value) = varDate then begin + if VarType(value) = varDate then + begin lCell.ContentType := cctDateTime; lCell.DateTimeValue := StrToDateTime(VarToStr(value), Workbook.FormatSettings); end else - if VarIsStr(value) then begin + if VarIsStr(value) then + begin lCell.ContentType := cctUTF8String; lCell.UTF8StringValue := VarToStrDef(value, ''); end else - if VarIsBool(value) then begin + if VarIsBool(value) then + begin lCell.ContentType := cctBool; lCell.BoolValue := value <> 0; end else @@ -2903,7 +2911,6 @@ begin WriteCellCallback(@lCell, AStream); value := varNULL; end; - end; end; { Writes an Excel 5/8 WINDOW1 record diff --git a/components/fpspreadsheet/xlsxooxml.pas b/components/fpspreadsheet/xlsxooxml.pas index 772e2be41..90f3a7485 100755 --- a/components/fpspreadsheet/xlsxooxml.pas +++ b/components/fpspreadsheet/xlsxooxml.pas @@ -2010,21 +2010,29 @@ begin lCell.Row := r; lCell.Col := c; if VarIsNull(value) then - lCell.ContentType := cctEmpty - else - if VarIsNumeric(value) then begin + begin + if styleCell <> nil then + lCell.ContentType := cctEmpty + else + Continue; + end else + if VarIsNumeric(value) then + begin lCell.ContentType := cctNumber; lCell.NumberValue := value; end else - if VarType(value) = varDate then begin + if VarType(value) = varDate then + begin lCell.ContentType := cctDateTime; lCell.DateTimeValue := StrToDate(VarToStr(value), Workbook.FormatSettings); end else - if VarIsStr(value) then begin + if VarIsStr(value) then + begin lCell.ContentType := cctUTF8String; lCell.UTF8StringValue := VarToStrDef(value, ''); end else - if VarIsBool(value) then begin + if VarIsBool(value) then + begin lCell.ContentType := cctBool; lCell.BoolValue := value <> 0; end;