fpspreadsheet: Complete prepared read/write support for cell wordwrap in biff8 and fpspreadsheetgrid

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2954 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
wp_xxyyzz
2014-04-20 16:07:53 +00:00
parent f1fcd9f1f8
commit 313daa2eaf
5 changed files with 289 additions and 104 deletions

View File

@ -52,6 +52,10 @@ begin
lCell^.BackgroundColor := scPURPLE; lCell^.BackgroundColor := scPURPLE;
lCell^.UsedFormattingFields := [uffBackgroundColor]; lCell^.UsedFormattingFields := [uffBackgroundColor];
// Word-wrapped long text
MyWorksheet.WriteUTF8Text(6, 3, 'This is a very, very, very, very long text.');
MyWorksheet.WriteUsedFormatting(6, 3, [uffWordwrap]);
{ Uncomment this to test large XLS files { Uncomment this to test large XLS files
for i := 2 to 20 do for i := 2 to 20 do
begin begin
@ -61,7 +65,6 @@ begin
MyWorksheet.WriteAnsiText(i, 3, ParamStr(0)); MyWorksheet.WriteAnsiText(i, 3, ParamStr(0));
end; end;
} }
// Write the formula E1 = A1 + B1 // Write the formula E1 = A1 + B1
SetLength(MyRPNFormula, 3); SetLength(MyRPNFormula, 3);
MyRPNFormula[0].ElementKind := fekCell; MyRPNFormula[0].ElementKind := fekCell;

View File

@ -38,15 +38,17 @@
<PackageName Value="LCL"/> <PackageName Value="LCL"/>
</Item2> </Item2>
</RequiredPackages> </RequiredPackages>
<Units Count="12"> <Units Count="23">
<Unit0> <Unit0>
<Filename Value="fpsgrid.lpr"/> <Filename Value="fpsgrid.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="fpsgrid"/> <UnitName Value="fpsgrid"/>
<EditorIndex Value="0"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="1"/> <TopLine Value="1"/>
<CursorPos X="16" Y="9"/> <CursorPos X="1" Y="11"/>
<UsageCount Value="67"/> <UsageCount Value="88"/>
<Loaded Value="True"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<Filename Value="mainform.pas"/> <Filename Value="mainform.pas"/>
@ -55,35 +57,35 @@
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="mainform"/> <UnitName Value="mainform"/>
<EditorIndex Value="0"/> <EditorIndex Value="1"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="1"/> <TopLine Value="50"/>
<CursorPos X="11" Y="12"/> <CursorPos X="30" Y="57"/>
<UsageCount Value="67"/> <UsageCount Value="88"/>
<Loaded Value="True"/> <Loaded Value="True"/>
<LoadedDesigner Value="True"/> <LoadedDesigner Value="True"/>
</Unit1> </Unit1>
<Unit2> <Unit2>
<Filename Value="..\..\fpspreadsheet.pas"/> <Filename Value="..\..\fpspreadsheet.pas"/>
<UnitName Value="fpspreadsheet"/> <UnitName Value="fpspreadsheet"/>
<EditorIndex Value="1"/> <EditorIndex Value="9"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="1413"/> <TopLine Value="161"/>
<CursorPos X="1" Y="1428"/> <CursorPos X="3" Y="180"/>
<UsageCount Value="32"/> <UsageCount Value="42"/>
<Bookmarks Count="1">
<Item0 X="28" Y="1425" ID="1"/>
</Bookmarks>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit2> </Unit2>
<Unit3> <Unit3>
<Filename Value="..\..\fpspreadsheetgrid.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<UnitName Value="fpspreadsheetgrid"/> <UnitName Value="fpspreadsheetgrid"/>
<EditorIndex Value="5"/> <EditorIndex Value="2"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="129"/> <TopLine Value="206"/>
<CursorPos X="14" Y="142"/> <CursorPos X="45" Y="223"/>
<UsageCount Value="33"/> <UsageCount Value="43"/>
<Bookmarks Count="1">
<Item0 X="1" Y="194" ID="1"/>
</Bookmarks>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit3> </Unit3>
<Unit4> <Unit4>
@ -92,7 +94,7 @@
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="25"/> <TopLine Value="25"/>
<CursorPos X="4" Y="44"/> <CursorPos X="4" Y="44"/>
<UsageCount Value="6"/> <UsageCount Value="5"/>
</Unit4> </Unit4>
<Unit5> <Unit5>
<Filename Value="c:\lazarus27\fpc\2.2.4\source\packages\winunits-base\src\activex.pp"/> <Filename Value="c:\lazarus27\fpc\2.2.4\source\packages\winunits-base\src\activex.pp"/>
@ -100,7 +102,7 @@
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="49"/> <TopLine Value="49"/>
<CursorPos X="10" Y="24"/> <CursorPos X="10" Y="24"/>
<UsageCount Value="6"/> <UsageCount Value="5"/>
</Unit5> </Unit5>
<Unit6> <Unit6>
<Filename Value="c:\lazarus27\fpc\2.2.4\source\packages\fcl-base\src\avl_tree.pp"/> <Filename Value="c:\lazarus27\fpc\2.2.4\source\packages\fcl-base\src\avl_tree.pp"/>
@ -108,7 +110,7 @@
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="37"/> <TopLine Value="37"/>
<CursorPos X="14" Y="83"/> <CursorPos X="14" Y="83"/>
<UsageCount Value="6"/> <UsageCount Value="5"/>
</Unit6> </Unit6>
<Unit7> <Unit7>
<Filename Value="c:\Lazarus\lcl\grids.pas"/> <Filename Value="c:\Lazarus\lcl\grids.pas"/>
@ -116,167 +118,266 @@
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="1516"/> <TopLine Value="1516"/>
<CursorPos X="28" Y="1534"/> <CursorPos X="28" Y="1534"/>
<UsageCount Value="6"/> <UsageCount Value="5"/>
</Unit7> </Unit7>
<Unit8> <Unit8>
<Filename Value="c:\Lazarus\lcl\include\customform.inc"/> <Filename Value="c:\Lazarus\lcl\include\customform.inc"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="2021"/> <TopLine Value="2021"/>
<CursorPos X="1" Y="2041"/> <CursorPos X="1" Y="2041"/>
<UsageCount Value="6"/> <UsageCount Value="5"/>
</Unit8> </Unit8>
<Unit9> <Unit9>
<Filename Value="..\..\fpsallformats.pas"/> <Filename Value="..\..\fpsallformats.pas"/>
<UnitName Value="fpsallformats"/> <UnitName Value="fpsallformats"/>
<EditorIndex Value="3"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="1"/> <TopLine Value="1"/>
<CursorPos X="62" Y="13"/> <CursorPos X="62" Y="13"/>
<UsageCount Value="11"/> <UsageCount Value="15"/>
<Loaded Value="True"/>
</Unit9> </Unit9>
<Unit10> <Unit10>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\wikitable.pas"/>
<UnitName Value="wikitable"/> <UnitName Value="wikitable"/>
<EditorIndex Value="4"/> <EditorIndex Value="10"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="329"/> <TopLine Value="48"/>
<CursorPos X="26" Y="339"/> <CursorPos X="41" Y="60"/>
<UsageCount Value="11"/> <UsageCount Value="20"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit10> </Unit10>
<Unit11> <Unit11>
<Filename Value="..\..\fpsopendocument.pas"/> <Filename Value="..\..\fpsopendocument.pas"/>
<UnitName Value="fpsopendocument"/> <UnitName Value="fpsopendocument"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="2"/>
<WindowIndex Value="0"/> <WindowIndex Value="0"/>
<TopLine Value="280"/> <TopLine Value="280"/>
<CursorPos X="7" Y="291"/> <CursorPos X="41" Y="285"/>
<UsageCount Value="11"/> <UsageCount Value="15"/>
<Loaded Value="True"/>
</Unit11> </Unit11>
<Unit12>
<Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<UnitName Value="Grids"/>
<EditorIndex Value="13"/>
<WindowIndex Value="0"/>
<TopLine Value="4124"/>
<CursorPos X="3" Y="4129"/>
<UsageCount Value="20"/>
<Loaded Value="True"/>
</Unit12>
<Unit13>
<Filename Value="..\..\fpsutils.pas"/>
<UnitName Value="fpsutils"/>
<EditorIndex Value="12"/>
<WindowIndex Value="0"/>
<TopLine Value="413"/>
<CursorPos X="45" Y="447"/>
<UsageCount Value="19"/>
<Loaded Value="True"/>
</Unit13>
<Unit14>
<Filename Value="d:\lazarus-svn\lcl\include\canvas.inc"/>
<EditorIndex Value="4"/>
<WindowIndex Value="0"/>
<TopLine Value="1212"/>
<CursorPos X="3" Y="1218"/>
<UsageCount Value="12"/>
<Loaded Value="True"/>
</Unit14>
<Unit15>
<Filename Value="d:\lazarus-svn\lcl\graphics.pp"/>
<UnitName Value="Graphics"/>
<EditorIndex Value="3"/>
<WindowIndex Value="0"/>
<TopLine Value="84"/>
<CursorPos X="3" Y="101"/>
<UsageCount Value="12"/>
<Loaded Value="True"/>
</Unit15>
<Unit16>
<Filename Value="d:\lazarus-svn\fpc\2.6.2\source\rtl\objpas\classes\classesh.inc"/>
<WindowIndex Value="0"/>
<TopLine Value="76"/>
<CursorPos X="3" Y="95"/>
<UsageCount Value="12"/>
</Unit16>
<Unit17>
<Filename Value="..\..\xlsbiff8.pas"/>
<UnitName Value="xlsbiff8"/>
<IsVisibleTab Value="True"/>
<EditorIndex Value="5"/>
<WindowIndex Value="0"/>
<TopLine Value="1518"/>
<CursorPos X="38" Y="1529"/>
<UsageCount Value="17"/>
<Loaded Value="True"/>
</Unit17>
<Unit18>
<Filename Value="d:\lazarus-svn\lcl\comctrls.pp"/>
<UnitName Value="ComCtrls"/>
<WindowIndex Value="0"/>
<TopLine Value="537"/>
<CursorPos X="23" Y="567"/>
<UsageCount Value="9"/>
</Unit18>
<Unit19>
<Filename Value="d:\lazarus-svn\lcl\include\wincontrol.inc"/>
<EditorIndex Value="8"/>
<WindowIndex Value="0"/>
<TopLine Value="7344"/>
<CursorPos X="30" Y="7349"/>
<UsageCount Value="14"/>
<Loaded Value="True"/>
</Unit19>
<Unit20>
<Filename Value="..\..\xlscommon.pas"/>
<UnitName Value="xlscommon"/>
<EditorIndex Value="11"/>
<WindowIndex Value="0"/>
<TopLine Value="464"/>
<CursorPos X="1" Y="485"/>
<UsageCount Value="14"/>
<Loaded Value="True"/>
</Unit20>
<Unit21>
<Filename Value="..\..\xlsbiff5.pas"/>
<UnitName Value="xlsbiff5"/>
<EditorIndex Value="6"/>
<WindowIndex Value="0"/>
<TopLine Value="1110"/>
<CursorPos X="1" Y="1134"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit21>
<Unit22>
<Filename Value="..\..\xlsbiff2.pas"/>
<UnitName Value="xlsbiff2"/>
<EditorIndex Value="7"/>
<WindowIndex Value="0"/>
<TopLine Value="93"/>
<CursorPos X="35" Y="83"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit22>
</Units> </Units>
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="30" HistoryIndex="29">
<Position1> <Position1>
<Filename Value="..\..\fpsallformats.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="13" Column="62" TopLine="1"/> <Caret Line="193" Column="14" TopLine="186"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="1" Column="1" TopLine="1"/> <Caret Line="194" Column="1" TopLine="186"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="417" Column="63" TopLine="399"/> <Caret Line="180" Column="58" TopLine="171"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="mainform.pas"/> <Filename Value="..\..\fpsutils.pas"/>
<Caret Line="10" Column="42" TopLine="1"/> <Caret Line="56" Column="1" TopLine="34"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\fpsutils.pas"/>
<Caret Line="350" Column="34" TopLine="342"/> <Caret Line="445" Column="1" TopLine="411"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\fpsutils.pas"/>
<Caret Line="323" Column="29" TopLine="313"/> <Caret Line="59" Column="1" TopLine="21"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="7" Column="12" TopLine="1"/> <Caret Line="191" Column="1" TopLine="181"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="131" Column="17" TopLine="113"/> <Caret Line="1905" Column="39" TopLine="1869"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\xlsbiff5.pas"/>
<Caret Line="136" Column="50" TopLine="118"/> <Caret Line="1372" Column="3" TopLine="1367"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="138" Column="11" TopLine="120"/> <Caret Line="205" Column="1" TopLine="186"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="176" Column="49" TopLine="159"/> <Caret Line="204" Column="23" TopLine="186"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\xlsbiff2.pas"/>
<Caret Line="178" Column="29" TopLine="161"/> <Caret Line="464" Column="1" TopLine="435"/>
</Position12> </Position12>
<Position13> <Position13>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="182" Column="37" TopLine="165"/> <Caret Line="128" Column="45" TopLine="125"/>
</Position13> </Position13>
<Position14> <Position14>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="205" Column="29" TopLine="188"/> <Caret Line="148" Column="28" TopLine="148"/>
</Position14> </Position14>
<Position15> <Position15>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="228" Column="29" TopLine="211"/> <Caret Line="222" Column="29" TopLine="188"/>
</Position15> </Position15>
<Position16> <Position16>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="289" Column="42" TopLine="271"/> <Caret Line="221" Column="47" TopLine="203"/>
</Position16> </Position16>
<Position17> <Position17>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="293" Column="49" TopLine="275"/> <Caret Line="200" Column="3" TopLine="180"/>
</Position17> </Position17>
<Position18> <Position18>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="307" Column="40" TopLine="302"/> <Caret Line="222" Column="45" TopLine="196"/>
</Position18> </Position18>
<Position19> <Position19>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="d:\lazarus-svn\lcl\graphics.pp"/>
<Caret Line="321" Column="19" TopLine="312"/> <Caret Line="1218" Column="14" TopLine="1200"/>
</Position19> </Position19>
<Position20> <Position20>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="..\..\fpspreadsheetgrid.pas"/>
<Caret Line="53" Column="1" TopLine="32"/> <Caret Line="211" Column="71" TopLine="241"/>
</Position20> </Position20>
<Position21> <Position21>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="d:\lazarus-svn\lcl\grids.pas"/>
<Caret Line="88" Column="79" TopLine="75"/> <Caret Line="4129" Column="3" TopLine="4124"/>
</Position21> </Position21>
<Position22> <Position22>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="d:\lazarus-svn\lcl\include\canvas.inc"/>
<Caret Line="411" Column="10" TopLine="407"/> <Caret Line="1187" Column="3" TopLine="1178"/>
</Position22> </Position22>
<Position23> <Position23>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="d:\lazarus-svn\lcl\graphics.pp"/>
<Caret Line="102" Column="19" TopLine="85"/> <Caret Line="1207" Column="15" TopLine="1188"/>
</Position23> </Position23>
<Position24> <Position24>
<Filename Value="..\..\wikitable.pas"/> <Filename Value="d:\lazarus-svn\lcl\graphics.pp"/>
<Caret Line="108" Column="1" TopLine="104"/> <Caret Line="1208" Column="40" TopLine="1188"/>
</Position24> </Position24>
<Position25> <Position25>
<Filename Value="mainform.pas"/> <Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="10" Column="16" TopLine="1"/> <Caret Line="1558" Column="3" TopLine="1520"/>
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="..\..\fpspreadsheet.pas"/> <Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="1425" Column="28" TopLine="1416"/> <Caret Line="162" Column="78" TopLine="147"/>
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="..\..\fpspreadsheet.pas"/> <Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="1249" Column="3" TopLine="1240"/> <Caret Line="1531" Column="29" TopLine="1518"/>
</Position27> </Position27>
<Position28> <Position28>
<Filename Value="..\..\fpspreadsheet.pas"/> <Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="1425" Column="28" TopLine="1413"/> <Caret Line="409" Column="1" TopLine="382"/>
</Position28> </Position28>
<Position29> <Position29>
<Filename Value="..\..\fpspreadsheet.pas"/> <Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="1428" Column="1" TopLine="1413"/> <Caret Line="613" Column="81" TopLine="588"/>
</Position29> </Position29>
<Position30> <Position30>
<Filename Value="..\..\fpsopendocument.pas"/> <Filename Value="..\..\xlsbiff8.pas"/>
<Caret Line="295" Column="32" TopLine="279"/> <Caret Line="163" Column="37" TopLine="144"/>
</Position30> </Position30>
</JumpHistory> </JumpHistory>
</ProjectOptions> </ProjectOptions>
@ -303,6 +404,11 @@
</Other> </Other>
</CompilerOptions> </CompilerOptions>
<Debugging> <Debugging>
<Watches Count="1">
<Item1>
<Expression Value="ldata.borders"/>
</Item1>
</Watches>
<Exceptions Count="3"> <Exceptions Count="3">
<Item1> <Item1>
<Name Value="EAbort"/> <Name Value="EAbort"/>

View File

@ -217,6 +217,11 @@ begin
// Default alignment of number is right-justify // Default alignment of number is right-justify
if lCell^.ContentType = cctNumber then if lCell^.ContentType = cctNumber then
ts.Alignment := taRightJustify; ts.Alignment := taRightJustify;
// Word wrap?
if (uffWordWrap in lCell^.UsedFormattingFields) then begin
ts.Wordbreak := true;
ts.SingleLine := false;
end;
end; end;
end; end;
Canvas.TextStyle := ts; Canvas.TextStyle := ts;

View File

@ -49,6 +49,8 @@ type
procedure TestWriteReadDateTimeFormats; procedure TestWriteReadDateTimeFormats;
// Test column width // Test column width
procedure TestWriteReadColWidths; procedure TestWriteReadColWidths;
// Test word wrapping
procedure TestWriteReadWordWrap;
end; end;
implementation implementation
@ -274,6 +276,58 @@ begin
DeleteFile(TempFile); DeleteFile(TempFile);
end; end;
procedure TSpreadWriteReadFormatTests.TestWriteReadWordWrap;
const
LONGTEXT = 'This is a very, very, very, very long text.';
var
MyWorksheet: TsWorksheet;
MyWorkbook: TsWorkbook;
MyCell: PCell;
TempFile: string; //write xls/xml to this file and read back from it
begin
TempFile:=GetTempFileName;
{// Not needed: use workbook.writetofile with overwrite=true
if fileexists(TempFile) then
DeleteFile(TempFile);
}
// Write out all test values:
// Cell A1 is word-wrapped, Cell B1 is NOT word-wrapped
MyWorkbook := TsWorkbook.Create;
MyWorkSheet:= MyWorkBook.AddWorksheet(FmtNumbersSheet);
MyWorksheet.WriteUTF8Text(0, 0, LONGTEXT);
MyWorksheet.WriteUsedFormatting(0, 0, [uffWordwrap]);
MyCell := MyWorksheet.FindCell(0, 0);
if MyCell = nil then
fail('Error in test code. Failed to get word-wrapped cell.');
CheckEquals((uffWordWrap in MyCell^.UsedFormattingFields), true, 'Test unsaved word wrap mismatch cell ' + CellNotation(MyWorksheet,0,0));
MyWorksheet.WriteUTF8Text(1, 0, LONGTEXT);
MyWorksheet.WriteUsedFormatting(1, 0, []);
MyCell := MyWorksheet.FindCell(1, 0);
if MyCell = nil then
fail('Error in test code. Failed to get word-wrapped cell.');
CheckEquals((uffWordWrap in MyCell^.UsedFormattingFields), false, 'Test unsaved non-wrapped cell mismatch, cell ' + CellNotation(MyWorksheet,0,0));
MyWorkBook.WriteToFile(TempFile,sfExcel8,true);
MyWorkbook.Free;
// Open the spreadsheet, as biff8
MyWorkbook := TsWorkbook.Create;
MyWorkbook.ReadFromFile(TempFile, sfExcel8);
MyWorksheet:=GetWorksheetByName(MyWorkBook, FmtNumbersSheet);
if MyWorksheet=nil then
fail('Error in test code. Failed to get named worksheet');
MyCell := MyWorksheet.FindCell(0, 0);
if MyCell = nil then
fail('Error in test code. Failed to get word-wrapped cell.');
CheckEquals((uffWordWrap in MyCell^.UsedFormattingFields), true, 'failed to return correct word-wrap flag, cell ' + CellNotation(MyWorksheet,0,0));
MyCell := MyWorksheet.FindCell(1, 0);
if MyCell = nil then
fail('Error in test code. Failed to get non-wrapped cell.');
CheckEquals((uffWordWrap in MyCell^.UsedFormattingFields), false, 'failed to return correct word-wrap flag, cell ' + CellNotation(MyWorksheet,0,0));
// Finalization
MyWorkbook.Free;
DeleteFile(TempFile);
end;
initialization initialization
RegisterTest(TSpreadWriteReadFormatTests); RegisterTest(TSpreadWriteReadFormatTests);

View File

@ -66,6 +66,7 @@ type
TXFRecordData = class TXFRecordData = class
public public
FormatIndex: Integer; FormatIndex: Integer;
WordWrap: Boolean;
Borders: TsCellBorders; Borders: TsCellBorders;
{ {
FontIndex: Integer; FontIndex: Integer;
@ -156,6 +157,10 @@ type
protected protected
procedure AddDefaultFormats(); override; procedure AddDefaultFormats(); override;
procedure WriteColInfo(AStream: TStream; ASheet: TsWorksheet; ACol: PCol); procedure WriteColInfo(AStream: TStream; ASheet: TsWorksheet; ACol: PCol);
procedure WriteXF(AStream: TStream; AFontIndex: Word;
AFormatIndex: Word; AXF_TYPE_PROT, ATextRotation: Byte; ABorders: TsCellBorders;
AddWordWrap: Boolean = false; AddBackground: Boolean = false;
ABackgroundColor: TsColor = scSilver);
public public
// constructor Create; // constructor Create;
// destructor Destroy; override; // destructor Destroy; override;
@ -181,9 +186,6 @@ type
procedure WriteStyle(AStream: TStream); procedure WriteStyle(AStream: TStream);
procedure WriteWindow1(AStream: TStream); procedure WriteWindow1(AStream: TStream);
procedure WriteWindow2(AStream: TStream; ASheetSelected: Boolean); procedure WriteWindow2(AStream: TStream; ASheetSelected: Boolean);
procedure WriteXF(AStream: TStream; AFontIndex: Word;
AFormatIndex: Word; AXF_TYPE_PROT, ATextRotation: Byte; ABorders: TsCellBorders;
AddBackground: Boolean = False; ABackgroundColor: TsColor = scSilver);
end; end;
implementation implementation
@ -302,7 +304,9 @@ const
MASK_XF_TYPE_PROT = $0007; MASK_XF_TYPE_PROT = $0007;
MASK_XF_TYPE_PROT_PARENT = $FFF0; MASK_XF_TYPE_PROT_PARENT = $FFF0;
MASK_XF_HOR_ALIGN = $07;
MASK_XF_VERT_ALIGN = $70; MASK_XF_VERT_ALIGN = $70;
MASK_XF_TEXTWRAP = $08;
{ {
Exported functions Exported functions
@ -392,6 +396,7 @@ var
lBorders: TsCellBorders; lBorders: TsCellBorders;
lAddBackground: Boolean; lAddBackground: Boolean;
lBackgroundColor: TsColor; lBackgroundColor: TsColor;
lWordWrap: Boolean;
fmt: String; fmt: String;
begin begin
// The first 4 styles were already added // The first 4 styles were already added
@ -402,7 +407,6 @@ begin
lFormatIndex := 0; //General format (one of the built-in number formats) lFormatIndex := 0; //General format (one of the built-in number formats)
lTextRotation := XF_ROTATION_HORIZONTAL; lTextRotation := XF_ROTATION_HORIZONTAL;
lBorders := []; lBorders := [];
lAddBackground := False;
lBackgroundColor := FFormattingStyles[i].BackgroundColor; lBackgroundColor := FFormattingStyles[i].BackgroundColor;
// Now apply the modifications. // Now apply the modifications.
@ -480,11 +484,12 @@ begin
if uffBold in FFormattingStyles[i].UsedFormattingFields then if uffBold in FFormattingStyles[i].UsedFormattingFields then
lFontIndex := 1; lFontIndex := 1;
if uffBackgroundColor in FFormattingStyles[i].UsedFormattingFields then lAddBackground := (uffBackgroundColor in FFormattingStyles[i].UsedFormattingFields);
lAddBackground := True; lWordwrap := (uffWordwrap in FFormattingStyles[i].UsedFormattingFields);
// And finally write the style // And finally write the style
WriteXF(AStream, lFontIndex, lFormatIndex, 0, lTextRotation, lBorders, lAddBackground, lBackgroundColor); WriteXF(AStream, lFontIndex, lFormatIndex, 0, lTextRotation, lBorders, lWordwrap,
lAddBackground, lBackgroundColor);
end; end;
end; end;
@ -1520,7 +1525,8 @@ end;
*******************************************************************} *******************************************************************}
procedure TsSpreadBIFF8Writer.WriteXF(AStream: TStream; AFontIndex: Word; procedure TsSpreadBIFF8Writer.WriteXF(AStream: TStream; AFontIndex: Word;
AFormatIndex: Word; AXF_TYPE_PROT, ATextRotation: Byte; ABorders: TsCellBorders; AFormatIndex: Word; AXF_TYPE_PROT, ATextRotation: Byte; ABorders: TsCellBorders;
AddBackground: Boolean = False; ABackgroundColor: TsColor = scSilver); AddWordWrap: Boolean = false; AddBackground: Boolean = false;
ABackgroundColor: TsColor = scSilver);
var var
XFOptions: Word; XFOptions: Word;
XFAlignment, XFOrientationAttrib: Byte; XFAlignment, XFOrientationAttrib: Byte;
@ -1546,6 +1552,8 @@ begin
{ Alignment and text break } { Alignment and text break }
XFAlignment := MASK_XF_VERT_ALIGN_BOTTOM; XFAlignment := MASK_XF_VERT_ALIGN_BOTTOM;
if AddWordWrap then
XFAlignment := XFAlignment or MASK_XF_TEXTWRAP;
AStream.WriteByte(XFAlignment); AStream.WriteByte(XFAlignment);
@ -2050,6 +2058,12 @@ begin
if Assigned(lCell) then begin if Assigned(lCell) then begin
XFData := TXFRecordData(FXFList.Items[XFIndex]); XFData := TXFRecordData(FXFList.Items[XFIndex]);
// Word wrap
if XFData.WordWrap then
Include(lCell^.UsedFormattingFields, uffWordWrap)
else
Exclude(lCell^.UsedFormattingFields, uffWordWrap);
// Borders // Borders
if XFData.Borders <> [] then begin if XFData.Borders <> [] then begin
Include(lCell^.UsedFormattingFields, uffBorder); Include(lCell^.UsedFormattingFields, uffBorder);
@ -2389,6 +2403,9 @@ begin
// Format index // Format index
lData.FormatIndex := WordLEToN(xf.FormatIndex); lData.FormatIndex := WordLEToN(xf.FormatIndex);
// Word wrap
lData.WordWrap := (xf.Align_TextBreak and MASK_XF_TEXTWRAP) <> 0;
// Cell borders // Cell borders
xf.Border_Background_1 := DWordLEToN(xf.Border_Background_1); xf.Border_Background_1 := DWordLEToN(xf.Border_Background_1);
lData.Borders := []; lData.Borders := [];