You've already forked lazarus-ccr
fpspreadsheet: Add merged cell support to ExcelXML writer.
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4343 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -19,6 +19,11 @@ type
|
|||||||
private
|
private
|
||||||
FDateMode: TDateMode;
|
FDateMode: TDateMode;
|
||||||
FPointSeparatorSettings: TFormatSettings;
|
FPointSeparatorSettings: TFormatSettings;
|
||||||
|
function GetCommentStr(ACell: PCell): String;
|
||||||
|
function GetHyperlinkStr(ACell: PCell): String;
|
||||||
|
function GetIndexStr(AIndex: Integer): String;
|
||||||
|
function GetMergeStr(ACell: PCell): String;
|
||||||
|
function GetStyleStr(ACell: PCell): String;
|
||||||
procedure WriteCells(AStream: TStream; AWorksheet: TsWorksheet);
|
procedure WriteCells(AStream: TStream; AWorksheet: TsWorksheet);
|
||||||
procedure WriteStyle(AStream: TStream; AIndex: Integer);
|
procedure WriteStyle(AStream: TStream; AIndex: Integer);
|
||||||
procedure WriteStyles(AStream: TStream);
|
procedure WriteStyles(AStream: TStream);
|
||||||
@@ -65,15 +70,51 @@ uses
|
|||||||
const
|
const
|
||||||
FMT_OFFSET = 61;
|
FMT_OFFSET = 61;
|
||||||
|
|
||||||
|
const
|
||||||
|
{ TsFillStyle = (
|
||||||
|
fsNoFill, fsSolidFill,
|
||||||
|
fsGray75, fsGray50, fsGray25, fsGray12, fsGray6,
|
||||||
|
fsStripeHor, fsStripeVert, fsStripeDiagUp, fsStripeDiagDown,
|
||||||
|
fsThinStripeHor, fsThinStripeVert, fsThinStripeDiagUp, fsThinStripeDiagDown,
|
||||||
|
fsHatchDiag, fsThinHatchDiag, fsThickHatchDiag, fsThinHatchHor) }
|
||||||
|
FILL_NAMES: array[TsFillStyle] of string = (
|
||||||
|
'', 'Solid',
|
||||||
|
'Gray75', 'Gray50', 'Gray25', 'Gray12', 'Gray0625',
|
||||||
|
'HorzStripe', 'VertStripe', 'DiagStripe', 'ReverseDiagStripe',
|
||||||
|
'ThinHorzStripe', 'ThinVertStripe', 'ThinDiagStripe', 'ThinReverseDiagStripe',
|
||||||
|
'DiagCross', 'ThinDiagCross', 'ThickDiagCross', 'ThinHorzCross'
|
||||||
|
);
|
||||||
|
|
||||||
|
{TsCellBorder = (cbNorth, cbWest, cbEast, cbSouth, cbDiagUp, cbDiagDown); }
|
||||||
|
BORDER_NAMES: array[TsCellBorder] of string = (
|
||||||
|
'Top', 'Left', 'Right', 'Bottom', 'DiagonalRight', 'DiagonalLeft'
|
||||||
|
);
|
||||||
|
|
||||||
|
{ TsLineStyle = (
|
||||||
|
lsThin, lsMedium, lsDashed, lsDotted, lsThick, lsDouble, lsHair,
|
||||||
|
lsMediumDash, lsDashDot, lsMediumDashDot, lsDashDotDot, lsMediumDashDotDot,
|
||||||
|
lsSlantDashDot) }
|
||||||
|
LINE_STYLES: array[TsLineStyle] of string = (
|
||||||
|
'Continuous', 'Continuous', 'Dash', 'Dot', 'Continuous', 'Double', 'Continuous',
|
||||||
|
'Dash', 'DashDot', 'DashDot', 'DashDotDot', 'DashDotDot',
|
||||||
|
'SlantDashDot'
|
||||||
|
);
|
||||||
|
LINE_WIDTHS: array[TsLineStyle] of Integer = (
|
||||||
|
1, 2, 1, 1, 3, 3, 0,
|
||||||
|
2, 1, 2, 1, 2,
|
||||||
|
2
|
||||||
|
);
|
||||||
|
|
||||||
function GetCellContentTypeStr(ACell: PCell): String;
|
function GetCellContentTypeStr(ACell: PCell): String;
|
||||||
begin
|
begin
|
||||||
case ACell^.ContentType of
|
case ACell^.ContentType of
|
||||||
cctNumber : Result := 'Number';
|
cctNumber : Result := 'Number';
|
||||||
cctUTF8String: Result := 'String';
|
cctUTF8String : Result := 'String';
|
||||||
cctDateTime : Result := 'DateTime';
|
cctDateTime : Result := 'DateTime';
|
||||||
cctBool : Result := 'Boolean';
|
cctBool : Result := 'Boolean';
|
||||||
cctError : Result := 'Error';
|
cctError : Result := 'Error';
|
||||||
else raise Exception.Create('Content type error in cell ' + GetCellString(ACell^.Row, ACell^.Col));
|
else
|
||||||
|
raise Exception.Create('Content type error in cell ' + GetCellString(ACell^.Row, ACell^.Col));
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -100,43 +141,64 @@ begin
|
|||||||
FLimitations.MaxRowCount := 65536;
|
FLimitations.MaxRowCount := 65536;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadExcelXMLWriter.WriteBlank(AStream: TStream;
|
function TsSpreadExcelXMLWriter.GetCommentStr(ACell: PCell): String;
|
||||||
const ARow, ACol: Cardinal; ACell: PCell);
|
|
||||||
var
|
var
|
||||||
styleStr: String;
|
|
||||||
hyperlink: PsHyperlink;
|
|
||||||
hyperlinkStr: String;
|
|
||||||
comment: PsComment;
|
comment: PsComment;
|
||||||
commentStr: String;
|
|
||||||
begin
|
begin
|
||||||
if ACell^.FormatIndex > 0 then
|
Result := '';
|
||||||
styleStr := Format(' ss:StyleID="s%d"', [ACell^.FormatIndex + FMT_OFFSET]) else
|
|
||||||
styleStr := '';
|
|
||||||
|
|
||||||
hyperlink := FWorksheet.FindHyperlink(ACell);
|
|
||||||
if Assigned(hyperlink) then
|
|
||||||
hyperlinkStr := ' ss:HRef="' + hyperlink^.Target + '"' else
|
|
||||||
hyperlinkStr := '';
|
|
||||||
|
|
||||||
comment := FWorksheet.FindComment(ACell);
|
comment := FWorksheet.FindComment(ACell);
|
||||||
if Assigned(comment) then
|
if Assigned(comment) then
|
||||||
// commentStr := '<Comment><ss:Data xmlns="http://www.w3.org/TR/REC-html40">'+comment^.Text+'</ss:Data></Comment>' else
|
Result := '<Comment><Data>' + comment^.Text + '</Data></Comment>';
|
||||||
commentStr := '<Comment><Data>'+comment^.Text+'</Data></Comment>' else
|
// If there will be some rich-text-like formatting in the future, use
|
||||||
commentStr := '';
|
// Result := '<Comment><ss:Data xmlns="http://www.w3.org/TR/REC-html40">'+comment^.Text+'</ss:Data></Comment>':
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TsSpreadExcelXMLWriter.GetHyperlinkStr(ACell: PCell): String;
|
||||||
|
var
|
||||||
|
hyperlink: PsHyperlink;
|
||||||
|
begin
|
||||||
|
Result := '';
|
||||||
|
hyperlink := FWorksheet.FindHyperlink(ACell);
|
||||||
|
if Assigned(hyperlink) then
|
||||||
|
Result := ' ss:HRef="' + hyperlink^.Target + '"';
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TsSpreadExcelXMLWriter.GetIndexStr(AIndex: Integer): String;
|
||||||
|
begin
|
||||||
|
Result := Format(' ss:Index="%d"', [AIndex]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TsSpreadExcelXMLWriter.GetMergeStr(ACell: PCell): String;
|
||||||
|
var
|
||||||
|
r1, c1, r2, c2: Cardinal;
|
||||||
|
begin
|
||||||
|
Result := '';
|
||||||
|
if FWorksheet.IsMerged(ACell) then begin
|
||||||
|
FWorksheet.FindMergedRange(ACell, r1, c1, r2, c2);
|
||||||
|
if c2 > c1 then
|
||||||
|
Result := Result + Format(' ss:MergeAcross="%d"', [c2-c1]);
|
||||||
|
if r2 > r1 then
|
||||||
|
Result := Result + Format(' ss:MergeDown="%d"', [r2-r1]);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function TsSpreadExcelXMLWriter.GetStyleStr(ACell: PCell): String;
|
||||||
|
begin
|
||||||
|
Result := '';
|
||||||
|
if ACell^.FormatIndex > 0 then
|
||||||
|
Result := Format(' ss:StyleID="s%d"', [ACell^.FormatIndex + FMT_OFFSET]);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TsSpreadExcelXMLWriter.WriteBlank(AStream: TStream;
|
||||||
|
const ARow, ACol: Cardinal; ACell: PCell);
|
||||||
|
begin
|
||||||
AppendToStream(AStream, Format(
|
AppendToStream(AStream, Format(
|
||||||
' <Cell%s%s>' + // style, hyperlink
|
' <Cell%s%s%s%s>' + // colIndex, style, hyperlink, merge
|
||||||
'%s' + // Comment <Comment>...</Comment>
|
'%s' + // Comment <Comment>...</Comment>
|
||||||
'</Cell>' + LineEnding, [
|
'</Cell>' + LineEnding, [
|
||||||
styleStr, hyperlinkStr,
|
GetIndexStr(ACol+1), GetStyleStr(ACell), GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
||||||
commentStr
|
GetCommentStr(ACell)
|
||||||
]));
|
]));
|
||||||
|
|
||||||
{
|
|
||||||
AppendToStream(AStream, Format(
|
|
||||||
' <Cell%s />' + LineEnding,
|
|
||||||
[styleStr])
|
|
||||||
); }
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadExcelXMLWriter.WriteBool(AStream: TStream;
|
procedure TsSpreadExcelXMLWriter.WriteBool(AStream: TStream;
|
||||||
@@ -145,11 +207,6 @@ var
|
|||||||
valueStr: String;
|
valueStr: String;
|
||||||
formulaStr: String;
|
formulaStr: String;
|
||||||
cctStr: String;
|
cctStr: String;
|
||||||
stylestr: String;
|
|
||||||
hyperlink: PsHyperlink;
|
|
||||||
hyperlinkStr: String;
|
|
||||||
comment: PsComment;
|
|
||||||
commentStr: String;
|
|
||||||
begin
|
begin
|
||||||
valueStr := StrUtils.IfThen(AValue, '1', '0');
|
valueStr := StrUtils.IfThen(AValue, '1', '0');
|
||||||
cctStr := 'Boolean';
|
cctStr := 'Boolean';
|
||||||
@@ -159,37 +216,19 @@ begin
|
|||||||
formulaStr := Format(' ss:Formula="=%s"', [ACell^.FormulaValue]);
|
formulaStr := Format(' ss:Formula="=%s"', [ACell^.FormulaValue]);
|
||||||
cctStr := GetCellContentTypeStr(ACell);
|
cctStr := GetCellContentTypeStr(ACell);
|
||||||
end;
|
end;
|
||||||
if ACell^.FormatIndex > 0 then
|
|
||||||
styleStr := Format(' ss:StyleID="s%d"', [ACell^.FormatIndex + FMT_OFFSET]) else
|
|
||||||
styleStr := '';
|
|
||||||
|
|
||||||
hyperlink := FWorksheet.FindHyperlink(ACell);
|
|
||||||
if Assigned(hyperlink) then
|
|
||||||
hyperlinkStr := ' ss:HRef="' + hyperlink^.Target + '"' else
|
|
||||||
hyperlinkStr := '';
|
|
||||||
|
|
||||||
comment := FWorksheet.FindComment(ACell);
|
|
||||||
if Assigned(comment) then
|
|
||||||
commentStr := '<Comment><Data>'+comment^.Text+'</Data></Comment>' else
|
|
||||||
commentStr := '';
|
|
||||||
|
|
||||||
AppendToStream(AStream, Format(
|
AppendToStream(AStream, Format(
|
||||||
' <Cell%s%s%s>' + // style, formula, hyperlink
|
' <Cell%s%s%s%s%s>' + // colIndex, style, formula, hyperlink, merge
|
||||||
'<Data ss:Type="%s">' + // data type
|
'<Data ss:Type="%s">' + // data type
|
||||||
'%s' + // value string
|
'%s' + // value string
|
||||||
'</Data>' +
|
'</Data>' +
|
||||||
'%s' + // Comment <Comment>...</Comment>
|
'%s' + // Comment <Comment>...</Comment>
|
||||||
'</Cell>' + LineEnding, [
|
'</Cell>' + LineEnding, [
|
||||||
styleStr, formulaStr, hyperlinkStr,
|
GetIndexStr(ACol+1), GetStyleStr(ACell), formulaStr, GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
||||||
cctStr,
|
cctStr,
|
||||||
valueStr,
|
valueStr,
|
||||||
commentStr
|
GetCommentStr(ACell)
|
||||||
]));
|
]));
|
||||||
|
|
||||||
{
|
|
||||||
AppendToStream(AStream, Format(
|
|
||||||
' <Cell%s%s><Data ss:Type="%s">%s</Data></Cell>' + LineEnding,
|
|
||||||
[styleStr, formulaStr, cctStr, valueStr])); }
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadExcelXMLWriter.WriteCells(AStream: TStream; AWorksheet: TsWorksheet);
|
procedure TsSpreadExcelXMLWriter.WriteCells(AStream: TStream; AWorksheet: TsWorksheet);
|
||||||
@@ -215,11 +254,12 @@ begin
|
|||||||
for c := c1 to c2 do
|
for c := c1 to c2 do
|
||||||
begin
|
begin
|
||||||
cell := AWorksheet.FindCell(r, c);
|
cell := AWorksheet.FindCell(r, c);
|
||||||
if cell = nil then
|
if cell <> nil then
|
||||||
AppendToStream(AStream,
|
begin
|
||||||
' <Cell />' + LineEnding)
|
if FWorksheet.IsMerged(cell) and not FWorksheet.IsMergeBase(cell) then
|
||||||
else
|
Continue;
|
||||||
WriteCellToStream(AStream, cell);
|
WriteCellToStream(AStream, cell);
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
AppendToStream(AStream,
|
AppendToStream(AStream,
|
||||||
' </Row>' + LineEnding);
|
' </Row>' + LineEnding);
|
||||||
@@ -256,14 +296,9 @@ var
|
|||||||
valueStr: String;
|
valueStr: String;
|
||||||
formulaStr: String;
|
formulaStr: String;
|
||||||
cctStr: String;
|
cctStr: String;
|
||||||
styleStr: STring;
|
|
||||||
ExcelDate: TDateTime;
|
ExcelDate: TDateTime;
|
||||||
nfp: TsNumFormatParams;
|
nfp: TsNumFormatParams;
|
||||||
fmt: PsCellFormat;
|
fmt: PsCellFormat;
|
||||||
hyperlink: PsHyperlink;
|
|
||||||
hyperlinkStr: String;
|
|
||||||
comment: PsComment;
|
|
||||||
commentStr: String;
|
|
||||||
begin
|
begin
|
||||||
ExcelDate := AValue;
|
ExcelDate := AValue;
|
||||||
fmt := FWorkbook.GetPointerToCellFormat(ACell^.FormatIndex);
|
fmt := FWorkbook.GetPointerToCellFormat(ACell^.FormatIndex);
|
||||||
@@ -283,37 +318,19 @@ begin
|
|||||||
formulaStr := Format(' ss:Formula="=%s"', [ACell^.FormulaValue]);
|
formulaStr := Format(' ss:Formula="=%s"', [ACell^.FormulaValue]);
|
||||||
cctStr := GetCellContentTypeStr(ACell);
|
cctStr := GetCellContentTypeStr(ACell);
|
||||||
end;
|
end;
|
||||||
if ACell^.FormatIndex > 0 then
|
|
||||||
styleStr := Format(' ss:StyleID="s%d"', [ACell^.FormatIndex + FMT_OFFSET]) else
|
|
||||||
styleStr := '';
|
|
||||||
|
|
||||||
hyperlink := FWorksheet.FindHyperlink(ACell);
|
|
||||||
if Assigned(hyperlink) then
|
|
||||||
hyperlinkStr := ' ss:HRef="' + hyperlink^.Target + '"' else
|
|
||||||
hyperlinkStr := '';
|
|
||||||
|
|
||||||
comment := FWorksheet.FindComment(ACell);
|
|
||||||
if Assigned(comment) then
|
|
||||||
commentStr := '<Comment><Data>'+comment^.Text+'</Data></Comment>' else
|
|
||||||
commentStr := '';
|
|
||||||
AppendToStream(AStream, Format(
|
AppendToStream(AStream, Format(
|
||||||
' <Cell%s%s%s>' + // style, formula, hyperlink
|
' <Cell%s%s%s%s%s>' + // colIndex, style, formula, hyperlink, merge
|
||||||
'<Data ss:Type="%s">' + // data type
|
'<Data ss:Type="%s">' + // data type
|
||||||
'%s' + // value string
|
'%s' + // value string
|
||||||
'</Data>' +
|
'</Data>' +
|
||||||
'%s' + // Comment <Comment>...</Comment>
|
'%s' + // Comment <Comment>...</Comment>
|
||||||
'</Cell>' + LineEnding, [
|
'</Cell>' + LineEnding, [
|
||||||
styleStr, formulaStr, hyperlinkStr,
|
GetIndexStr(ACol+1), GetStyleStr(ACell), formulaStr, GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
||||||
cctStr,
|
cctStr,
|
||||||
valueStr,
|
valueStr,
|
||||||
commentStr
|
GetCommentStr(ACell)
|
||||||
]));
|
]));
|
||||||
|
|
||||||
{
|
|
||||||
AppendToStream(AStream, Format(
|
|
||||||
' <Cell%s%s><Data ss:Type="%s">%s</Data></Cell>' + LineEnding,
|
|
||||||
[styleStr, formulaStr, cctStr, valueStr])
|
|
||||||
); }
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadExcelXMLWriter.WriteError(AStream: TStream;
|
procedure TsSpreadExcelXMLWriter.WriteError(AStream: TStream;
|
||||||
@@ -322,11 +339,6 @@ var
|
|||||||
valueStr: String;
|
valueStr: String;
|
||||||
cctStr: String;
|
cctStr: String;
|
||||||
formulaStr: String;
|
formulaStr: String;
|
||||||
styleStr: String;
|
|
||||||
hyperlink: PsHyperlink;
|
|
||||||
hyperlinkStr: String;
|
|
||||||
comment: PsComment;
|
|
||||||
commentStr: String;
|
|
||||||
begin
|
begin
|
||||||
valueStr := GetErrorValueStr(AValue);
|
valueStr := GetErrorValueStr(AValue);
|
||||||
|
|
||||||
@@ -338,40 +350,18 @@ begin
|
|||||||
formulaStr := Format(' ss:Formula="=%s"', [ACell^.FormulaValue]);
|
formulaStr := Format(' ss:Formula="=%s"', [ACell^.FormulaValue]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if ACell^.FormatIndex > 0 then
|
|
||||||
styleStr := Format(' ss:StyleID="s%d"', [ACell^.FormatIndex + FMT_OFFSET]) else
|
|
||||||
styleStr := '';
|
|
||||||
|
|
||||||
hyperlink := FWorksheet.FindHyperlink(ACell);
|
|
||||||
if Assigned(hyperlink) then
|
|
||||||
hyperlinkStr := ' ss:HRef="' + hyperlink^.Target + '"' else
|
|
||||||
hyperlinkStr := '';
|
|
||||||
|
|
||||||
comment := FWorksheet.FindComment(ACell);
|
|
||||||
if Assigned(comment) then
|
|
||||||
// commentStr := '<Comment><ss:Data xmlns="http://www.w3.org/TR/REC-html40">'+comment^.Text+'</ss:Data></Comment>' else
|
|
||||||
commentStr := '<Comment><Data>'+comment^.Text+'</Data></Comment>' else
|
|
||||||
commentStr := '';
|
|
||||||
|
|
||||||
AppendToStream(AStream, Format(
|
AppendToStream(AStream, Format(
|
||||||
' <Cell%s%s%s>' + // style, formula, hyperlink
|
' <Cell%s%s%s%s%s>' + // colIndex, style, formula, hyperlink, merge
|
||||||
'<Data ss:Type="%s">' + // data type
|
'<Data ss:Type="%s">' + // data type
|
||||||
'%s' + // value string
|
'%s' + // value string
|
||||||
'</Data>' +
|
'</Data>' +
|
||||||
'%s' + // Comment <Comment>...</Comment>
|
'%s' + // Comment <Comment>...</Comment>
|
||||||
'</Cell>' + LineEnding, [
|
'</Cell>' + LineEnding, [
|
||||||
styleStr, formulaStr, hyperlinkStr,
|
GetIndexStr(ACol+1), GetStyleStr(ACell), formulaStr, GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
||||||
cctStr,
|
cctStr,
|
||||||
valueStr,
|
valueStr,
|
||||||
commentStr
|
GetCommentStr(ACell)
|
||||||
]));
|
]));
|
||||||
|
|
||||||
{
|
|
||||||
AppendToStream(AStream, Format(
|
|
||||||
' <Cell%s%s><Data ss:Type="%s">%s</Data></Cell>' + LineEnding,
|
|
||||||
[styleStr, formulaStr, cctStr, valueStr])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadExcelXMLWriter.WriteLabel(AStream: TStream; const ARow,
|
procedure TsSpreadExcelXMLWriter.WriteLabel(AStream: TStream; const ARow,
|
||||||
@@ -380,13 +370,8 @@ var
|
|||||||
valueStr: String;
|
valueStr: String;
|
||||||
cctStr: String;
|
cctStr: String;
|
||||||
formulaStr: String;
|
formulaStr: String;
|
||||||
styleStr: String;
|
|
||||||
xmlnsStr: String;
|
xmlnsStr: String;
|
||||||
dataTagStr: String;
|
dataTagStr: String;
|
||||||
comment: PsComment;
|
|
||||||
commentStr: String;
|
|
||||||
hyperlink: PsHyperlink;
|
|
||||||
hyperlinkStr: String;
|
|
||||||
begin
|
begin
|
||||||
if Length(ACell^.RichTextParams) > 0 then
|
if Length(ACell^.RichTextParams) > 0 then
|
||||||
begin
|
begin
|
||||||
@@ -395,7 +380,7 @@ begin
|
|||||||
FWorksheet.ReadCellFont(ACell),
|
FWorksheet.ReadCellFont(ACell),
|
||||||
AValue,
|
AValue,
|
||||||
ACell^.RichTextParams,
|
ACell^.RichTextParams,
|
||||||
valueStr, // html-formatted rich text
|
valueStr, // html-formatted rich text
|
||||||
'html:', tcProperCase
|
'html:', tcProperCase
|
||||||
);
|
);
|
||||||
xmlnsStr := ' xmlns="http://www.w3.org/TR/REC-html40"';
|
xmlnsStr := ' xmlns="http://www.w3.org/TR/REC-html40"';
|
||||||
@@ -419,33 +404,18 @@ begin
|
|||||||
formulaStr := Format(' ss:Formula="=%s"', [ACell^.FormulaValue]);
|
formulaStr := Format(' ss:Formula="=%s"', [ACell^.FormulaValue]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
if ACell^.FormatIndex > 0 then
|
|
||||||
styleStr := Format(' ss:StyleID="s%d"', [ACell^.FormatIndex + FMT_OFFSET]) else
|
|
||||||
styleStr := '';
|
|
||||||
|
|
||||||
hyperlink := FWorksheet.FindHyperlink(ACell);
|
|
||||||
if Assigned(hyperlink) then
|
|
||||||
hyperlinkStr := ' ss:HRef="' + hyperlink^.Target + '"' else
|
|
||||||
hyperlinkStr := '';
|
|
||||||
|
|
||||||
comment := FWorksheet.FindComment(ACell);
|
|
||||||
if Assigned(comment) then
|
|
||||||
// commentStr := '<Comment><ss:Data xmlns="http://www.w3.org/TR/REC-html40">'+comment^.Text+'</ss:Data></Comment>' else
|
|
||||||
commentStr := '<Comment><Data>'+comment^.Text+'</Data></Comment>' else
|
|
||||||
commentStr := '';
|
|
||||||
|
|
||||||
AppendToStream(AStream, Format(
|
AppendToStream(AStream, Format(
|
||||||
' <Cell%s%s%s>' + // style, formula, hyperlink
|
' <Cell%s%s%s%s%s>' + // colIndex, style, formula, hyperlink, merge
|
||||||
'<%sData ss:Type="%s"%s>'+ // "ss:", data type, "xmlns=.."
|
'<%sData ss:Type="%s"%s>'+ // "ss:", data type, "xmlns=.."
|
||||||
'%s' + // value string
|
'%s' + // value string
|
||||||
'</%sData>' + // "ss:"
|
'</%sData>' + // "ss:"
|
||||||
'%s' + // Comment
|
'%s' + // Comment
|
||||||
'</Cell>' + LineEnding, [
|
'</Cell>' + LineEnding, [
|
||||||
styleStr, formulaStr, hyperlinkStr,
|
GetIndexStr(ACol+1), GetStyleStr(ACell), formulaStr, GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
||||||
dataTagStr, cctStr, xmlnsStr,
|
dataTagStr, cctStr, xmlnsStr,
|
||||||
valueStr,
|
valueStr,
|
||||||
dataTagStr,
|
dataTagStr,
|
||||||
commentStr
|
GetCommentStr(ACell)
|
||||||
]));
|
]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@@ -454,11 +424,6 @@ procedure TsSpreadExcelXMLWriter.WriteNumber(AStream: TStream; const ARow, ACol:
|
|||||||
var
|
var
|
||||||
formulaStr: String;
|
formulaStr: String;
|
||||||
cctStr: String;
|
cctStr: String;
|
||||||
styleStr: String;
|
|
||||||
hyperlink: PsHyperlink;
|
|
||||||
hyperlinkStr: String;
|
|
||||||
comment: PsComment;
|
|
||||||
commentStr: String;
|
|
||||||
begin
|
begin
|
||||||
cctStr := 'Number';
|
cctStr := 'Number';
|
||||||
if HasFormula(ACell) then
|
if HasFormula(ACell) then
|
||||||
@@ -466,74 +431,22 @@ begin
|
|||||||
cctStr := GetCellContentTypeStr(ACell);
|
cctStr := GetCellContentTypeStr(ACell);
|
||||||
formulaStr := Format(' ss:Formula="=%s"', [ACell^.FormulaValue]);
|
formulaStr := Format(' ss:Formula="=%s"', [ACell^.FormulaValue]);
|
||||||
end;
|
end;
|
||||||
if ACell^.FormatIndex > 0 then
|
|
||||||
styleStr := Format(' ss:StyleID="s%d"', [ACell^.FormatIndex + FMT_OFFSET]) else
|
|
||||||
styleStr := '';
|
|
||||||
|
|
||||||
hyperlink := FWorksheet.FindHyperlink(ACell);
|
|
||||||
if Assigned(hyperlink) then
|
|
||||||
hyperlinkStr := ' ss:HRef="' + hyperlink^.Target + '"' else
|
|
||||||
hyperlinkStr := '';
|
|
||||||
|
|
||||||
comment := FWorksheet.FindComment(ACell);
|
|
||||||
if Assigned(comment) then
|
|
||||||
commentStr := '<Comment><Data>'+comment^.Text+'</Data></Comment>' else
|
|
||||||
commentStr := '';
|
|
||||||
|
|
||||||
AppendToStream(AStream, Format(
|
AppendToStream(AStream, Format(
|
||||||
' <Cell%s%s%s>' + // style, formula, hyperlink
|
' <Cell%s%s%s%s%s>' + // colIndex, style, formula, hyperlink, merge
|
||||||
'<Data ss:Type="%s">' + // data type
|
'<Data ss:Type="%s">' + // data type
|
||||||
'%g' + // value
|
'%g' + // value
|
||||||
'</Data>' +
|
'</Data>' +
|
||||||
'%s' + // Comment <Comment>...</Comment>
|
'%s' + // Comment <Comment>...</Comment>
|
||||||
'</Cell>' + LineEnding, [
|
'</Cell>' + LineEnding, [
|
||||||
styleStr, formulaStr, hyperlinkStr,
|
GetIndexStr(ACol+1), GetStyleStr(ACell), formulaStr, GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
||||||
cctStr,
|
cctStr,
|
||||||
AValue,
|
AValue,
|
||||||
commentStr
|
GetCommentStr(ACell)
|
||||||
]));
|
]));
|
||||||
{
|
|
||||||
AppendToStream(AStream, Format(
|
|
||||||
' <Cell%s%s><Data ss:Type="%s">%g</Data></Cell>' + LineEnding,
|
|
||||||
[styleStr, formulaStr, cctStr, AValue], FPointSeparatorSettings)
|
|
||||||
); }
|
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadExcelXMLWriter.WriteStyle(AStream: TStream; AIndex: Integer);
|
procedure TsSpreadExcelXMLWriter.WriteStyle(AStream: TStream; AIndex: Integer);
|
||||||
const
|
|
||||||
{ TsFillStyle = (
|
|
||||||
fsNoFill, fsSolidFill,
|
|
||||||
fsGray75, fsGray50, fsGray25, fsGray12, fsGray6,
|
|
||||||
fsStripeHor, fsStripeVert, fsStripeDiagUp, fsStripeDiagDown,
|
|
||||||
fsThinStripeHor, fsThinStripeVert, fsThinStripeDiagUp, fsThinStripeDiagDown,
|
|
||||||
fsHatchDiag, fsThinHatchDiag, fsThickHatchDiag, fsThinHatchHor) }
|
|
||||||
FILL_NAMES: array[TsFillStyle] of string = (
|
|
||||||
'', 'Solid',
|
|
||||||
'Gray75', 'Gray50', 'Gray25', 'Gray12', 'Gray0625',
|
|
||||||
'HorzStripe', 'VertStripe', 'DiagStripe', 'ReverseDiagStripe',
|
|
||||||
'ThinHorzStripe', 'ThinVertStripe', 'ThinDiagStripe', 'ThinReverseDiagStripe',
|
|
||||||
'DiagCross', 'ThinDiagCross', 'ThickDiagCross', 'ThinHorzCross'
|
|
||||||
);
|
|
||||||
|
|
||||||
{TsCellBorder = (cbNorth, cbWest, cbEast, cbSouth, cbDiagUp, cbDiagDown); }
|
|
||||||
BORDER_NAMES: array[TsCellBorder] of string = (
|
|
||||||
'Top', 'Left', 'Right', 'Bottom', 'DiagonalRight', 'DiagonalLeft'
|
|
||||||
);
|
|
||||||
|
|
||||||
{ TsLineStyle = (
|
|
||||||
lsThin, lsMedium, lsDashed, lsDotted, lsThick, lsDouble, lsHair,
|
|
||||||
lsMediumDash, lsDashDot, lsMediumDashDot, lsDashDotDot, lsMediumDashDotDot,
|
|
||||||
lsSlantDashDot) }
|
|
||||||
LINE_STYLES: array[TsLineStyle] of string = (
|
|
||||||
'Continuous', 'Continuous', 'Dash', 'Dot', 'Continuous', 'Double', 'Continuous',
|
|
||||||
'Dash', 'DashDot', 'DashDot', 'DashDotDot', 'DashDotDot',
|
|
||||||
'SlantDashDot'
|
|
||||||
);
|
|
||||||
LINE_WIDTHS: array[TsLineStyle] of Integer = (
|
|
||||||
1, 2, 1, 1, 3, 3, 0,
|
|
||||||
2, 1, 2, 1, 2,
|
|
||||||
2
|
|
||||||
);
|
|
||||||
var
|
var
|
||||||
fmt: PsCellFormat;
|
fmt: PsCellFormat;
|
||||||
deffnt, fnt: TsFont;
|
deffnt, fnt: TsFont;
|
||||||
|
Reference in New Issue
Block a user