fpspreadsheet: Improves OpenDocument support

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@685 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat
2009-01-28 23:20:25 +00:00
parent e4abbcffc9
commit 47baa4b5a9
3 changed files with 116 additions and 54 deletions

View File

@ -11,7 +11,7 @@
<TargetFileExt Value=".exe"/>
<Title Value="opendocwrite"/>
<UseAppBundle Value="False"/>
<ActiveEditorIndexAtStart Value="0"/>
<ActiveEditorIndexAtStart Value="1"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
@ -38,8 +38,8 @@
<Filename Value="opendocwrite.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="opendocwrite"/>
<CursorPos X="3" Y="66"/>
<TopLine Value="46"/>
<CursorPos X="30" Y="37"/>
<TopLine Value="33"/>
<EditorIndex Value="0"/>
<UsageCount Value="309"/>
<Loaded Value="True"/>
@ -116,10 +116,10 @@
<Unit10>
<Filename Value="..\..\fpspreadsheet.pas"/>
<UnitName Value="fpspreadsheet"/>
<CursorPos X="44" Y="636"/>
<TopLine Value="630"/>
<CursorPos X="1" Y="752"/>
<TopLine Value="737"/>
<EditorIndex Value="3"/>
<UsageCount Value="93"/>
<UsageCount Value="94"/>
<Loaded Value="True"/>
</Unit10>
<Unit11>
@ -131,10 +131,10 @@
<Unit12>
<Filename Value="..\..\fpsopendocument.pas"/>
<UnitName Value="fpsopendocument"/>
<CursorPos X="28" Y="248"/>
<TopLine Value="237"/>
<CursorPos X="87" Y="394"/>
<TopLine Value="386"/>
<EditorIndex Value="1"/>
<UsageCount Value="11"/>
<UsageCount Value="12"/>
<Loaded Value="True"/>
</Unit12>
<Unit13>
@ -143,130 +143,130 @@
<CursorPos X="1" Y="268"/>
<TopLine Value="253"/>
<EditorIndex Value="2"/>
<UsageCount Value="11"/>
<UsageCount Value="12"/>
<Loaded Value="True"/>
</Unit13>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="458" Column="15" TopLine="434"/>
<Caret Line="386" Column="1" TopLine="372"/>
</Position1>
<Position2>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="386" Column="1" TopLine="372"/>
<Caret Line="390" Column="26" TopLine="377"/>
</Position2>
<Position3>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="390" Column="26" TopLine="377"/>
<Caret Line="420" Column="32" TopLine="407"/>
</Position3>
<Position4>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="420" Column="32" TopLine="407"/>
<Caret Line="421" Column="14" TopLine="408"/>
</Position4>
<Position5>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="421" Column="14" TopLine="408"/>
<Caret Line="460" Column="33" TopLine="440"/>
</Position5>
<Position6>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="460" Column="33" TopLine="440"/>
<Caret Line="181" Column="91" TopLine="160"/>
</Position6>
<Position7>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="181" Column="91" TopLine="160"/>
<Caret Line="769" Column="83" TopLine="754"/>
</Position7>
<Position8>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="769" Column="83" TopLine="754"/>
<Caret Line="102" Column="15" TopLine="89"/>
</Position8>
<Position9>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="102" Column="15" TopLine="89"/>
<Caret Line="103" Column="15" TopLine="90"/>
</Position9>
<Position10>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="103" Column="15" TopLine="90"/>
<Caret Line="404" Column="5" TopLine="379"/>
</Position10>
<Position11>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="404" Column="5" TopLine="379"/>
<Caret Line="187" Column="1" TopLine="172"/>
</Position11>
<Position12>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="187" Column="1" TopLine="172"/>
<Caret Line="380" Column="17" TopLine="362"/>
</Position12>
<Position13>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="380" Column="17" TopLine="362"/>
<Caret Line="412" Column="1" TopLine="404"/>
</Position13>
<Position14>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="412" Column="1" TopLine="404"/>
<Caret Line="716" Column="1" TopLine="702"/>
</Position14>
<Position15>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="716" Column="1" TopLine="702"/>
<Caret Line="167" Column="17" TopLine="154"/>
</Position15>
<Position16>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="167" Column="17" TopLine="154"/>
</Position16>
<Position17>
<Filename Value="..\..\xlsbiff2.pas"/>
<Caret Line="69" Column="1" TopLine="57"/>
</Position17>
<Position18>
</Position16>
<Position17>
<Filename Value="opendocwrite.lpr"/>
<Caret Line="71" Column="1" TopLine="46"/>
</Position18>
<Position19>
</Position17>
<Position18>
<Filename Value="..\..\xlsxooxml.pas"/>
<Caret Line="48" Column="16" TopLine="35"/>
</Position18>
<Position19>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="105" Column="1" TopLine="80"/>
</Position19>
<Position20>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="105" Column="1" TopLine="80"/>
<Caret Line="111" Column="1" TopLine="86"/>
</Position20>
<Position21>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="111" Column="1" TopLine="86"/>
<Caret Line="386" Column="1" TopLine="377"/>
</Position21>
<Position22>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="386" Column="1" TopLine="377"/>
<Caret Line="357" Column="1" TopLine="350"/>
</Position22>
<Position23>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="357" Column="1" TopLine="350"/>
<Caret Line="304" Column="3" TopLine="294"/>
</Position23>
<Position24>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="304" Column="3" TopLine="294"/>
<Caret Line="265" Column="28" TopLine="253"/>
</Position24>
<Position25>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="265" Column="28" TopLine="253"/>
<Caret Line="313" Column="1" TopLine="301"/>
</Position25>
<Position26>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="313" Column="1" TopLine="301"/>
<Caret Line="41" Column="45" TopLine="37"/>
</Position26>
<Position27>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="41" Column="45" TopLine="37"/>
<Caret Line="355" Column="5" TopLine="331"/>
</Position27>
<Position28>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="355" Column="5" TopLine="331"/>
<Caret Line="311" Column="1" TopLine="299"/>
</Position28>
<Position29>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="311" Column="1" TopLine="299"/>
<Caret Line="260" Column="28" TopLine="249"/>
</Position29>
<Position30>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="260" Column="28" TopLine="249"/>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="365" Column="5" TopLine="340"/>
</Position30>
</JumpHistory>
</ProjectOptions>

View File

@ -200,8 +200,9 @@ end;
procedure TsSpreadOpenDocWriter.WriteContent(AData: TsWorkbook);
var
i: Integer;
i, j, k: Integer;
CurSheet: TsWorksheet;
CurCell: PCell;
begin
FContent :=
XML_HEADER + LineEnding +
@ -233,7 +234,19 @@ begin
' </office:font-face-decls>' + LineEnding +
// Automatic styles
' <office:automatic-styles>' + LineEnding +
'<office:automatic-styles>' + LineEnding +
'<style:style style:name="co1" style:family="table-column">' + LineEnding +
'<style:table-column-properties fo:break-before="auto" style:column-width="2.267cm"/>' + LineEnding +
'</style:style>' + LineEnding +
'<style:style style:name="ro1" style:family="table-row">' + LineEnding +
'<style:table-row-properties style:row-height="0.416cm" fo:break-before="auto" style:use-optimal-row-height="true"/>' + LineEnding +
'</style:style>' + LineEnding +
'<style:style style:name="ta1" style:family="table" style:master-page-name="Default">' + LineEnding +
'<style:table-properties table:display="true" style:writing-mode="lr-tb"/>' + LineEnding +
'</style:style>' + LineEnding +
'</office:automatic-styles>' + LineEnding +
{ ' <office:automatic-styles>' + LineEnding +
' <style:style style:name="ID0EM" style:family="table-column" xmlns:v="urn:schemas-microsoft-com:vml">' + LineEnding +
' <style:table-column-properties fo:break-before="auto" style:column-width="1.961cm" />' + LineEnding +
' </style:style>' + LineEnding +
@ -249,7 +262,7 @@ begin
' <style:style style:name="scenario" style:family="table" style:master-page-name="Default">' + LineEnding +
' <style:table-properties table:display="false" style:writing-mode="lr-tb" />' + LineEnding +
' </style:style>' + LineEnding +
' </office:automatic-styles>' + LineEnding +
' </office:automatic-styles>' + LineEnding +}
// Body
' <office:body>' + LineEnding +
@ -260,10 +273,23 @@ begin
CurSheet := Adata.GetWorksheetByIndex(i);
// Header
FContent := FContent + '<table:table table:name="' + CurSheet.Name + '" table:style-name="ID2EY">' + LineEnding;
FContent := FContent + '<table:table table:name="' + CurSheet.Name + '" table:style-name="ta1">' + LineEnding
+ '<table:table-column table:style-name="co1" table:number-columns-repeated="' +
IntToStr(CurSheet.GetLastColNumber + 1) + '" table:default-cell-style-name="Default"/>' + LineEnding;
// The cells need to be written in order, row by row
WriteCellsToStream(nil, CurSheet.FCells);
for j := 0 to CurSheet.GetLastRowNumber do
begin
FContent := FContent + '<table:table-row table:style-name="ro1">' + LineEnding;
for k := 0 to CurSheet.FCells.Count - 1 do
begin
CurCell := CurSheet.FCells.Items[k];
if CurCell^.Row = j then WriteCellCallback(CurCell, nil);
end;
FContent := FContent + '</table:table-row>' + LineEnding;
end;
// Footer
FContent := FContent + '</table:table>' + LineEnding;
@ -365,11 +391,9 @@ procedure TsSpreadOpenDocWriter.WriteNumber(AStream: TStream; const ARow,
begin
// The row should already be the correct one
FContent := FContent +
'<table:table-row table:style-name="ro' + IntToStr(ARow) + '">' + LineEnding +
' <table:table-cell office:value-type="float" office:value="' + IntToStr(ACol) + '1">' + LineEnding +
' <table:table-cell office:value-type="float" office:value="' + IntToStr(ACol + 1) + '">' + LineEnding +
' <text:p>1</text:p>' + LineEnding +
' </table:table-cell>' + LineEnding +
'</table:table-row>' + LineEnding;
' </table:table-cell>' + LineEnding;
end;
{*******************************************************************

View File

@ -98,6 +98,8 @@ type
function GetCell(ARow, ACol: Cardinal): PCell;
function GetCellCount: Cardinal;
function GetCellByIndex(AIndex: Cardinal): PCell;
function GetLastColNumber: Cardinal;
function GetLastRowNumber: Cardinal;
function ReadAsUTF8Text(ARow, ACol: Cardinal): ansistring;
procedure RemoveAllCells;
procedure WriteUTF8Text(ARow, ACol: Cardinal; AText: ansistring);
@ -352,6 +354,42 @@ begin
else Result := nil;
end;
function TsWorksheet.GetLastColNumber: Cardinal;
var
i: Integer;
ACell: PCell;
begin
i := 0;
Result := 0;
while (i < FCells.Count) do
begin
ACell := PCell(FCells.Items[i]);
if ACell^.Col > Result then Result := ACell^.Col;
Inc(i);
end;
end;
function TsWorksheet.GetLastRowNumber: Cardinal;
var
i: Integer;
ACell: PCell;
begin
i := 0;
Result := 0;
while (i < FCells.Count) do
begin
ACell := PCell(FCells.Items[i]);
if ACell^.Row > Result then Result := ACell^.Row;
Inc(i);
end;
end;
{@@
Reads the contents of a cell and returns an user readable text
representing the contents of the cell.