fpspreadsheet: Fix show/hide gridlines/headers issue of BIFF2 by adding WINDOW1 record. Move WINDOW1 record of BIFF5-BIFF8 to xlscommon. Add test cases for BIFF2. ok.

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3008 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-05-04 20:01:21 +00:00
parent 256d7b1fbd
commit 707f64e511
6 changed files with 137 additions and 145 deletions

View File

@ -31,6 +31,9 @@ begin
//MyWorksheet.WriteColWidth(0, 5);
//MyWorksheet.WriteColWidth(1, 30);
// Turn off grid lines and hide headers
MyWorksheet.Options := MyWorksheet.Options - [soShowGridLines, soShowHeaders];
{ -- currently not working
MyWorksheet.Options := MyWorksheet.Options + [soHasFrozenPanes];
MyWorksheet.LeftPaneWidth := 1;

View File

@ -15,7 +15,7 @@ uses
testsutility;
type
{ TSpreadWriteReadColorTests }
{ TSpreadWriteReadOptionTests }
//Write to xls/xml file and read back
TSpreadWriteReadOptionsTests = class(TTestCase)
private
@ -29,27 +29,30 @@ type
AShowGridLines, AShowHeaders: Boolean);
published
// Writes out colors & reads back.
// Writes out sheet options & reads back.
{ BIFF2 file format tests }
// procedure TestWriteReadBIFF2_Font_InternalPal; // internal palette for BIFF2 file format
{ BIFF2 tests }
procedure TestWriteReadBIFF2_ShowGridLines_ShowHeaders;
procedure TestWriteReadBIFF2_ShowGridLines_HideHeaders;
procedure TestWriteReadBIFF2_HideGridLines_ShowHeaders;
procedure TestWriteReadBIFF2_HideGridLines_HideHeaders;
{ BIFF5 file format tests }
procedure TestWriteReadBIFF5_GridLines_Headers;
procedure TestWriteReadBIFF5_GridLines;
procedure TestWriteReadBIFF5_Headers;
procedure TestWriteReadBIFF5_NoGridLines_NoHeaders;
{ BIFF5 tests }
procedure TestWriteReadBIFF5_ShowGridLines_ShowHeaders;
procedure TestWriteReadBIFF5_ShowGridLines_HideHeaders;
procedure TestWriteReadBIFF5_HideGridLines_ShowHeaders;
procedure TestWriteReadBIFF5_HideGridLines_HideHeaders;
procedure TestWriteReadBIFF5_Panes_HorVert;
procedure TestWriteReadBIFF5_Panes_Hor;
procedure TestWriteReadBIFF5_Panes_Vert;
procedure TestWriteReadBIFF5_Panes_None;
{ BIFF8 file format tests }
procedure TestWriteReadBIFF8_GridLines_Headers;
procedure TestWriteReadBIFF8_GridLines;
procedure TestWriteReadBIFF8_Headers;
procedure TestWriteReadBIFF8_NoGridLines_NoHeaders;
{ BIFF8 tests }
procedure TestWriteReadBIFF8_ShowGridLines_ShowHeaders;
procedure TestWriteReadBIFF8_ShowGridLines_HideHeaders;
procedure TestWriteReadBIFF8_HideGridLines_ShowHeaders;
procedure TestWriteReadBIFF8_HideGridLines_HideHeaders;
procedure TestWriteReadBIFF8_Panes_HorVert;
procedure TestWriteReadBIFF8_Panes_Hor;
@ -122,44 +125,65 @@ begin
DeleteFile(TempFile);
end;
{ Tests for BIFF2 grid lines and/or headers }
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF2_ShowGridLines_ShowHeaders;
begin
TestWriteReadGridHeaders(sfExcel2, true, true);
end;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF2_ShowGridLines_HideHeaders;
begin
TestWriteReadGridHeaders(sfExcel2, true, false);
end;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF2_HideGridLines_ShowHeaders;
begin
TestWriteReadGridHeaders(sfExcel2, false, true);
end;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF2_HideGridLines_HideHeaders;
begin
TestWriteReadGridHeaders(sfExcel2, false, false);
end;
{ Tests for BIFF5 grid lines and/or headers }
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_GridLines_Headers;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_ShowGridLines_ShowHeaders;
begin
TestWriteReadGridHeaders(sfExcel5, true, true);
end;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_GridLines;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_ShowGridLines_HideHeaders;
begin
TestWriteReadGridHeaders(sfExcel5, true, false);
end;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_Headers;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_HideGridLines_ShowHeaders;
begin
TestWriteReadGridHeaders(sfExcel5, false, true);
end;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_NoGridLines_NoHeaders;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF5_HideGridLines_HideHeaders;
begin
TestWriteReadGridHeaders(sfExcel5, false, false);
end;
{ Tests for BIFF8 grid lines and/or headers }
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_GridLines_Headers;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_ShowGridLines_ShowHeaders;
begin
TestWriteReadGridHeaders(sfExcel8, true, true);
end;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_GridLines;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_ShowGridLines_HideHeaders;
begin
TestWriteReadGridHeaders(sfExcel8, true, false);
end;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_Headers;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_HideGridLines_ShowHeaders;
begin
TestWriteReadGridHeaders(sfExcel8, false, true);
end;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_NoGridLines_NoHeaders;
procedure TSpreadWriteReadOptionsTests.TestWriteReadBIFF8_HideGridLines_HideHeaders;
begin
TestWriteReadGridHeaders(sfExcel8, false, false);
end;

View File

@ -89,6 +89,7 @@ type
AddBackground: Boolean = false);
procedure WriteXFFieldsForFormattingStyles(AStream: TStream);
procedure WriteXFRecords(AStream: TStream);
procedure WriteWindow1(AStream: TStream); override;
procedure WriteWindow2(AStream: TStream; ASheet: TsWorksheet);
protected
procedure WriteBlank(AStream: TStream; const ARow, ACol: Cardinal; ACell: PCell); override;
@ -827,14 +828,41 @@ begin
WriteFormats(AStream);
WriteXFRecords(AStream);
WriteColWidths(AStream);
{ -- currently not working
WriteCellsToStream(AStream, sheet.Cells);
WriteWindow1(AStream);
// { -- currently not working
WriteWindow2(AStream, sheet);
WritePane(AStream, sheet, false); // false for "is not BIFF5 or BIFF8"
}
WriteCellsToStream(AStream, sheet.Cells);
//}
WriteEOF(AStream);
end;
{
Writes an Excel 2 WINDOW1 record
}
procedure TsSpreadBIFF2Writer.WriteWindow1(AStream: TStream);
begin
{ BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_WINDOW1));
AStream.WriteWord(WordToLE(9));
{ Horizontal position of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE(0));
{ Vertical position of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE($0069));
{ Width of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE($339F));
{ Height of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE($1B5D));
{ Window is visible (1) / hidden (0) }
AStream.WriteByte(WordToLE(0));
end;
{
Writes an Excel 2 WINDOW2 record
}

View File

@ -125,7 +125,6 @@ type
procedure WriteRPNFormula(AStream: TStream; const ARow, ACol: Cardinal;
const AFormula: TsRPNFormula; ACell: PCell); override;
procedure WriteStyle(AStream: TStream);
procedure WriteWindow1(AStream: TStream);
procedure WriteWindow2(AStream: TStream; ASheet: TsWorksheet);
procedure WriteXF(AStream: TStream; AFontIndex: Word;
AFormatIndex: Word; AXF_TYPE_PROT, ATextRotation: Byte; ABorders: TsCellBorders;
@ -940,66 +939,9 @@ begin
end;
{*******************************************************************
* TsSpreadBIFF5Writer.WriteWindow1 ()
* TsSpreadBIFF5Writer.WriteWindow2 ()
*
* DESCRIPTION: Writes an Excel 5 WINDOW1 record
*
* This record contains general settings for the
* document window and global workbook settings.
*
* The values written here are reasonable defaults,
* which should work for most sheets.
*
*******************************************************************}
procedure TsSpreadBIFF5Writer.WriteWindow1(AStream: TStream);
begin
{ BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_WINDOW1));
AStream.WriteWord(WordToLE(18));
{ Horizontal position of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(0);
{ Vertical position of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE($0069));
{ Width of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE($339F));
{ Height of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE($1B5D));
{ Option flags }
AStream.WriteWord(WordToLE(
MASK_WINDOW1_OPTION_HORZ_SCROLL_VISIBLE or
MASK_WINDOW1_OPTION_VERT_SCROLL_VISIBLE or
MASK_WINDOW1_OPTION_WORKSHEET_TAB_VISIBLE));
{ Index to active (displayed) worksheet }
AStream.WriteWord($00);
{ Index of first visible tab in the worksheet tab bar }
AStream.WriteWord($00);
{ Number of selected worksheets }
AStream.WriteWord(WordToLE(1));
{ Width of worksheet tab bar (in 1/1000 of window width).
The remaining space is used by the horizontal scroll bar }
AStream.WriteWord(WordToLE(600));
end;
{*******************************************************************
* TsSpreadBIFF5Writer.WriteWindow1 ()
*
* DESCRIPTION: Writes an Excel 5 WINDOW1 record
*
* This record contains aditional settings for the
* document window (BIFF2-BIFF4) or for a specific
* worksheet (BIFF5-BIFF8).
*
* The values written here are reasonable defaults,
* which should work for most sheets.
* DESCRIPTION: Writes an Excel 5 WINDOW2 record
*
*******************************************************************}
procedure TsSpreadBIFF5Writer.WriteWindow2(AStream: TStream;

View File

@ -126,7 +126,6 @@ type
procedure WriteRPNFormula(AStream: TStream; const ARow, ACol: Cardinal;
const AFormula: TsRPNFormula; ACell: PCell); override;
procedure WriteStyle(AStream: TStream);
procedure WriteWindow1(AStream: TStream);
procedure WriteWindow2(AStream: TStream; ASheet: TsWorksheet);
procedure WriteXF(AStream: TStream; AFontIndex: Word;
AFormatIndex: Word; AXF_TYPE_PROT, ATextRotation: Byte; ABorders: TsCellBorders;
@ -227,7 +226,6 @@ const
INT_EXCEL_ID_INDEX = $020B;
INT_EXCEL_ID_ROWINFO = $0208;
INT_EXCEL_ID_STYLE = $0293;
INT_EXCEL_ID_WINDOW1 = $003D;
INT_EXCEL_ID_WINDOW2 = $023E;
INT_EXCEL_ID_RSTRING = $00D6;
INT_EXCEL_ID_RK = $027E;
@ -263,13 +261,6 @@ const
{ STYLE record constants }
MASK_STYLE_BUILT_IN = $8000;
{ WINDOW1 record constants }
MASK_WINDOW1_OPTION_WINDOW_HIDDEN = $0001;
MASK_WINDOW1_OPTION_WINDOW_MINIMISED = $0002;
MASK_WINDOW1_OPTION_HORZ_SCROLL_VISIBLE = $0008;
MASK_WINDOW1_OPTION_VERT_SCROLL_VISIBLE = $0010;
MASK_WINDOW1_OPTION_WORKSHEET_TAB_VISIBLE = $0020;
{ XF substructures }
{ XF_ROTATION }
@ -1109,56 +1100,6 @@ begin
AStream.WriteByte($FF);
end;
{*******************************************************************
* TsSpreadBIFF8Writer.WriteWindow1 ()
*
* DESCRIPTION: Writes an Excel 8 WINDOW1 record
*
* This record contains general settings for the
* document window and global workbook settings.
*
* The values written here are reasonable defaults,
* which should work for most sheets.
*
*******************************************************************}
procedure TsSpreadBIFF8Writer.WriteWindow1(AStream: TStream);
begin
{ BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_WINDOW1));
AStream.WriteWord(WordToLE(18));
{ Horizontal position of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE(0));
{ Vertical position of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE($0069));
{ Width of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE($339F));
{ Height of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE($1B5D));
{ Option flags }
AStream.WriteWord(WordToLE(
MASK_WINDOW1_OPTION_HORZ_SCROLL_VISIBLE or
MASK_WINDOW1_OPTION_VERT_SCROLL_VISIBLE or
MASK_WINDOW1_OPTION_WORKSHEET_TAB_VISIBLE));
{ Index to active (displayed) worksheet }
AStream.WriteWord(WordToLE($00));
{ Index of first visible tab in the worksheet tab bar }
AStream.WriteWord(WordToLE($00));
{ Number of selected worksheets }
AStream.WriteWord(WordToLE(1));
{ Width of worksheet tab bar (in 1/1000 of window width).
The remaining space is used by the horizontal scroll bar }
AStream.WriteWord(WordToLE(600));
end;
{*******************************************************************
* TsSpreadBIFF8Writer.WriteWindow2 ()
*

View File

@ -22,6 +22,7 @@ const
INT_EXCEL_ID_COLINFO = $007D;
INT_EXCEL_ID_DATEMODE = $0022;
INT_EXCEL_ID_PALETTE = $0092;
INT_EXCEL_ID_WINDOW1 = $003D;
INT_EXCEL_ID_XF = $00E0;
{ RECORD IDs which did not change across versions 5-8 }
@ -240,7 +241,14 @@ const
FORMAT_TIME_MSZ = 47; //time MM:SS.0
FORMAT_SCI_1_DECIMAL = 48; //scientific, 1 decimal
{ WINDOW2 record constants - BIFF3-BIFF8}
{ WINDOW1 record constants - BIFF5-BIFF8 }
MASK_WINDOW1_OPTION_WINDOW_HIDDEN = $0001;
MASK_WINDOW1_OPTION_WINDOW_MINIMISED = $0002;
MASK_WINDOW1_OPTION_HORZ_SCROLL_VISIBLE = $0008;
MASK_WINDOW1_OPTION_VERT_SCROLL_VISIBLE = $0010;
MASK_WINDOW1_OPTION_WORKSHEET_TAB_VISIBLE = $0020;
{ WINDOW2 record constants - BIFF3-BIFF8 }
MASK_WINDOW2_OPTION_SHOW_FORMULAS = $0001;
MASK_WINDOW2_OPTION_SHOW_GRID_LINES = $0002;
MASK_WINDOW2_OPTION_SHOW_SHEET_HEADERS = $0004;
@ -416,6 +424,8 @@ type
procedure WritePalette(AStream: TStream);
// Writes out a PANE record
procedure WritePane(AStream: TStream; ASheet: TsWorksheet; IsBiff58: Boolean);
// Writes out a WINDOW1 record
procedure WriteWindow1(AStream: TStream); virtual;
// Writes the index of the XF record used in the given cell
procedure WriteXFIndex(AStream: TStream; ACell: PCell);
@ -1392,6 +1402,50 @@ begin
{ Not used (BIFF5-BIFF8 only, not written in BIFF2-BIFF4 }
end;
{ Writes an Excel 5/8 WINDOW1 record
This record contains general settings for the document window and
global workbook settings.
The values written here are reasonable defaults which should work for most
sheets.
Valid for BIFF5-BIFF8. }
procedure TsSpreadBIFFWriter.WriteWindow1(AStream: TStream);
begin
{ BIFF Record header }
AStream.WriteWord(WordToLE(INT_EXCEL_ID_WINDOW1));
AStream.WriteWord(WordToLE(18));
{ Horizontal position of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE(0));
{ Vertical position of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE($0069));
{ Width of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE($339F));
{ Height of the document window, in twips = 1 / 20 of a point }
AStream.WriteWord(WordToLE($1B5D));
{ Option flags }
AStream.WriteWord(WordToLE(
MASK_WINDOW1_OPTION_HORZ_SCROLL_VISIBLE or
MASK_WINDOW1_OPTION_VERT_SCROLL_VISIBLE or
MASK_WINDOW1_OPTION_WORKSHEET_TAB_VISIBLE));
{ Index to active (displayed) worksheet }
AStream.WriteWord(WordToLE($00));
{ Index of first visible tab in the worksheet tab bar }
AStream.WriteWord(WordToLE($00));
{ Number of selected worksheets }
AStream.WriteWord(WordToLE(1));
{ Width of worksheet tab bar (in 1/1000 of window width).
The remaining space is used by the horizontal scroll bar }
AStream.WriteWord(WordToLE(600));
end;
{ Write the index of the XF record, according to formatting of the given cell
Valid for BIFF5 and BIFF8.
BIFF2 is handled differently. }