You've already forked lazarus-ccr
fpspreadsheet: Beginning to read number formatting styles from ods file (so far, just populating the number format list)
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3098 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -1,4 +1,4 @@
|
|||||||
<?xml version="1.0"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<CONFIG>
|
<CONFIG>
|
||||||
<ProjectOptions>
|
<ProjectOptions>
|
||||||
<Version Value="9"/>
|
<Version Value="9"/>
|
||||||
@ -44,7 +44,7 @@
|
|||||||
</Units>
|
</Units>
|
||||||
</ProjectOptions>
|
</ProjectOptions>
|
||||||
<CompilerOptions>
|
<CompilerOptions>
|
||||||
<Version Value="9"/>
|
<Version Value="11"/>
|
||||||
<PathDelim Value="\"/>
|
<PathDelim Value="\"/>
|
||||||
<SearchPaths>
|
<SearchPaths>
|
||||||
<OtherUnitFiles Value=".."/>
|
<OtherUnitFiles Value=".."/>
|
||||||
|
@ -58,6 +58,7 @@ type
|
|||||||
|
|
||||||
TsSpreadOpenDocReader = class(TsCustomSpreadReader)
|
TsSpreadOpenDocReader = class(TsCustomSpreadReader)
|
||||||
private
|
private
|
||||||
|
FDoc : TXMLDocument;
|
||||||
FDateMode: TDateMode;
|
FDateMode: TDateMode;
|
||||||
FWorksheet: TsWorksheet;
|
FWorksheet: TsWorksheet;
|
||||||
// Gets value for the specified attribute. Returns empty string if attribute
|
// Gets value for the specified attribute. Returns empty string if attribute
|
||||||
@ -67,6 +68,7 @@ type
|
|||||||
procedure ReadDateMode(SpreadSheetNode: TDOMNode);
|
procedure ReadDateMode(SpreadSheetNode: TDOMNode);
|
||||||
protected
|
protected
|
||||||
procedure CreateNumFormatList; override;
|
procedure CreateNumFormatList; override;
|
||||||
|
procedure ReadAutomaticStyles;
|
||||||
{ Record writing methods }
|
{ Record writing methods }
|
||||||
procedure ReadFormula(ARow : Word; ACol : Word; ACellNode: TDOMNode);
|
procedure ReadFormula(ARow : Word; ACol : Word; ACellNode: TDOMNode);
|
||||||
procedure ReadLabel(ARow : Word; ACol : Word; ACellNode: TDOMNode);
|
procedure ReadLabel(ARow : Word; ACol : Word; ACellNode: TDOMNode);
|
||||||
@ -122,6 +124,9 @@ type
|
|||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
|
uses
|
||||||
|
StrUtils;
|
||||||
|
|
||||||
const
|
const
|
||||||
{ OpenDocument general XML constants }
|
{ OpenDocument general XML constants }
|
||||||
XML_HEADER = '<?xml version="1.0" encoding="utf-8" ?>';
|
XML_HEADER = '<?xml version="1.0" encoding="utf-8" ?>';
|
||||||
@ -174,7 +179,7 @@ const
|
|||||||
|
|
||||||
procedure TsSpreadOpenDocNumFormatList.AddBuiltinFormats;
|
procedure TsSpreadOpenDocNumFormatList.AddBuiltinFormats;
|
||||||
begin
|
begin
|
||||||
// to be filled later...
|
// there are no built-in number formats which are silently assumed to exist.
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TsSpreadOpenDocReader }
|
{ TsSpreadOpenDocReader }
|
||||||
@ -234,7 +239,6 @@ var
|
|||||||
FilePath : string;
|
FilePath : string;
|
||||||
UnZip : TUnZipper;
|
UnZip : TUnZipper;
|
||||||
FileList : TStringList;
|
FileList : TStringList;
|
||||||
Doc : TXMLDocument;
|
|
||||||
BodyNode, SpreadSheetNode, TableNode, RowNode, CellNode : TDOMNode;
|
BodyNode, SpreadSheetNode, TableNode, RowNode, CellNode : TDOMNode;
|
||||||
ParamRowsRepeated, ParamColsRepeated, ParamValueType, ParamFormula : string;
|
ParamRowsRepeated, ParamColsRepeated, ParamValueType, ParamFormula : string;
|
||||||
RowsCount, ColsCount : integer;
|
RowsCount, ColsCount : integer;
|
||||||
@ -252,13 +256,15 @@ begin
|
|||||||
FreeAndNil(UnZip);
|
FreeAndNil(UnZip);
|
||||||
end; //try
|
end; //try
|
||||||
|
|
||||||
Doc:=nil;
|
FDoc := nil;
|
||||||
try
|
try
|
||||||
//process the xml file
|
//process the xml file
|
||||||
ReadXMLFile(Doc,FilePath+'content.xml');
|
ReadXMLFile(FDoc, FilePath+'content.xml');
|
||||||
DeleteFile(FilePath+'content.xml');
|
DeleteFile(FilePath+'content.xml');
|
||||||
|
|
||||||
BodyNode:= Doc.DocumentElement.FindNode('office:body');
|
ReadAutomaticStyles;
|
||||||
|
|
||||||
|
BodyNode := FDoc.DocumentElement.FindNode('office:body');
|
||||||
if not Assigned(BodyNode) then Exit;
|
if not Assigned(BodyNode) then Exit;
|
||||||
|
|
||||||
SpreadSheetNode:=BodyNode.FindNode('office:spreadsheet');
|
SpreadSheetNode:=BodyNode.FindNode('office:spreadsheet');
|
||||||
@ -323,7 +329,7 @@ begin
|
|||||||
TableNode:=TableNode.NextSibling;
|
TableNode:=TableNode.NextSibling;
|
||||||
end; //while Assigned(TableNode)
|
end; //while Assigned(TableNode)
|
||||||
finally
|
finally
|
||||||
Doc.Free;
|
FDoc.Free;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -466,6 +472,56 @@ begin
|
|||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
procedure TsSpreadOpenDocReader.ReadAutomaticStyles;
|
||||||
|
var
|
||||||
|
StylesNode, NumFormatNode, node: TDOMNode;
|
||||||
|
decs: Integer;
|
||||||
|
fmtName: String;
|
||||||
|
grouping: boolean;
|
||||||
|
fmt: String;
|
||||||
|
nf: TsNumberFormat;
|
||||||
|
nex: Integer;
|
||||||
|
begin
|
||||||
|
StylesNode := FDoc.DocumentElement.FindNode('office:automatic-styles');
|
||||||
|
if not Assigned(StylesNode) then Exit;
|
||||||
|
|
||||||
|
NumFormatNode := StylesNode.FirstChild;
|
||||||
|
while Assigned(NumFormatNode) do begin
|
||||||
|
if NumFormatNode.NodeName = 'number:number-style' then begin
|
||||||
|
fmtName := GetAttrValue(NumFormatNode, 'style:name');
|
||||||
|
node := NumFormatNode.FindNode('number:number');
|
||||||
|
if node <> nil then begin
|
||||||
|
decs := StrToInt(GetAttrValue(node, 'number:decimal-places'));
|
||||||
|
grouping := GetAttrValue(node, 'grouping') = 'true';
|
||||||
|
nf := IfThen(grouping, nfFixedTh, nfFixed);
|
||||||
|
fmt := BuildNumberFormatString(nf, Workbook.FormatSettings, decs);
|
||||||
|
NumFormatList.AddFormat(fmt, nf, decs);
|
||||||
|
end;
|
||||||
|
node := NumFormatNode.FindNode('number:scientific-number');
|
||||||
|
if node <> nil then begin
|
||||||
|
nf := nfExp;
|
||||||
|
decs := StrToInt(GetAttrValue(node, 'number:decimal-places'));
|
||||||
|
nex := StrToInt(GetAttrValue(node, 'number:min-exponent-digits'));
|
||||||
|
fmt := BuildNumberFormatString(nfFixed, Workbook.FormatSettings, decs);
|
||||||
|
fmt := fmt + 'E+' + DupeString('0', nex);
|
||||||
|
NumFormatList.AddFormat(fmt, nf, decs);
|
||||||
|
end;
|
||||||
|
end else
|
||||||
|
if NumFormatNode.NodeName = 'number:percentage-style' then begin
|
||||||
|
fmtName := GetAttrValue(NumFormatNode, 'style:name');
|
||||||
|
node := NumFormatNode.FindNode('number:number');
|
||||||
|
if node <> nil then begin
|
||||||
|
nf := nfPercentage;
|
||||||
|
decs := StrToInt(GetAttrValue(node, 'number:decimal-places'));
|
||||||
|
fmt := BuildNumberFormatString(nf, Workbook.FormatSettings, decs);
|
||||||
|
NumFormatList.AddFormat(fmt, nf, decs);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
NumFormatNode := NumFormatNode.NextSibling;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
{ TsSpreadOpenDocWriter }
|
{ TsSpreadOpenDocWriter }
|
||||||
|
|
||||||
procedure TsSpreadOpenDocWriter.CreateNumFormatList;
|
procedure TsSpreadOpenDocWriter.CreateNumFormatList;
|
||||||
|
Reference in New Issue
Block a user