fpspreadsheet: Improves OpenDocument support

git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@687 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
sekelsenmat 2009-01-29 11:54:07 +00:00
parent f8cd84c9ee
commit 87fe92f9d7
5 changed files with 110 additions and 82 deletions

View File

@ -11,7 +11,7 @@
<TargetFileExt Value=".exe"/>
<Title Value="opendocwrite"/>
<UseAppBundle Value="False"/>
<ActiveEditorIndexAtStart Value="3"/>
<ActiveEditorIndexAtStart Value="1"/>
</General>
<VersionInfo>
<ProjectVersion Value=""/>
@ -33,13 +33,13 @@
<PackageName Value="laz_fpspreadsheet"/>
</Item1>
</RequiredPackages>
<Units Count="14">
<Units Count="15">
<Unit0>
<Filename Value="opendocwrite.lpr"/>
<IsPartOfProject Value="True"/>
<UnitName Value="opendocwrite"/>
<CursorPos X="33" Y="61"/>
<TopLine Value="47"/>
<CursorPos X="9" Y="30"/>
<TopLine Value="8"/>
<EditorIndex Value="0"/>
<UsageCount Value="309"/>
<Loaded Value="True"/>
@ -70,7 +70,7 @@
<UnitName Value="xlsbiff5"/>
<CursorPos X="26" Y="95"/>
<TopLine Value="92"/>
<EditorIndex Value="5"/>
<EditorIndex Value="6"/>
<UsageCount Value="140"/>
<Loaded Value="True"/>
</Unit4>
@ -79,7 +79,7 @@
<UnitName Value="fpsutils"/>
<CursorPos X="1" Y="49"/>
<TopLine Value="30"/>
<EditorIndex Value="4"/>
<EditorIndex Value="5"/>
<UsageCount Value="140"/>
<Loaded Value="True"/>
</Unit5>
@ -88,7 +88,7 @@
<UnitName Value="xlsbiff2"/>
<CursorPos X="1" Y="16"/>
<TopLine Value="1"/>
<EditorIndex Value="6"/>
<EditorIndex Value="7"/>
<UsageCount Value="139"/>
<Loaded Value="True"/>
</Unit6>
@ -97,7 +97,7 @@
<UnitName Value="fpolestorage"/>
<CursorPos X="30" Y="654"/>
<TopLine Value="642"/>
<EditorIndex Value="7"/>
<EditorIndex Value="8"/>
<UsageCount Value="139"/>
<Loaded Value="True"/>
</Unit7>
@ -116,9 +116,9 @@
<Unit10>
<Filename Value="..\..\fpspreadsheet.pas"/>
<UnitName Value="fpspreadsheet"/>
<CursorPos X="46" Y="308"/>
<TopLine Value="296"/>
<EditorIndex Value="3"/>
<CursorPos X="1" Y="759"/>
<TopLine Value="746"/>
<EditorIndex Value="4"/>
<UsageCount Value="95"/>
<Loaded Value="True"/>
</Unit10>
@ -131,8 +131,8 @@
<Unit12>
<Filename Value="..\..\fpsopendocument.pas"/>
<UnitName Value="fpsopendocument"/>
<CursorPos X="9" Y="266"/>
<TopLine Value="263"/>
<CursorPos X="7" Y="296"/>
<TopLine Value="275"/>
<EditorIndex Value="1"/>
<UsageCount Value="13"/>
<Loaded Value="True"/>
@ -142,131 +142,139 @@
<UnitName Value="xlsxooxml"/>
<CursorPos X="1" Y="268"/>
<TopLine Value="253"/>
<EditorIndex Value="2"/>
<EditorIndex Value="3"/>
<UsageCount Value="13"/>
<Loaded Value="True"/>
</Unit13>
<Unit14>
<Filename Value="..\..\..\..\..\..\..\..\usr\local\share\fpcsrc\rtl\objpas\sysutils\sysstrh.inc"/>
<CursorPos X="10" Y="154"/>
<TopLine Value="141"/>
<EditorIndex Value="2"/>
<UsageCount Value="10"/>
<Loaded Value="True"/>
</Unit14>
</Units>
<JumpHistory Count="30" HistoryIndex="29">
<Position1>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="390" Column="26" TopLine="377"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="265" Column="28" TopLine="253"/>
</Position1>
<Position2>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="420" Column="32" TopLine="407"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="313" Column="1" TopLine="301"/>
</Position2>
<Position3>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="421" Column="14" TopLine="408"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="41" Column="45" TopLine="37"/>
</Position3>
<Position4>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="460" Column="33" TopLine="440"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="355" Column="5" TopLine="331"/>
</Position4>
<Position5>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="181" Column="91" TopLine="160"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="311" Column="1" TopLine="299"/>
</Position5>
<Position6>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="769" Column="83" TopLine="754"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="260" Column="28" TopLine="249"/>
</Position6>
<Position7>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="102" Column="15" TopLine="89"/>
<Caret Line="365" Column="5" TopLine="340"/>
</Position7>
<Position8>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="103" Column="15" TopLine="90"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="290" Column="5" TopLine="265"/>
</Position8>
<Position9>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="404" Column="5" TopLine="379"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="380" Column="74" TopLine="363"/>
</Position9>
<Position10>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="187" Column="1" TopLine="172"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="278" Column="1" TopLine="265"/>
</Position10>
<Position11>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="380" Column="17" TopLine="362"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="279" Column="1" TopLine="266"/>
</Position11>
<Position12>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="412" Column="1" TopLine="404"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="283" Column="1" TopLine="270"/>
</Position12>
<Position13>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="716" Column="1" TopLine="702"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="284" Column="1" TopLine="271"/>
</Position13>
<Position14>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="167" Column="17" TopLine="154"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="287" Column="1" TopLine="274"/>
</Position14>
<Position15>
<Filename Value="..\..\xlsbiff2.pas"/>
<Caret Line="69" Column="1" TopLine="57"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="289" Column="1" TopLine="276"/>
</Position15>
<Position16>
<Filename Value="opendocwrite.lpr"/>
<Caret Line="71" Column="1" TopLine="46"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="290" Column="18" TopLine="277"/>
</Position16>
<Position17>
<Filename Value="..\..\xlsxooxml.pas"/>
<Caret Line="48" Column="16" TopLine="35"/>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="289" Column="1" TopLine="276"/>
</Position17>
<Position18>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="105" Column="1" TopLine="80"/>
<Caret Line="290" Column="1" TopLine="277"/>
</Position18>
<Position19>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="111" Column="1" TopLine="86"/>
<Caret Line="289" Column="1" TopLine="276"/>
</Position19>
<Position20>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="386" Column="1" TopLine="377"/>
<Caret Line="290" Column="1" TopLine="277"/>
</Position20>
<Position21>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="357" Column="1" TopLine="350"/>
<Caret Line="289" Column="1" TopLine="276"/>
</Position21>
<Position22>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="304" Column="3" TopLine="294"/>
<Caret Line="290" Column="1" TopLine="277"/>
</Position22>
<Position23>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="265" Column="28" TopLine="253"/>
<Caret Line="293" Column="1" TopLine="280"/>
</Position23>
<Position24>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="313" Column="1" TopLine="301"/>
<Caret Line="295" Column="1" TopLine="282"/>
</Position24>
<Position25>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="41" Column="45" TopLine="37"/>
<Caret Line="297" Column="1" TopLine="284"/>
</Position25>
<Position26>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="355" Column="5" TopLine="331"/>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="754" Column="1" TopLine="741"/>
</Position26>
<Position27>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="311" Column="1" TopLine="299"/>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="755" Column="1" TopLine="742"/>
</Position27>
<Position28>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="260" Column="28" TopLine="249"/>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="757" Column="1" TopLine="744"/>
</Position28>
<Position29>
<Filename Value="..\..\fpspreadsheet.pas"/>
<Caret Line="365" Column="5" TopLine="340"/>
<Caret Line="759" Column="1" TopLine="746"/>
</Position29>
<Position30>
<Filename Value="..\..\fpsopendocument.pas"/>
<Caret Line="290" Column="5" TopLine="265"/>
<Caret Line="392" Column="1" TopLine="379"/>
</Position30>
</JumpHistory>
</ProjectOptions>

View File

@ -0,0 +1 @@
unzip oocreated.ods

View File

@ -0,0 +1,4 @@
cd test
zip test.ods *
mv test.ods ../
cd ..

View File

@ -72,8 +72,8 @@ const
OOXML_PATH_SETTINGS = 'settings.xml';
OOXML_PATH_STYLES = 'styles.xml';
OOXML_PATH_MIMETYPE = 'mimetype.xml';
OPENDOC_PATH_METAINF = 'META-INF\';
OPENDOC_PATH_METAINF_MANIFEST = 'META-INF\manifest.xml';
OPENDOC_PATH_METAINF = 'META-INF' + PathDelim;
OPENDOC_PATH_METAINF_MANIFEST = 'META-INF' + PathDelim + 'manifest.xml';
{ OpenDocument schemas constants }
SCHEMAS_XMLNS_OFFICE = 'urn:oasis:names:tc:opendocument:xmlns:office:1.0';
@ -261,30 +261,54 @@ procedure TsSpreadOpenDocWriter.WriteWorksheet(CurSheet: TsWorksheet);
var
j, k: Integer;
CurCell: PCell;
CurRow: array of PCell;
LastColNum: Cardinal;
begin
LastColNum := CurSheet.GetLastColNumber;
// Header
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;
IntToStr(LastColNum) + '" table:default-cell-style-name="Default"/>' + LineEnding;
// The cells need to be written in order, row by row
for j := 0 to CurSheet.GetLastRowNumber do
// The cells need to be written in order, row by row, cell by cell
for j := 1 to CurSheet.GetLastRowNumber do
begin
FContent := FContent +
' <table:table-row table:style-name="ro1">' + LineEnding;
// First make an array with the cells of this row in their respective order
// nil pointers indicate empty cells, so it's necessary to initialize the array
SetLength(CurRow, LastColNum);
for k := 0 to LastColNum - 1 do CurRow[k] := nil;
// Now fill the array with the cells in their proper place
for k := 0 to CurSheet.FCells.Count - 1 do
begin
CurCell := CurSheet.FCells.Items[k];
if CurCell^.Row = j then WriteCellCallback(CurCell, nil);
if CurCell^.Row = j then CurRow[CurCell^.Col - 1] := CurCell;
end;
FContent := FContent + ' </table:table-row>' + LineEnding;
for k := 0 to LastColNum - 1 do
begin
CurCell := CurRow[k];
if CurCell = nil then
FContent := FContent + '<table:table-cell/>' + LineEnding
else WriteCellCallback(CurCell, nil);
end;
FContent := FContent +
' </table:table-row>' + LineEnding;
end;
// Clean up
SetLength(CurRow, 0);
// Footer
FContent := FContent + ' </table:table>' + LineEnding;
FContent := FContent +
' </table:table>' + LineEnding;
end;
{*******************************************************************
@ -346,15 +370,6 @@ begin
WriteStringToFile(TempDir + OPENDOC_PATH_METAINF_MANIFEST, FMetaInfManifest);
end;
{*******************************************************************
* TsSpreadOOXMLWriter.WriteToStream ()
*
* DESCRIPTION: Writes an Excel 2 file to a stream
*
* Excel 2.x files support only one Worksheet per Workbook,
* so only the first will be written.
*
*******************************************************************}
procedure TsSpreadOpenDocWriter.WriteToStream(AStream: TStream; AData: TsWorkbook);
begin
@ -377,8 +392,8 @@ procedure TsSpreadOpenDocWriter.WriteNumber(AStream: TStream; const ARow,
begin
// The row should already be the correct one
FContent := FContent +
' <table:table-cell office:value-type="float" office:value="' + IntToStr(ACol + 1) + '">' + LineEnding +
' <text:p>1</text:p>' + LineEnding +
' <table:table-cell office:value-type="float" office:value="' + FloatToStr(AValue) + '">' + LineEnding +
' <text:p>' + FloatToStr(AValue) + '</text:p>' + LineEnding +
' </table:table-cell>' + LineEnding;
end;