fpspreadsheet: reformatting, cosmetic changes

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3945 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2015-02-15 22:05:20 +00:00
parent 12e8f3f987
commit 54c2af0154
5 changed files with 383 additions and 265 deletions

View File

@ -3552,7 +3552,7 @@ end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Clears the list of cells and releases their memory. Clears the list of cells and releases their memory.
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.RemoveAllCells; procedure TsWorksheet.RemoveAllCells;
begin begin
RemoveAllAvlTreeNodes(FCells, RemoveCellsCallback); RemoveAllAvlTreeNodes(FCells, RemoveCellsCallback);
@ -3626,7 +3626,7 @@ end;
@param ARow Row index of the cell to be removed @param ARow Row index of the cell to be removed
@param ACol Column index of the cell to be removed @param ACol Column index of the cell to be removed
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.RemoveAndFreeCell(ARow, ACol: Cardinal); procedure TsWorksheet.RemoveAndFreeCell(ARow, ACol: Cardinal);
var var
cellnode: TAVLTreeNode; cellnode: TAVLTreeNode;
@ -4053,7 +4053,7 @@ end;
Note: An exception is raised if the cell already contains a formula (and is Note: An exception is raised if the cell already contains a formula (and is
different from the ASharedFormulaBase cell). different from the ASharedFormulaBase cell).
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.UseSharedFormula(ARow, ACol: Cardinal; function TsWorksheet.UseSharedFormula(ARow, ACol: Cardinal;
ASharedFormulaBase: PCell): PCell; ASharedFormulaBase: PCell): PCell;
begin begin
@ -4080,7 +4080,7 @@ end;
@param ACol The column of the cell @param ACol The column of the cell
@param AText The text to be written encoded in utf-8 @param AText The text to be written encoded in utf-8
@return Pointer to cell created or used @return Pointer to cell created or used
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.WriteUTF8Text(ARow, ACol: Cardinal; AText: ansistring): PCell; function TsWorksheet.WriteUTF8Text(ARow, ACol: Cardinal; AText: ansistring): PCell;
begin begin
Result := GetCell(ARow, ACol); Result := GetCell(ARow, ACol);
@ -4095,7 +4095,7 @@ end;
@param ACell Poiner to the cell @param ACell Poiner to the cell
@param AText The text to be written encoded in utf-8 @param AText The text to be written encoded in utf-8
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.WriteUTF8Text(ACell: PCell; AText: ansistring); procedure TsWorksheet.WriteUTF8Text(ACell: PCell; AText: ansistring);
begin begin
if ACell = nil then if ACell = nil then
@ -4112,7 +4112,7 @@ end;
@param ACol Cell column index @param ACol Cell column index
@param ANumber Number to be written @param ANumber Number to be written
@return Pointer to cell created or used @return Pointer to cell created or used
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.WriteNumber(ARow, ACol: Cardinal; ANumber: double): PCell; function TsWorksheet.WriteNumber(ARow, ACol: Cardinal; ANumber: double): PCell;
begin begin
Result := GetCell(ARow, ACol); Result := GetCell(ARow, ACol);
@ -4125,7 +4125,7 @@ end;
@param ARow Cell row index @param ARow Cell row index
@param ACol Cell column index @param ACol Cell column index
@param ANumber Number to be written @param ANumber Number to be written
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.WriteNumber(ACell: PCell; ANumber: double); procedure TsWorksheet.WriteNumber(ACell: PCell; ANumber: double);
begin begin
if ACell <> nil then begin if ACell <> nil then begin
@ -4145,7 +4145,7 @@ end;
@param ADecimals Number of decimal places used for formatting (optional) @param ADecimals Number of decimal places used for formatting (optional)
@return Pointer to cell created or used @return Pointer to cell created or used
@see TsNumberFormat @see TsNumberFormat
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.WriteNumber(ARow, ACol: Cardinal; ANumber: double; function TsWorksheet.WriteNumber(ARow, ACol: Cardinal; ANumber: double;
ANumFormat: TsNumberFormat; ADecimals: Byte = 2): PCell; ANumFormat: TsNumberFormat; ADecimals: Byte = 2): PCell;
begin begin
@ -4161,7 +4161,7 @@ end;
@param ANumFormat Identifier for a built-in number format, e.g. nfFixed @param ANumFormat Identifier for a built-in number format, e.g. nfFixed
@param ADecimals Optional number of decimal places used for formatting @param ADecimals Optional number of decimal places used for formatting
@see TsNumberFormat @see TsNumberFormat
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.WriteNumber(ACell: PCell; ANumber: Double; procedure TsWorksheet.WriteNumber(ACell: PCell; ANumber: Double;
ANumFormat: TsNumberFormat; ADecimals: Byte = 2); ANumFormat: TsNumberFormat; ADecimals: Byte = 2);
var var
@ -4202,7 +4202,7 @@ end;
@param ANumFormat Format identifier (nfCustom) @param ANumFormat Format identifier (nfCustom)
@param ANumFormatString String of formatting codes (such as 'dd/mmm' @param ANumFormatString String of formatting codes (such as 'dd/mmm'
@return Pointer to cell created or used @return Pointer to cell created or used
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.WriteNumber(ARow, ACol: Cardinal; ANumber: Double; function TsWorksheet.WriteNumber(ARow, ACol: Cardinal; ANumber: Double;
ANumFormat: TsNumberFormat; ANumFormatString: String): PCell; ANumFormat: TsNumberFormat; ANumFormatString: String): PCell;
begin begin
@ -4219,8 +4219,8 @@ end;
@param ACell Pointer to the cell considered @param ACell Pointer to the cell considered
@param ANumber Number to be written @param ANumber Number to be written
@param ANumFormat Format identifier (nfCustom) @param ANumFormat Format identifier (nfCustom)
@param ANumFormatString String of formatting codes (such as 'dd/mmm' @param ANumFormatString String of formatting codes (such as 'dd/mmm' )
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.WriteNumber(ACell: PCell; ANumber: Double; procedure TsWorksheet.WriteNumber(ACell: PCell; ANumber: Double;
ANumFormat: TsNumberFormat; ANumFormatString: String); ANumFormat: TsNumberFormat; ANumFormatString: String);
var var
@ -4268,7 +4268,7 @@ end;
@return Pointer to the cell @return Pointer to the cell
Note: Empty cells are useful when, for example, a border line extends Note: Empty cells are useful when, for example, a border line extends
along a range of cells including empty cells. along a range of cells including empty cells.
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.WriteBlank(ARow, ACol: Cardinal): PCell; function TsWorksheet.WriteBlank(ARow, ACol: Cardinal): PCell;
begin begin
Result := GetCell(ARow, ACol); Result := GetCell(ARow, ACol);
@ -4281,7 +4281,7 @@ end;
@param ACel Pointer to the cell @param ACel Pointer to the cell
Note: Empty cells are useful when, for example, a border line extends Note: Empty cells are useful when, for example, a border line extends
along a range of cells including empty cells. along a range of cells including empty cells.
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.WriteBlank(ACell: PCell); procedure TsWorksheet.WriteBlank(ACell: PCell);
begin begin
if ACell <> nil then begin if ACell <> nil then begin
@ -4297,7 +4297,7 @@ end;
@param ACol The column of the cell @param ACol The column of the cell
@param AValue The boolean value @param AValue The boolean value
@return Pointer to the cell @return Pointer to the cell
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.WriteBoolValue(ARow, ACol: Cardinal; AValue: Boolean): PCell; function TsWorksheet.WriteBoolValue(ARow, ACol: Cardinal; AValue: Boolean): PCell;
begin begin
Result := GetCell(ARow, ACol); Result := GetCell(ARow, ACol);
@ -4309,7 +4309,7 @@ end;
@param ACell Pointer to the cell @param ACell Pointer to the cell
@param AValue The boolean value @param AValue The boolean value
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.WriteBoolValue(ACell: PCell; AValue: Boolean); procedure TsWorksheet.WriteBoolValue(ACell: PCell; AValue: Boolean);
begin begin
if ACell <> nil then begin if ACell <> nil then begin
@ -4330,7 +4330,7 @@ end;
on the structure of the string, however, the value is written on the structure of the string, however, the value is written
as a number, a date/time or a text. as a number, a date/time or a text.
@return Pointer to the cell @return Pointer to the cell
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.WriteCellValueAsString(ARow, ACol: Cardinal; function TsWorksheet.WriteCellValueAsString(ARow, ACol: Cardinal;
AValue: String): PCell; AValue: String): PCell;
begin begin
@ -4347,7 +4347,7 @@ end;
@param AValue Value to be written into the cell given as a string. Depending @param AValue Value to be written into the cell given as a string. Depending
on the structure of the string, however, the value is written on the structure of the string, however, the value is written
as a number, a date/time or a text. as a number, a date/time or a text.
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.WriteCellValueAsString(ACell: PCell; AValue: String); procedure TsWorksheet.WriteCellValueAsString(ACell: PCell; AValue: String);
var var
isPercent: Boolean; isPercent: Boolean;
@ -4475,7 +4475,7 @@ end;
In case of '?' the currency symbol defined in the In case of '?' the currency symbol defined in the
workbook's FormatSettings is used. workbook's FormatSettings is used.
@return Pointer to the cell @return Pointer to the cell
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.WriteCurrency(ARow, ACol: Cardinal; AValue: Double; function TsWorksheet.WriteCurrency(ARow, ACol: Cardinal; AValue: Double;
ANumFormat: TsNumberFormat = nfCurrency; ADecimals: Integer = 2; ANumFormat: TsNumberFormat = nfCurrency; ADecimals: Integer = 2;
ACurrencySymbol: String = '?'; APosCurrFormat: Integer = -1; ACurrencySymbol: String = '?'; APosCurrFormat: Integer = -1;
@ -4502,7 +4502,7 @@ end;
@param ACurrencySymbol String to be shown as currency, such as '$', or 'EUR'. @param ACurrencySymbol String to be shown as currency, such as '$', or 'EUR'.
In case of '?' the currency symbol defined in the In case of '?' the currency symbol defined in the
workbook's FormatSettings is used. workbook's FormatSettings is used.
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.WriteCurrency(ACell: PCell; AValue: Double; procedure TsWorksheet.WriteCurrency(ACell: PCell; AValue: Double;
ANumFormat: TsNumberFormat = nfCurrency; ADecimals: Integer = -1; ANumFormat: TsNumberFormat = nfCurrency; ADecimals: Integer = -1;
ACurrencySymbol: String = '?'; APosCurrFormat: Integer = -1; ACurrencySymbol: String = '?'; APosCurrFormat: Integer = -1;
@ -4544,7 +4544,7 @@ end;
and negative number. and negative number.
Example: '"EUR" #,##0.00;("EUR" #,##0.00)' Example: '"EUR" #,##0.00;("EUR" #,##0.00)'
@return Pointer to the cell @return Pointer to the cell
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.WriteCurrency(ARow, ACol: Cardinal; AValue: Double; function TsWorksheet.WriteCurrency(ARow, ACol: Cardinal; AValue: Double;
ANumFormat: TsNumberFormat; ANumFormatString: String): PCell; ANumFormat: TsNumberFormat; ANumFormatString: String): PCell;
begin begin
@ -4563,7 +4563,7 @@ end;
Can contain sections for different formatting of positive Can contain sections for different formatting of positive
and negative number. and negative number.
Example: '"EUR" #,##0.00;("EUR" #,##0.00)' Example: '"EUR" #,##0.00;("EUR" #,##0.00)'
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.WriteCurrency(ACell: PCell; AValue: Double; procedure TsWorksheet.WriteCurrency(ACell: PCell; AValue: Double;
ANumFormat: TsNumberFormat; ANumFormatString: String); ANumFormat: TsNumberFormat; ANumFormatString: String);
var var
@ -4597,7 +4597,7 @@ end;
Note: at least Excel xls does not recognize a separate datetime cell type: Note: at least Excel xls does not recognize a separate datetime cell type:
a datetime is stored as a (floating point) number, and the cell is formatted a datetime is stored as a (floating point) number, and the cell is formatted
as a date (either built-in or a custom format). as a date (either built-in or a custom format).
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.WriteDateTime(ARow, ACol: Cardinal; AValue: TDateTime; function TsWorksheet.WriteDateTime(ARow, ACol: Cardinal; AValue: TDateTime;
ANumFormat: TsNumberFormat = nfShortDateTime; ANumFormatStr: String = ''): PCell; ANumFormat: TsNumberFormat = nfShortDateTime; ANumFormatStr: String = ''): PCell;
begin begin
@ -4617,7 +4617,7 @@ end;
Note: at least Excel xls does not recognize a separate datetime cell type: Note: at least Excel xls does not recognize a separate datetime cell type:
a datetime is stored as a (floating point) number, and the cell is formatted a datetime is stored as a (floating point) number, and the cell is formatted
as a date (either built-in or a custom format). as a date (either built-in or a custom format).
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.WriteDateTime(ACell: PCell; AValue: TDateTime; procedure TsWorksheet.WriteDateTime(ACell: PCell; AValue: TDateTime;
ANumFormat: TsNumberFormat = nfShortDateTime; ANumFormatStr: String = ''); ANumFormat: TsNumberFormat = nfShortDateTime; ANumFormatStr: String = '');
var var
@ -4686,7 +4686,7 @@ end;
Note: at least Excel xls does not recognize a separate datetime cell type: Note: at least Excel xls does not recognize a separate datetime cell type:
a datetime is stored as a (floating point) number, and the cell is formatted a datetime is stored as a (floating point) number, and the cell is formatted
as a date (either built-in or a custom format). as a date (either built-in or a custom format).
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.WriteDateTime(ARow, ACol: Cardinal; AValue: TDateTime; function TsWorksheet.WriteDateTime(ARow, ACol: Cardinal; AValue: TDateTime;
ANumFormatStr: String): PCell; ANumFormatStr: String): PCell;
begin begin
@ -4705,7 +4705,7 @@ end;
Note: at least Excel xls does not recognize a separate datetime cell type: Note: at least Excel xls does not recognize a separate datetime cell type:
a datetime is stored as a (floating point) number, and the cell is formatted a datetime is stored as a (floating point) number, and the cell is formatted
as a date (either built-in or a custom format). as a date (either built-in or a custom format).
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.WriteDateTime(ACell: PCell; AValue: TDateTime; procedure TsWorksheet.WriteDateTime(ACell: PCell; AValue: TDateTime;
ANumFormatStr: String); ANumFormatStr: String);
begin begin
@ -4723,7 +4723,7 @@ end;
@return Pointer to the cell @return Pointer to the cell
@see TsNumberFormat @see TsNumberFormat
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorksheet.WriteDateTimeFormat(ARow, ACol: Cardinal; function TsWorksheet.WriteDateTimeFormat(ARow, ACol: Cardinal;
ANumFormat: TsNumberFormat; const ANumFormatString: String = ''): PCell; ANumFormat: TsNumberFormat; const ANumFormatString: String = ''): PCell;
begin begin
@ -6551,7 +6551,7 @@ end;
Removes a specified row record from the worksheet and frees the occupied memory. Removes a specified row record from the worksheet and frees the occupied memory.
This resets the its row height to default. This resets the its row height to default.
Note: Cells in that row are retained. Note: Cells in that row are retained.
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorksheet.RemoveRow(ARow: Cardinal); procedure TsWorksheet.RemoveRow(ARow: Cardinal);
var var
AVLNode: TAVGLVLTreeNode; AVLNode: TAVGLVLTreeNode;
@ -6656,7 +6656,7 @@ end;
Helper method called before saving the workbook. Clears the error log, and Helper method called before saving the workbook. Clears the error log, and
calculates the formulas in all worksheets if workbook option soCalcBeforeSaving calculates the formulas in all worksheets if workbook option soCalcBeforeSaving
is set. is set.
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsWorkbook.PrepareBeforeSaving; procedure TsWorkbook.PrepareBeforeSaving;
var var
sheet: TsWorksheet; sheet: TsWorksheet;
@ -7971,7 +7971,7 @@ end;
BIFF5/BIFF8 can write only 64 colors, i.e BIFF5/BIFF8 can write only 64 colors, i.e
AMaxPaletteCount = 64 AMaxPaletteCount = 64
@return Palette index of the color closest to AColorValue @return Palette index of the color closest to AColorValue
--------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
function TsWorkbook.FindClosestColor(AColorValue: TsColorValue; function TsWorkbook.FindClosestColor(AColorValue: TsColorValue;
AMaxPaletteCount: Integer = -1): TsColor; AMaxPaletteCount: Integer = -1): TsColor;
type type

View File

@ -1480,8 +1480,7 @@ end;
procedure TsSpreadBIFF2Writer.WriteBOF(AStream: TStream); procedure TsSpreadBIFF2Writer.WriteBOF(AStream: TStream);
begin begin
{ BIFF Record header } { BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_BOF)); WriteBiffHeader(AStream, INT_EXCEL_ID_BOF, 4);
AStream.WriteWord(WordToLE($0004));
{ Unused } { Unused }
AStream.WriteWord($0000); AStream.WriteWord($0000);
@ -1497,8 +1496,7 @@ end;
procedure TsSpreadBIFF2Writer.WriteEOF(AStream: TStream); procedure TsSpreadBIFF2Writer.WriteEOF(AStream: TStream);
begin begin
{ BIFF Record header } { BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_EOF)); WriteBiffHeader(AStream, INT_EXCEL_ID_EOF, 0);
AStream.WriteWord($0000);
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -1525,8 +1523,7 @@ begin
Len := Length(lFontName); Len := Length(lFontName);
{ BIFF Record header } { BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_FONT)); WriteBiffHeader(AStream, INT_EXCEL_ID_FONT, 4 + 1 + Len * SizeOf(AnsiChar));
AStream.WriteWord(WordToLE(4 + 1 + Len * SizeOf(AnsiChar)));
{ Height of the font in twips = 1/20 of a point } { Height of the font in twips = 1/20 of a point }
AStream.WriteWord(WordToLE(round(font.Size*20))); AStream.WriteWord(WordToLE(round(font.Size*20)));
@ -1612,8 +1609,7 @@ end;
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsSpreadBIFF2Writer.WriteFormatCount(AStream: TStream); procedure TsSpreadBIFF2Writer.WriteFormatCount(AStream: TStream);
begin begin
AStream.WriteWord(WordToLE(INT_EXCEL_ID_FORMATCOUNT)); WriteBiffHeader(AStream, INT_EXCEL_ID_FORMATCOUNT, 2);
AStream.WriteWord(WordToLE(2));
AStream.WriteWord(WordToLE(21)); // there are 21 built-in formats AStream.WriteWord(WordToLE(21)); // there are 21 built-in formats
end; end;
@ -1718,7 +1714,6 @@ procedure TsSpreadBIFF2Writer.WriteRPNTokenArraySize(AStream: TStream;
ASize: Word); ASize: Word);
begin begin
AStream.WriteByte(ASize); AStream.WriteByte(ASize);
// AStream.WriteByte(Lo(ASize));
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -1745,13 +1740,12 @@ begin
len := Length(s); len := Length(s);
{ BIFF Record header } { BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_STRING)); WriteBiffHeader(AStream, INT_EXCEL_ID_STRING, 1 + len*SizeOf(ansichar));
AStream.WriteWord(WordToLE(1 + len*SizeOf(Char)));
{ Write string length } { Write string length }
AStream.WriteByte(len); AStream.WriteByte(len);
{ Write characters } { Write characters }
AStream.WriteBuffer(s[1], len * SizeOf(Char)); AStream.WriteBuffer(s[1], len * SizeOf(ansichar));
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -1838,7 +1832,6 @@ type
Col: Word; Col: Word;
Attrib1, Attrib2, Attrib3: Byte; Attrib1, Attrib2, Attrib3: Byte;
end; end;
var var
xf: Word; xf: Word;
rec: TBlankRecord; rec: TBlankRecord;
@ -1981,8 +1974,7 @@ begin
containsXF := false; containsXF := false;
{ BIFF record header } { BIFF record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_ROW)); WriteBiffHeader(AStream, INT_EXCEL_ID_ROW, IfThen(containsXF, 18, 13));
AStream.WriteWord(WordToLE(IfThen(containsXF, 18, 13)));
{ Index of row } { Index of row }
AStream.WriteWord(WordToLE(Word(ARowIndex))); AStream.WriteWord(WordToLE(Word(ARowIndex)));

View File

@ -883,7 +883,9 @@ begin
end; end;
{ TsSpreadBIFF5Writer } {------------------------------------------------------------------------------}
{ TsSpreadBIFF5Writer }
{------------------------------------------------------------------------------}
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Writes an Excel BIFF5 file to the disc Writes an Excel BIFF5 file to the disc
@ -1003,8 +1005,7 @@ end;
procedure TsSpreadBIFF5Writer.WriteBOF(AStream: TStream; ADataType: Word); procedure TsSpreadBIFF5Writer.WriteBOF(AStream: TStream; ADataType: Word);
begin begin
{ BIFF Record header } { BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_BOF)); WriteBiffHeader(AStream, INT_EXCEL_ID_BOF, 8);
AStream.WriteWord(WordToLE(8));
{ BIFF version. Should only be used if this BOF is for the workbook globals } { BIFF version. Should only be used if this BOF is for the workbook globals }
if ADataType = INT_BOF_WORKBOOK_GLOBALS then if ADataType = INT_BOF_WORKBOOK_GLOBALS then
@ -1042,8 +1043,7 @@ begin
Len := Length(LatinSheetName); Len := Length(LatinSheetName);
} }
{ BIFF Record header } { BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_BOUNDSHEET)); WriteBiffHeader(AStream, INT_EXCEL_ID_BOUNDSHEET, 6 + 1 + Len);
AStream.WriteWord(WordToLE(6 + 1 + Len));
{ Absolute stream position of the BOF record of the sheet represented { Absolute stream position of the BOF record of the sheet represented
by this record } by this record }
@ -1103,8 +1103,7 @@ end;
procedure TsSpreadBIFF5Writer.WriteEOF(AStream: TStream); procedure TsSpreadBIFF5Writer.WriteEOF(AStream: TStream);
begin begin
{ BIFF Record header } { BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_EOF)); WriteBiffHeader(AStream, INT_EXCEL_ID_EOF, $0000);
AStream.WriteWord($0000);
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -1127,8 +1126,7 @@ begin
Len := Length(AFont.FontName); Len := Length(AFont.FontName);
{ BIFF Record header } { BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_FONT)); WriteBiffHeader(AStream, INT_EXCEL_ID_FONT, 14 + 1 + Len);
AStream.WriteWord(WordToLE(14 + 1 + Len));
{ Height of the font in twips = 1/20 of a point } { Height of the font in twips = 1/20 of a point }
AStream.WriteWord(WordToLE(round(AFont.Size*20))); AStream.WriteWord(WordToLE(round(AFont.Size*20)));
@ -1207,7 +1205,6 @@ begin
if (ANumFormatData = nil) or (ANumFormatData.FormatString = '') then if (ANumFormatData = nil) or (ANumFormatData.FormatString = '') then
exit; exit;
// s := UTF8ToAnsi(NumFormatList.FormatStringForWriting(AListIndex));
fmtStr := NumFormatList.FormatStringForWriting(AListIndex); fmtStr := NumFormatList.FormatStringForWriting(AListIndex);
ansiFmtStr := ConvertEncoding(fmtStr, encodingUTF8, FCodePage); ansiFmtStr := ConvertEncoding(fmtStr, encodingUTF8, FCodePage);
len := Length(ansiFmtStr); len := Length(ansiFmtStr);
@ -1242,8 +1239,7 @@ end;
procedure TsSpreadBIFF5Writer.WriteIndex(AStream: TStream); procedure TsSpreadBIFF5Writer.WriteIndex(AStream: TStream);
begin begin
{ BIFF Record header } { BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_INDEX)); WriteBiffHeader(AStream, INT_EXCEL_ID_INDEX, 12);
AStream.WriteWord(WordToLE(12));
{ Not used } { Not used }
AStream.WriteDWord(0); AStream.WriteDWord(0);
@ -1283,20 +1279,6 @@ begin
exit; exit;
ansiValue := ConvertEncoding(AValue, encodingUTF8, FCodePage); ansiValue := ConvertEncoding(AValue, encodingUTF8, FCodePage);
{
case WorkBookEncoding of
seLatin2: AnsiValue := UTF8ToCP1250(AValue);
seCyrillic: AnsiValue := UTF8ToCP1251(AValue);
seGreek: AnsiValue := UTF8ToCP1253(AValue);
seTurkish: AnsiValue := UTF8ToCP1254(AValue);
seHebrew: AnsiValue := UTF8ToCP1255(AValue);
seArabic: AnsiValue := UTF8ToCP1256(AValue);
else
// Latin 1 is the default
AnsiValue := UTF8ToCP1252(AValue);
end;
}
if AnsiValue = '' then begin if AnsiValue = '' then begin
// Bad formatted UTF8String (maybe ANSI?) // Bad formatted UTF8String (maybe ANSI?)
if Length(AValue) <> 0 then begin if Length(AValue) <> 0 then begin
@ -1355,18 +1337,16 @@ var
s: ansistring; s: ansistring;
len: Integer; len: Integer;
begin begin
// s := UTF8ToAnsi(AString);
s := ConvertEncoding(AString, encodingUTF8, FCodePage); s := ConvertEncoding(AString, encodingUTF8, FCodePage);
len := Length(s); len := Length(s);
{ BIFF Record header } { BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_STRING)); WriteBiffHeader(AStream, INT_EXCEL_ID_STRING, 2 + len*SizeOf(ansichar));
AStream.WriteWord(WordToLE(2 + len*SizeOf(Char)));
{ Write string length } { Write string length }
AStream.WriteWord(WordToLE(len)); AStream.WriteWord(WordToLE(len));
{ Write characters } { Write characters }
AStream.WriteBuffer(s[1], len * SizeOf(Char)); AStream.WriteBuffer(s[1], len * SizeOf(ansichar));
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
@ -1378,8 +1358,7 @@ end;
procedure TsSpreadBIFF5Writer.WriteStyle(AStream: TStream); procedure TsSpreadBIFF5Writer.WriteStyle(AStream: TStream);
begin begin
{ BIFF Record header } { BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_STYLE)); WriteBiffHeader(AStream, INT_EXCEL_ID_STYLE, 4);
AStream.WriteWord(WordToLE(4));
{ Index to style XF and defines if it's a built-in or used defined style } { Index to style XF and defines if it's a built-in or used defined style }
AStream.WriteWord(WordToLE(MASK_STYLE_BUILT_IN)); AStream.WriteWord(WordToLE(MASK_STYLE_BUILT_IN));
@ -1400,8 +1379,7 @@ var
Options: Word; Options: Word;
begin begin
{ BIFF Record header } { BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_WINDOW2)); WriteBiffHeader(AStream, INT_EXCEL_ID_WINDOW2, 10);
AStream.WriteWord(WordToLE(10));
{ Options flags } { Options flags }
Options := Options :=
@ -1444,7 +1422,7 @@ var
begin begin
{ BIFF record header } { BIFF record header }
rec.RecordID := WordToLE(INT_EXCEL_ID_XF); rec.RecordID := WordToLE(INT_EXCEL_ID_XF);
rec.RecordSize := WordToLE(SizeOf(TBIFF5_XFRecord) - 2*SizeOf(Word)); rec.RecordSize := WordToLE(SizeOf(TBIFF5_XFRecord) - SizeOf(TsBiffHeader));
{ Index to font record } { Index to font record }
rec.FontIndex := 0; rec.FontIndex := 0;

View File

@ -118,8 +118,10 @@ type
TsSpreadBIFF8Writer = class(TsSpreadBIFFWriter) TsSpreadBIFF8Writer = class(TsSpreadBIFFWriter)
private private
procedure WriteCommentsCallback(AComment: PsComment; ACommentIndex: Integer; procedure WriteCommentsEscherCallback(AComment: PsComment;
AStream: TStream); ACommentIndex: Integer; AStream: TStream);
procedure WriteCommentsNoteCallback(AComment: PsComment;
ACommentIndex: Integer; AStream: TStream);
protected protected
{ Record writing methods } { Record writing methods }
@ -1595,14 +1597,19 @@ begin
exit; // Remove after comments can be written correctly exit; // Remove after comments can be written correctly
{$warning TODO: Fix writing of cell comments in BIFF8 (file is readable by OpenOffice, but not by Excel)} {$warning TODO: Fix writing of cell comments in BIFF8 (file is readable by OpenOffice, but not by Excel)}
IterateThroughComments(AStream, AWorksheet.Comments, WriteCommentsCallback); { At first we have to write all Escher-related records for all comments. }
IterateThroughComments(AStream, AWorksheet.Comments, WriteCommentsEscherCallback);
{ The NOTE records for all comments follow subsequently. }
IterateThroughComments(AStream, AWorksheet.Comments, WriteCommentsNoteCallback);
end; end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Helper method which stores the pointer to a cell in the FCommentsList if the Helper method which writes all Escher-related records required for a cell
cell contains a comment comment:
MSODRAWING - OBJ - MSODRAWING - TXT
The NOTE records are written separately
-------------------------------------------------------------------------------} -------------------------------------------------------------------------------}
procedure TsSpreadBIFF8Writer.WriteCommentsCallback(AComment: PsComment; procedure TsSpreadBIFF8Writer.WriteCommentsEscherCallback(AComment: PsComment;
ACommentIndex: Integer; AStream: TStream); ACommentIndex: Integer; AStream: TStream);
begin begin
if ACommentIndex = 0 then if ACommentIndex = 0 then
@ -1614,6 +1621,17 @@ begin
WriteTXO(AStream, AComment); WriteTXO(AStream, AComment);
end; end;
{@@ ----------------------------------------------------------------------------
Helper method for writing all NOTE records of a worksheet.
The Escher-related records required for each cell comment already have been
written.
-------------------------------------------------------------------------------}
procedure TsSpreadBIFF8Writer.WriteCommentsNoteCallback(AComment: PsComment;
ACommentIndex: Integer; AStream: TStream);
begin
WriteNOTE(AStream, AComment, ACommentIndex+1);
end;
{@@ ---------------------------------------------------------------------------- {@@ ----------------------------------------------------------------------------
Writes an Excel 8 DIMENSIONS record Writes an Excel 8 DIMENSIONS record

File diff suppressed because it is too large Load Diff