From e6e961d51f030a9c45e3e4c5ada927de49939153 Mon Sep 17 00:00:00 2001 From: wp_xxyyzz Date: Fri, 11 Jul 2014 20:00:49 +0000 Subject: [PATCH] fpspreadsheet: Add WriteBlank to TsSpreadOOXMLWriter to standardize code. git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3309 8e941d3f-bd1b-0410-a28a-d453659cc2b4 --- .../examples/other/test_virtualmode.lpr | 6 +- components/fpspreadsheet/xlscommon.pas | 2 +- components/fpspreadsheet/xlsxooxml.pas | 72 +++++++++++-------- 3 files changed, 47 insertions(+), 33 deletions(-) diff --git a/components/fpspreadsheet/examples/other/test_virtualmode.lpr b/components/fpspreadsheet/examples/other/test_virtualmode.lpr index 550211198..6d2794157 100644 --- a/components/fpspreadsheet/examples/other/test_virtualmode.lpr +++ b/components/fpspreadsheet/examples/other/test_virtualmode.lpr @@ -63,7 +63,7 @@ begin // writing temporaray data to a file stream instead of a memory stream. // woSaveMemory, however, considerably slows down writing of biff files. - workbook.VirtualRowCount := 1000; + workbook.VirtualRowCount := 10000; workbook.VirtualColCount := 100; // These two numbers define the size of virtual spreadsheet. // In case of a database, VirtualRowCount is the RecordCount, VirtualColCount @@ -74,8 +74,8 @@ begin // data to write. // In case of a database, you would open the dataset before calling this: -// workbook.WriteToFile('test_virtual.xlsx', sfOOXML, true); - workbook.WriteToFile('test_virtual.xls', sfExcel5, true); + workbook.WriteToFile('test_virtual.xlsx', sfOOXML, true); +// workbook.WriteToFile('test_virtual.xls', sfExcel5, true); finally workbook.Free; diff --git a/components/fpspreadsheet/xlscommon.pas b/components/fpspreadsheet/xlscommon.pas index c534b3fda..96d5bdbe0 100644 --- a/components/fpspreadsheet/xlscommon.pas +++ b/components/fpspreadsheet/xlscommon.pas @@ -2534,9 +2534,9 @@ var lCell: TCell; value: variant; begin - FillChar(lCell, SizeOf(lCell), 0); for r := 0 to Workbook.VirtualRowCount-1 do begin for c := 0 to Workbook.VirtualColCount-1 do begin + FillChar(lCell, SizeOf(lCell), 0); value := varNull; Workbook.OnNeedCellData(Workbook, r, c, value); lCell.Row := r; diff --git a/components/fpspreadsheet/xlsxooxml.pas b/components/fpspreadsheet/xlsxooxml.pas index 191dedd6d..6e92eb3cd 100755 --- a/components/fpspreadsheet/xlsxooxml.pas +++ b/components/fpspreadsheet/xlsxooxml.pas @@ -88,6 +88,7 @@ type protected { Record writing methods } //todo: add WriteDate + procedure WriteBlank(AStream: TStream; const ARow, ACol: Cardinal; ACell: PCell); override; procedure WriteLabel(AStream: TStream; const ARow, ACol: Cardinal; const AValue: string; ACell: PCell); override; procedure WriteNumber(AStream: TStream; const ARow, ACol: Cardinal; const AValue: double; ACell: PCell); override; procedure WriteDateTime(AStream: TStream; const ARow, ACol: Cardinal; const AValue: TDateTime; ACell: PCell); override; @@ -354,7 +355,7 @@ procedure TsSpreadOOXMLWriter.WriteWorksheet(CurSheet: TsWorksheet); var r, c: Cardinal; LastColIndex: Cardinal; - LCell: TCell; + lCell: TCell; AVLNode: TAVLTreeNode; CellPosText: string; value: Variant; @@ -391,37 +392,34 @@ begin AppendToStream(FSSheets[FCurSheetNum], Format( '', [r+1, Workbook.VirtualColCount])); for c := 0 to Workbook.VirtualColCount-1 do begin + FillChar(lCell, SizeOf(lCell), 0); CellPosText := CurSheet.CellPosToText(r, c); value := varNull; Workbook.OnNeedCellData(Workbook, r, c, value); + lCell.Row := r; + lCell.Col := c; if VarIsNull(value) then - AppendToStream(FSSheets[FCurSheetNum], Format( - '', - '') - else begin - lCell.Row := r; - lCell.Col := c; - if VarIsNumeric(value) then begin - lCell.ContentType := cctNumber; - lCell.NumberValue := value; - end - { - else if VarIsDateTime(value) then begin - lCell.ContentType := cctNumber; - lCell.DateTimeValue := value; - end - } - else if VarIsStr(value) then begin - lCell.ContentType := cctUTF8String; - lCell.UTF8StringValue := VarToStrDef(value, ''); - end else - if VarIsBool(value) then begin - lCell.ContentType := cctBool; - lCell.BoolValue := value <> 0; - end; - WriteCellCallback(@lCell, nil); + lCell.ContentType := cctEmpty + else + if VarIsNumeric(value) then begin + lCell.ContentType := cctNumber; + lCell.NumberValue := value; + end + { + else if VarIsDateTime(value) then begin + lCell.ContentType := cctNumber; + lCell.DateTimeValue := value; + end + } + else if VarIsStr(value) then begin + lCell.ContentType := cctUTF8String; + lCell.UTF8StringValue := VarToStrDef(value, ''); + end else + if VarIsBool(value) then begin + lCell.ContentType := cctBool; + lCell.BoolValue := value <> 0; end; + WriteCellCallback(@lCell, FSSheets[FCurSheetNum]); end; AppendToStream(FSSheets[FCurSheetNum], ''); @@ -625,6 +623,22 @@ begin end; end; +procedure TsSpreadOOXMLWriter.WriteBlank(AStream: TStream; + const ARow, ACol: Cardinal; ACell: PCell); +var + cellPosText: String; + lStyleIndex: Integer; +begin + cellPosText := TsWorksheet.CellPosToText(ARow, ACol); + lStyleIndex := GetStyleIndex(ACell); + + AppendToStream(AStream, Format( + '', [CellPosText, lStyleIndex]), + '', + ''); +end; + + {******************************************************************* * TsSpreadOOXMLWriter.WriteLabel () * @@ -664,7 +678,7 @@ begin CellPosText := TsWorksheet.CellPosToText(ARow, ACol); lStyleIndex := GetStyleIndex(ACell); - AppendToStream(FSSheets[FCurSheetNum], Format( + AppendToStream(AStream, Format( '%d', [CellPosText, lStyleIndex, FSharedStringsCount])); Inc(FSharedStringsCount); @@ -691,7 +705,7 @@ begin Unused(AStream, ACell); CellPosText := TsWorksheet.CellPosToText(ARow, ACol); CellValueText := Format('%g', [AValue], FPointSeparatorSettings); - AppendToStream(FSSheets[FCurSheetNum], Format( + AppendToStream(AStream, Format( '%s', [CellPosText, CellValueText])); end;