You've already forked lazarus-ccr
fpspreadsheet: Implement reading of cell comments from opendocument files. Fix cell text with manual line break in opendocument files.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@3913 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -130,10 +130,12 @@ begin
|
|||||||
MyWorksheet.WriteUTF8Text(7, 3, 'This is 16pt red bold & italic Times New Roman.');
|
MyWorksheet.WriteUTF8Text(7, 3, 'This is 16pt red bold & italic Times New Roman.');
|
||||||
Myworksheet.WriteFont(7, 3, 'Times New Roman', 16, [fssBold, fssItalic], scRed);
|
Myworksheet.WriteFont(7, 3, 'Times New Roman', 16, [fssBold, fssItalic], scRed);
|
||||||
|
|
||||||
// Cell with changed font and background in D9
|
// Cell with changed font and background in D9 and comment
|
||||||
MyWorksheet.WriteUTF8Text(8, 3, 'Colors...');
|
MyWorksheet.WriteUTF8Text(8, 3, 'Colors...');
|
||||||
MyWorksheet.WriteFont(8, 3, 'Courier New', 12, [fssUnderline], scBlue);
|
MyWorksheet.WriteFont(8, 3, 'Courier New', 12, [fssUnderline], scBlue);
|
||||||
MyWorksheet.WriteBackgroundColor(8, 3, scYellow);
|
MyWorksheet.WriteBackgroundColor(8, 3, scYellow);
|
||||||
|
// MyWorksheet.WriteComment(8, 3, 'This is font "Courier New", Size 12.');
|
||||||
|
|
||||||
{}
|
{}
|
||||||
{
|
{
|
||||||
// Uncomment this to test large XLS files
|
// Uncomment this to test large XLS files
|
||||||
|
@@ -83,20 +83,12 @@ type
|
|||||||
// Applies internally stored column widths to current worksheet
|
// Applies internally stored column widths to current worksheet
|
||||||
procedure ApplyColWidths;
|
procedure ApplyColWidths;
|
||||||
// Applies a style to a cell
|
// Applies a style to a cell
|
||||||
{
|
function ApplyStyleToCell(ACell: PCell; AStyleName: String): Boolean;
|
||||||
function ApplyStyleToCell(ARow, ACol: Cardinal;
|
|
||||||
AStyleName: String): Boolean; overload; }
|
|
||||||
function ApplyStyleToCell(ACell: PCell;
|
|
||||||
AStyleName: String): Boolean; //overload;
|
|
||||||
// Extracts a boolean value from the xml node
|
// Extracts a boolean value from the xml node
|
||||||
function ExtractBoolFromNode(ANode: TDOMNode): Boolean;
|
function ExtractBoolFromNode(ANode: TDOMNode): Boolean;
|
||||||
// Extracts the date/time value from the xml node
|
// Extracts the date/time value from the xml node
|
||||||
function ExtractDateTimeFromNode(ANode: TDOMNode;
|
function ExtractDateTimeFromNode(ANode: TDOMNode;
|
||||||
ANumFormat: TsNumberFormat; const AFormatStr: String): TDateTime;
|
ANumFormat: TsNumberFormat; const AFormatStr: String): TDateTime;
|
||||||
{
|
|
||||||
// Searches a style by its name in the CellStyleList
|
|
||||||
function FindCellStyleByName(AStyleName: String): integer;
|
|
||||||
}
|
|
||||||
// Searches a column style by its column index or its name in the StyleList
|
// Searches a column style by its column index or its name in the StyleList
|
||||||
function FindColumnByCol(AColIndex: Integer): Integer;
|
function FindColumnByCol(AColIndex: Integer): Integer;
|
||||||
function FindColStyleByName(AStyleName: String): integer;
|
function FindColStyleByName(AStyleName: String): integer;
|
||||||
@@ -118,6 +110,7 @@ type
|
|||||||
{ Record writing methods }
|
{ Record writing methods }
|
||||||
procedure ReadBlank(ARow, ACol: Word; ACellNode: TDOMNode); reintroduce;
|
procedure ReadBlank(ARow, ACol: Word; ACellNode: TDOMNode); reintroduce;
|
||||||
procedure ReadBoolean(ARow, ACol: Word; ACellNode: TDOMNode);
|
procedure ReadBoolean(ARow, ACol: Word; ACellNode: TDOMNode);
|
||||||
|
procedure ReadComment(ARow, ACol: Word; ACellNode: TDOMNode);
|
||||||
procedure ReadDateTime(ARow, ACol: Word; ACellNode: TDOMNode);
|
procedure ReadDateTime(ARow, ACol: Word; ACellNode: TDOMNode);
|
||||||
procedure ReadFormula(ARow, ACol: Word; ACellNode: TDOMNode); reintroduce;
|
procedure ReadFormula(ARow, ACol: Word; ACellNode: TDOMNode); reintroduce;
|
||||||
procedure ReadLabel(ARow, ACol: Word; ACellNode: TDOMNode); reintroduce;
|
procedure ReadLabel(ARow, ACol: Word; ACellNode: TDOMNode); reintroduce;
|
||||||
@@ -765,9 +758,7 @@ end;
|
|||||||
function TsSpreadOpenDocReader.ApplyStyleToCell(ACell: PCell; AStyleName: String): Boolean;
|
function TsSpreadOpenDocReader.ApplyStyleToCell(ACell: PCell; AStyleName: String): Boolean;
|
||||||
var
|
var
|
||||||
fmt: PsCellFormat;
|
fmt: PsCellFormat;
|
||||||
// styleData: TCellStyleData;
|
|
||||||
styleIndex: Integer;
|
styleIndex: Integer;
|
||||||
// numFmtData: TsNumFormatData;
|
|
||||||
i: Integer;
|
i: Integer;
|
||||||
begin
|
begin
|
||||||
Result := false;
|
Result := false;
|
||||||
@@ -1075,7 +1066,55 @@ begin
|
|||||||
FColumnStyleList.Add(colStyle);
|
FColumnStyleList.Add(colStyle);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadOpenDocReader.ReadDateTime(ARow: Word; ACol: Word;
|
procedure TsSpreadOpenDocReader.ReadComment(ARow, ACol: Word;
|
||||||
|
ACellNode: TDOMNode);
|
||||||
|
var
|
||||||
|
cellChildNode, pNode, spanNode: TDOMNode;
|
||||||
|
comment: String;
|
||||||
|
nodeName: String;
|
||||||
|
s: String;
|
||||||
|
found: Boolean;
|
||||||
|
begin
|
||||||
|
if ACellNode = nil then
|
||||||
|
exit;
|
||||||
|
|
||||||
|
comment := '';
|
||||||
|
found := false;
|
||||||
|
|
||||||
|
cellChildNode := ACellNode.FirstChild;
|
||||||
|
while cellChildNode <> nil do begin
|
||||||
|
nodeName := cellChildNode.NodeName;
|
||||||
|
if nodeName = 'office:annotation' then begin
|
||||||
|
pNode := cellChildNode.FirstChild;
|
||||||
|
while pNode <> nil do begin
|
||||||
|
nodeName := pNode.NodeName;
|
||||||
|
if nodeName = 'text:p' then
|
||||||
|
begin
|
||||||
|
s := GetNodeValue(pNode);
|
||||||
|
if comment = '' then comment := s else comment := comment + LineEnding + s;
|
||||||
|
found := true;
|
||||||
|
spanNode := pNode.FirstChild;
|
||||||
|
while spanNode <> nil do begin
|
||||||
|
nodeName := spanNode.NodeName;
|
||||||
|
if nodeName = 'text:span' then
|
||||||
|
begin
|
||||||
|
s := GetNodeValue(spanNode);
|
||||||
|
if comment = '' then comment := s else comment := comment + ' ' + s;
|
||||||
|
found := true;
|
||||||
|
end;
|
||||||
|
spanNode := spanNode.NextSibling;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
pNode := pNode.NextSibling;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
cellChildNode := cellChildNode.NextSibling;
|
||||||
|
end;
|
||||||
|
if found then
|
||||||
|
FWorksheet.WriteComment(ARow, ACol, comment);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TsSpreadOpenDocReader.ReadDateTime(ARow, ACol: Word;
|
||||||
ACellNode : TDOMNode);
|
ACellNode : TDOMNode);
|
||||||
var
|
var
|
||||||
dt: TDateTime;
|
dt: TDateTime;
|
||||||
@@ -1402,9 +1441,11 @@ var
|
|||||||
cellText: String;
|
cellText: String;
|
||||||
styleName: String;
|
styleName: String;
|
||||||
childnode: TDOMNode;
|
childnode: TDOMNode;
|
||||||
|
spanNode: TDOMNode;
|
||||||
|
nodeName: String;
|
||||||
|
s: String;
|
||||||
cell: PCell;
|
cell: PCell;
|
||||||
begin
|
begin
|
||||||
// cellText := ACellNode.TextContent;
|
|
||||||
{ We were forced to activate PreserveWhiteSpace in the DOMParser in order to
|
{ We were forced to activate PreserveWhiteSpace in the DOMParser in order to
|
||||||
catch the spaces inserted in formatting texts. However, this adds lots of
|
catch the spaces inserted in formatting texts. However, this adds lots of
|
||||||
garbage into the cellText if is is read by means of above statement. Done
|
garbage into the cellText if is is read by means of above statement. Done
|
||||||
@@ -1413,11 +1454,31 @@ begin
|
|||||||
childnode := ACellNode.FirstChild;
|
childnode := ACellNode.FirstChild;
|
||||||
while Assigned(childnode) do
|
while Assigned(childnode) do
|
||||||
begin
|
begin
|
||||||
|
nodeName := childNode.NodeName;
|
||||||
|
if nodeName = 'text:p' then begin
|
||||||
|
s := childNode.TextContent;
|
||||||
|
if s <> '' then
|
||||||
|
begin
|
||||||
|
if cellText = '' then cellText := s else cellText := cellText + LineEnding + s;
|
||||||
|
end;
|
||||||
|
spanNode := childNode.FirstChild;
|
||||||
|
while spanNode <> nil do begin
|
||||||
|
nodeName := spanNode.NodeName;
|
||||||
|
if nodeName = 'text:span' then
|
||||||
|
begin
|
||||||
|
s := spanNode.TextContent;
|
||||||
|
if cellText = '' then cellText := s else cellText := cellText + ' ' + s;
|
||||||
|
end;
|
||||||
|
spanNode := spanNode.NextSibling;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
{
|
||||||
case childnode.NodeType of
|
case childnode.NodeType of
|
||||||
TEXT_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE: ; // ignored
|
TEXT_NODE, COMMENT_NODE, PROCESSING_INSTRUCTION_NODE: ; // ignored
|
||||||
else
|
else
|
||||||
cellText := cellText + childnode.TextContent;
|
cellText := cellText + childnode.TextContent;
|
||||||
end;
|
end;
|
||||||
|
}
|
||||||
childnode := childnode.NextSibling;
|
childnode := childnode.NextSibling;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -1936,6 +1997,9 @@ begin
|
|||||||
if ParamFormula <> '' then
|
if ParamFormula <> '' then
|
||||||
ReadFormula(row, col, cellNode);
|
ReadFormula(row, col, cellNode);
|
||||||
|
|
||||||
|
// Read cell comment
|
||||||
|
ReadComment(row, col, cellNode);
|
||||||
|
|
||||||
paramColsSpanned := GetAttrValue(cellNode, 'table:number-columns-spanned');
|
paramColsSpanned := GetAttrValue(cellNode, 'table:number-columns-spanned');
|
||||||
if paramColsSpanned <> '' then
|
if paramColsSpanned <> '' then
|
||||||
colsSpanned := StrToInt(paramColsSpanned) - 1
|
colsSpanned := StrToInt(paramColsSpanned) - 1
|
||||||
@@ -2133,7 +2197,6 @@ end;
|
|||||||
|
|
||||||
procedure TsSpreadOpenDocReader.ReadStyles(AStylesNode: TDOMNode);
|
procedure TsSpreadOpenDocReader.ReadStyles(AStylesNode: TDOMNode);
|
||||||
var
|
var
|
||||||
// style: TCellStyleData;
|
|
||||||
styleNode: TDOMNode;
|
styleNode: TDOMNode;
|
||||||
styleChildNode: TDOMNode;
|
styleChildNode: TDOMNode;
|
||||||
nodeName: String;
|
nodeName: String;
|
||||||
@@ -3163,7 +3226,6 @@ begin
|
|||||||
|
|
||||||
// Next row
|
// Next row
|
||||||
inc(r, rowsRepeated);
|
inc(r, rowsRepeated);
|
||||||
// rowsRepeated := 1;
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@@ -1511,7 +1511,7 @@ end;
|
|||||||
-------------------------------------------------------------------------------}
|
-------------------------------------------------------------------------------}
|
||||||
procedure TscustomWorksheetGrid.DrawCommentMarker(ARect: TRect);
|
procedure TscustomWorksheetGrid.DrawCommentMarker(ARect: TRect);
|
||||||
const
|
const
|
||||||
COMMENT_SIZE = 6;
|
COMMENT_SIZE = 8;
|
||||||
var
|
var
|
||||||
P: Array[0..3] of TPoint;
|
P: Array[0..3] of TPoint;
|
||||||
begin
|
begin
|
||||||
|
@@ -104,6 +104,7 @@
|
|||||||
<Unit14>
|
<Unit14>
|
||||||
<Filename Value="emptycelltests.pas"/>
|
<Filename Value="emptycelltests.pas"/>
|
||||||
<IsPartOfProject Value="True"/>
|
<IsPartOfProject Value="True"/>
|
||||||
|
<UnitName Value="emptycelltests"/>
|
||||||
</Unit14>
|
</Unit14>
|
||||||
<Unit15>
|
<Unit15>
|
||||||
<Filename Value="errortests.pas"/>
|
<Filename Value="errortests.pas"/>
|
||||||
|
Reference in New Issue
Block a user