You've already forked lazarus-ccr
fpspreadsheet: Write row and column formats to ExcelXML
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5266 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@ -43,7 +43,7 @@ type
|
|||||||
function GetPageFooterStr(AWorksheet: TsWorksheet): String;
|
function GetPageFooterStr(AWorksheet: TsWorksheet): String;
|
||||||
function GetPageHeaderStr(AWorksheet: TsWorksheet): String;
|
function GetPageHeaderStr(AWorksheet: TsWorksheet): String;
|
||||||
function GetPageMarginStr(AWorksheet: TsWorksheet): String;
|
function GetPageMarginStr(AWorksheet: TsWorksheet): String;
|
||||||
function GetStyleStr(ACell: PCell): String;
|
function GetStyleStr(AFormatIndex: Integer): String;
|
||||||
procedure WriteExcelWorkbook(AStream: TStream);
|
procedure WriteExcelWorkbook(AStream: TStream);
|
||||||
procedure WriteStyle(AStream: TStream; AIndex: Integer);
|
procedure WriteStyle(AStream: TStream; AIndex: Integer);
|
||||||
procedure WriteStyles(AStream: TStream);
|
procedure WriteStyles(AStream: TStream);
|
||||||
@ -308,11 +308,11 @@ begin
|
|||||||
Result := '<PageMargins ' + Result + '/>';
|
Result := '<PageMargins ' + Result + '/>';
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function TsSpreadExcelXMLWriter.GetStyleStr(ACell: PCell): String;
|
function TsSpreadExcelXMLWriter.GetStyleStr(AFormatIndex: Integer): String;
|
||||||
begin
|
begin
|
||||||
Result := '';
|
Result := '';
|
||||||
if ACell^.FormatIndex > 0 then
|
if AFormatIndex > 0 then
|
||||||
Result := Format(' ss:StyleID="s%d"', [ACell^.FormatIndex + FMT_OFFSET]);
|
Result := Format(' ss:StyleID="s%d"', [AFormatIndex + FMT_OFFSET]);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TsSpreadExcelXMLWriter.WriteBlank(AStream: TStream;
|
procedure TsSpreadExcelXMLWriter.WriteBlank(AStream: TStream;
|
||||||
@ -323,7 +323,7 @@ begin
|
|||||||
'<Cell%s%s%s%s>' + // colIndex, style, hyperlink, merge
|
'<Cell%s%s%s%s>' + // colIndex, style, hyperlink, merge
|
||||||
'%s' + // Comment <Comment>...</Comment>
|
'%s' + // Comment <Comment>...</Comment>
|
||||||
'</Cell>' + LF, [
|
'</Cell>' + LF, [
|
||||||
GetIndexStr(ACol+1), GetStyleStr(ACell), GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
GetIndexStr(ACol+1), GetStyleStr(ACell^.FormatIndex), GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
||||||
GetCommentStr(ACell)
|
GetCommentStr(ACell)
|
||||||
]));
|
]));
|
||||||
end;
|
end;
|
||||||
@ -339,7 +339,8 @@ begin
|
|||||||
'</Data>' +
|
'</Data>' +
|
||||||
'%s' + // Comment <Comment>...</Comment>
|
'%s' + // Comment <Comment>...</Comment>
|
||||||
'</Cell>' + LF, [
|
'</Cell>' + LF, [
|
||||||
GetIndexStr(ACol+1), GetStyleStr(ACell), GetFormulaStr(ACell), GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
GetIndexStr(ACol+1), GetStyleStr(ACell^.FormatIndex), GetFormulaStr(ACell),
|
||||||
|
GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
||||||
StrUtils.IfThen(HasFormula(ACell), GetCellContentTypeStr(ACell), 'Boolean'),
|
StrUtils.IfThen(HasFormula(ACell), GetCellContentTypeStr(ACell), 'Boolean'),
|
||||||
StrUtils.IfThen(AValue, '1', '0'),
|
StrUtils.IfThen(AValue, '1', '0'),
|
||||||
GetCommentStr(ACell)
|
GetCommentStr(ACell)
|
||||||
@ -397,7 +398,8 @@ begin
|
|||||||
'</Data>' + LF + CELL_INDENT +
|
'</Data>' + LF + CELL_INDENT +
|
||||||
'%s' + // Comment <Comment>...</Comment>
|
'%s' + // Comment <Comment>...</Comment>
|
||||||
'</Cell>' + LF, [
|
'</Cell>' + LF, [
|
||||||
GetIndexStr(ACol+1), GetStyleStr(ACell), GetFormulaStr(ACell), GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
GetIndexStr(ACol+1), GetStyleStr(ACell^.FormatIndex), GetFormulaStr(ACell),
|
||||||
|
GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
||||||
StrUtils.IfThen(HasFormula(ACell), GetCellContentTypeStr(ACell), 'DateTime'),
|
StrUtils.IfThen(HasFormula(ACell), GetCellContentTypeStr(ACell), 'DateTime'),
|
||||||
valueStr,
|
valueStr,
|
||||||
GetCommentStr(ACell)
|
GetCommentStr(ACell)
|
||||||
@ -415,7 +417,8 @@ begin
|
|||||||
'</Data>' + LF + CELL_INDENT +
|
'</Data>' + LF + CELL_INDENT +
|
||||||
'%s' + // Comment <Comment>...</Comment>
|
'%s' + // Comment <Comment>...</Comment>
|
||||||
'</Cell>' + LF, [
|
'</Cell>' + LF, [
|
||||||
GetIndexStr(ACol+1), GetStyleStr(ACell), GetFormulaStr(ACell), GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
GetIndexStr(ACol+1), GetStyleStr(ACell^.FormatIndex), GetFormulaStr(ACell),
|
||||||
|
GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
||||||
StrUtils.IfThen(HasFormula(ACell), GetCellContentTypeStr(ACell), 'Error'),
|
StrUtils.IfThen(HasFormula(ACell), GetCellContentTypeStr(ACell), 'Error'),
|
||||||
GetErrorValueStr(AValue),
|
GetErrorValueStr(AValue),
|
||||||
GetCommentStr(ACell)
|
GetCommentStr(ACell)
|
||||||
@ -482,7 +485,8 @@ begin
|
|||||||
'</%sData>' + LF + CELL_INDENT + // "ss:"
|
'</%sData>' + LF + CELL_INDENT + // "ss:"
|
||||||
'%s' + // Comment
|
'%s' + // Comment
|
||||||
'</Cell>' + LF, [
|
'</Cell>' + LF, [
|
||||||
GetIndexStr(ACol+1), GetStyleStr(ACell), GetFormulaStr(ACell), GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
GetIndexStr(ACol+1), GetStyleStr(ACell^.FormatIndex), GetFormulaStr(ACell),
|
||||||
|
GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
||||||
dataTagStr, cctStr, xmlnsStr,
|
dataTagStr, cctStr, xmlnsStr,
|
||||||
valueStr,
|
valueStr,
|
||||||
dataTagStr,
|
dataTagStr,
|
||||||
@ -501,7 +505,8 @@ begin
|
|||||||
'</Data>' + LF + CELL_INDENT +
|
'</Data>' + LF + CELL_INDENT +
|
||||||
'%s' + // Comment <Comment>...</Comment>
|
'%s' + // Comment <Comment>...</Comment>
|
||||||
'</Cell>' + LF, [
|
'</Cell>' + LF, [
|
||||||
GetIndexStr(ACol+1), GetStyleStr(ACell), GetFormulaStr(ACell), GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
GetIndexStr(ACol+1), GetStyleStr(ACell^.FormatIndex), GetFormulaStr(ACell),
|
||||||
|
GetHyperlinkStr(ACell), GetMergeStr(ACell),
|
||||||
StrUtils.IfThen(HasFormula(ACell), GetCellContentTypeStr(ACell), 'Number'),
|
StrUtils.IfThen(HasFormula(ACell), GetCellContentTypeStr(ACell), 'Number'),
|
||||||
AValue,
|
AValue,
|
||||||
GetCommentStr(ACell)], FPointSeparatorSettings)
|
GetCommentStr(ACell)], FPointSeparatorSettings)
|
||||||
@ -671,6 +676,7 @@ var
|
|||||||
cell: PCell;
|
cell: PCell;
|
||||||
rowheightStr: String;
|
rowheightStr: String;
|
||||||
colwidthStr: String;
|
colwidthStr: String;
|
||||||
|
styleStr: String;
|
||||||
col: PCol;
|
col: PCol;
|
||||||
row: PRow;
|
row: PRow;
|
||||||
begin
|
begin
|
||||||
@ -694,20 +700,27 @@ begin
|
|||||||
for c := c1 to c2 do
|
for c := c1 to c2 do
|
||||||
begin
|
begin
|
||||||
col := FWorksheet.FindCol(c);
|
col := FWorksheet.FindCol(c);
|
||||||
// column width is needed in pts.
|
styleStr := '';
|
||||||
|
colWidthStr := '';
|
||||||
if Assigned(col) then
|
if Assigned(col) then
|
||||||
colwidthStr := Format(' ss:Width="%0.2f"',
|
begin
|
||||||
[FWorkbook.ConvertUnits(col^.Width, FWorkbook.Units, suPoints)],
|
// column width is needed in pts.
|
||||||
FPointSeparatorSettings)
|
if col^.ColWidthType = cwtCustom then
|
||||||
else
|
colwidthStr := Format(' ss:Width="%0.2f" ss:AutoFitWidth="0"',
|
||||||
colwidthStr := '';
|
[FWorkbook.ConvertUnits(col^.Width, FWorkbook.Units, suPoints)],
|
||||||
|
FPointSeparatorSettings);
|
||||||
|
// column style
|
||||||
|
if col^.FormatIndex > 0 then
|
||||||
|
styleStr := GetStyleStr(col^.FormatIndex);
|
||||||
|
end;
|
||||||
AppendToStream(AStream, COL_INDENT + Format(
|
AppendToStream(AStream, COL_INDENT + Format(
|
||||||
'<Column ss:Index="%d" ss:AutoFitWidth="0"%s />' + LF, [c+1, colWidthStr]));
|
'<Column ss:Index="%d" %s%s />' + LF, [c+1, colWidthStr, styleStr]));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
for r := r1 to r2 do
|
for r := r1 to r2 do
|
||||||
begin
|
begin
|
||||||
row := FWorksheet.FindRow(r);
|
row := FWorksheet.FindRow(r);
|
||||||
|
styleStr := '';
|
||||||
// Row height is needed in pts.
|
// Row height is needed in pts.
|
||||||
if Assigned(row) then
|
if Assigned(row) then
|
||||||
begin
|
begin
|
||||||
@ -718,10 +731,12 @@ begin
|
|||||||
if row^.RowHeightType = rhtCustom then
|
if row^.RowHeightType = rhtCustom then
|
||||||
rowHeightStr := 'ss:AutoFitHeight="0"' + rowHeightStr else
|
rowHeightStr := 'ss:AutoFitHeight="0"' + rowHeightStr else
|
||||||
rowHeightStr := 'ss:AutoFitHeight="1"' + rowHeightStr;
|
rowHeightStr := 'ss:AutoFitHeight="1"' + rowHeightStr;
|
||||||
|
if row^.FormatIndex > 0 then
|
||||||
|
styleStr := GetStyleStr(row^.FormatIndex);
|
||||||
end else
|
end else
|
||||||
rowheightStr := 'ss:AutoFitHeight="1"';
|
rowheightStr := 'ss:AutoFitHeight="1"';
|
||||||
AppendToStream(AStream, ROW_INDENT + Format(
|
AppendToStream(AStream, ROW_INDENT + Format(
|
||||||
'<Row %s>' + LF, [rowheightStr]));
|
'<Row %s%s>' + LF, [rowheightStr, styleStr]));
|
||||||
for c := c1 to c2 do
|
for c := c1 to c2 do
|
||||||
begin
|
begin
|
||||||
cell := AWorksheet.FindCell(r, c);
|
cell := AWorksheet.FindCell(r, c);
|
||||||
|
Reference in New Issue
Block a user