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
This commit is contained in:
wp_xxyyzz
2014-09-24 13:59:51 +00:00
parent 55792a75f9
commit dcbbb0c0a1
3 changed files with 34 additions and 16 deletions

View File

@@ -44,6 +44,9 @@ var
// formatting of all virtual cells in row 0. // formatting of all virtual cells in row 0.
// Important: The template cell must be an existing cell in the worksheet. // Important: The template cell must be an existing cell in the worksheet.
end else end else
if (ACol = 0) then
AData := NULL // Let's skip the column #0
else
if odd(random(10)) then begin if odd(random(10)) then begin
AData := Format('R=%d-C=%d', [ARow, ACol]); AData := Format('R=%d-C=%d', [ARow, ACol]);
end else end else

View File

@@ -2869,10 +2869,10 @@ var
lCell: TCell; lCell: TCell;
value: variant; value: variant;
styleCell: PCell; styleCell: PCell;
begin begin
for r := 0 to Workbook.VirtualRowCount-1 do begin for r := 0 to Workbook.VirtualRowCount-1 do
for c := 0 to Workbook.VirtualColCount-1 do begin for c := 0 to Workbook.VirtualColCount-1 do
begin
InitCell(lCell); InitCell(lCell);
value := varNull; value := varNull;
styleCell := nil; styleCell := nil;
@@ -2881,21 +2881,29 @@ begin
lCell.Row := r; lCell.Row := r;
lCell.Col := c; lCell.Col := c;
if VarIsNull(value) then if VarIsNull(value) then
begin // ignore empty cells that don't have a format
if styleCell <> nil then
lCell.ContentType := cctEmpty lCell.ContentType := cctEmpty
else else
if VarIsNumeric(value) then begin Continue;
end else
if VarIsNumeric(value) then
begin
lCell.ContentType := cctNumber; lCell.ContentType := cctNumber;
lCell.NumberValue := value; lCell.NumberValue := value;
end else end else
if VarType(value) = varDate then begin if VarType(value) = varDate then
begin
lCell.ContentType := cctDateTime; lCell.ContentType := cctDateTime;
lCell.DateTimeValue := StrToDateTime(VarToStr(value), Workbook.FormatSettings); lCell.DateTimeValue := StrToDateTime(VarToStr(value), Workbook.FormatSettings);
end else end else
if VarIsStr(value) then begin if VarIsStr(value) then
begin
lCell.ContentType := cctUTF8String; lCell.ContentType := cctUTF8String;
lCell.UTF8StringValue := VarToStrDef(value, ''); lCell.UTF8StringValue := VarToStrDef(value, '');
end else end else
if VarIsBool(value) then begin if VarIsBool(value) then
begin
lCell.ContentType := cctBool; lCell.ContentType := cctBool;
lCell.BoolValue := value <> 0; lCell.BoolValue := value <> 0;
end else end else
@@ -2903,7 +2911,6 @@ begin
WriteCellCallback(@lCell, AStream); WriteCellCallback(@lCell, AStream);
value := varNULL; value := varNULL;
end; end;
end;
end; end;
{ Writes an Excel 5/8 WINDOW1 record { Writes an Excel 5/8 WINDOW1 record

View File

@@ -2010,21 +2010,29 @@ begin
lCell.Row := r; lCell.Row := r;
lCell.Col := c; lCell.Col := c;
if VarIsNull(value) then if VarIsNull(value) then
begin
if styleCell <> nil then
lCell.ContentType := cctEmpty lCell.ContentType := cctEmpty
else else
if VarIsNumeric(value) then begin Continue;
end else
if VarIsNumeric(value) then
begin
lCell.ContentType := cctNumber; lCell.ContentType := cctNumber;
lCell.NumberValue := value; lCell.NumberValue := value;
end else end else
if VarType(value) = varDate then begin if VarType(value) = varDate then
begin
lCell.ContentType := cctDateTime; lCell.ContentType := cctDateTime;
lCell.DateTimeValue := StrToDate(VarToStr(value), Workbook.FormatSettings); lCell.DateTimeValue := StrToDate(VarToStr(value), Workbook.FormatSettings);
end else end else
if VarIsStr(value) then begin if VarIsStr(value) then
begin
lCell.ContentType := cctUTF8String; lCell.ContentType := cctUTF8String;
lCell.UTF8StringValue := VarToStrDef(value, ''); lCell.UTF8StringValue := VarToStrDef(value, '');
end else end else
if VarIsBool(value) then begin if VarIsBool(value) then
begin
lCell.ContentType := cctBool; lCell.ContentType := cctBool;
lCell.BoolValue := value <> 0; lCell.BoolValue := value <> 0;
end; end;