fpspreadsheet: Write wikitable cells with row and column formats correctly
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@5287 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
027504e95f
commit
a93e9d16d6
@ -377,7 +377,7 @@ Format mediawiki:
|
|||||||
*)
|
*)
|
||||||
procedure TsWikiTableWriter.WriteToStrings_WikiMedia(AStrings: TStrings);
|
procedure TsWikiTableWriter.WriteToStrings_WikiMedia(AStrings: TStrings);
|
||||||
|
|
||||||
function DoBorder(ABorder: TsCellBorder; ACell: PCell): String;
|
function DoBorder(AFormat: PsCellFormat; ABorder: TsCellBorder): String;
|
||||||
const
|
const
|
||||||
// (cbNorth, cbWest, cbEast, cbSouth, cbDiagUp, cbDiagDown)
|
// (cbNorth, cbWest, cbEast, cbSouth, cbDiagUp, cbDiagDown)
|
||||||
BORDERNAMES: array[TsCellBorder] of string =
|
BORDERNAMES: array[TsCellBorder] of string =
|
||||||
@ -389,11 +389,9 @@ procedure TsWikiTableWriter.WriteToStrings_WikiMedia(AStrings: TStrings);
|
|||||||
var
|
var
|
||||||
ls: TsLineStyle;
|
ls: TsLineStyle;
|
||||||
clr: TsColor;
|
clr: TsColor;
|
||||||
fmt: PsCellFormat;
|
|
||||||
begin
|
begin
|
||||||
fmt := Workbook.GetPointerToCellFormat(ACell^.FormatIndex);
|
ls := AFormat^.BorderStyles[ABorder].LineStyle;
|
||||||
ls := fmt^.BorderStyles[ABorder].LineStyle;
|
clr := AFormat^.BorderStyles[ABorder].Color;
|
||||||
clr := fmt^.BorderStyles[ABorder].Color;
|
|
||||||
Result := Format('border-%s:%s', [BORDERNAMES[ABorder], LINESTYLES[ls]]);
|
Result := Format('border-%s:%s', [BORDERNAMES[ABorder], LINESTYLES[ls]]);
|
||||||
if clr <> scBlack then
|
if clr <> scBlack then
|
||||||
Result := Result + ' ' + ColorToHTMLColorStr(clr) + '; ';
|
Result := Result + ' ' + ColorToHTMLColorStr(clr) + '; ';
|
||||||
@ -421,6 +419,7 @@ var
|
|||||||
isHeader: Boolean;
|
isHeader: Boolean;
|
||||||
borders: TsCellBorders;
|
borders: TsCellBorders;
|
||||||
fs: TFormatSettings;
|
fs: TFormatSettings;
|
||||||
|
fmt: PsCellFormat;
|
||||||
begin
|
begin
|
||||||
FWorksheet := Workbook.GetFirstWorksheet();
|
FWorksheet := Workbook.GetFirstWorksheet();
|
||||||
FWorksheet.UpdateCaches;
|
FWorksheet.UpdateCaches;
|
||||||
@ -458,10 +457,12 @@ begin
|
|||||||
for i := 0 to FWorksheet.GetLastRowIndex() do
|
for i := 0 to FWorksheet.GetLastRowIndex() do
|
||||||
begin
|
begin
|
||||||
AStrings.Add('|-');
|
AStrings.Add('|-');
|
||||||
|
lRow := FWorksheet.FindRow(i);
|
||||||
|
|
||||||
for j := 0 to FWorksheet.GetLastColIndex do
|
for j := 0 to FWorksheet.GetLastColIndex do
|
||||||
begin
|
begin
|
||||||
lCell := FWorksheet.FindCell(i, j);
|
lCell := FWorksheet.FindCell(i, j);
|
||||||
|
lCol := FWorksheet.FindCol(j);
|
||||||
lCurStr := FWorksheet.ReadAsText(lCell, fs);
|
lCurStr := FWorksheet.ReadAsText(lCell, fs);
|
||||||
|
|
||||||
// Check for invalid characters
|
// Check for invalid characters
|
||||||
@ -477,7 +478,12 @@ begin
|
|||||||
lRowSpanStr := '';
|
lRowSpanStr := '';
|
||||||
lColWidthStr := '';
|
lColWidthStr := '';
|
||||||
lRowHeightStr := '';
|
lRowHeightStr := '';
|
||||||
lCurUsedFormatting := FWorksheet.ReadUsedFormatting(lCell);
|
|
||||||
|
// Format
|
||||||
|
fmt := FWorksheet.GetPointerToEffectiveCellFormat(i, j);
|
||||||
|
if fmt <> nil then
|
||||||
|
lCurUsedFormatting := fmt^.UsedFormattingFields else
|
||||||
|
lCurUsedFormatting := [];
|
||||||
|
|
||||||
// Row header
|
// Row header
|
||||||
isHeader := (soHasFrozenPanes in FWorksheet.Options) and
|
isHeader := (soHasFrozenPanes in FWorksheet.Options) and
|
||||||
@ -485,27 +491,21 @@ begin
|
|||||||
|
|
||||||
// Column width (to be considered in first row)
|
// Column width (to be considered in first row)
|
||||||
if i = 0 then
|
if i = 0 then
|
||||||
begin
|
lColWidthStr := Format(' width="%.0fpt"', [
|
||||||
lCol := FWorksheet.FindCol(j);
|
FWorkbook.ConvertUnits(FWorksheet.GetColWidth(i), FWorkbook.Units, suPoints)
|
||||||
if lCol <> nil then
|
]);
|
||||||
lColWidthStr := Format(' width="%.0fpt"',
|
|
||||||
[FWorkbook.ConvertUnits(lCol^.Width, FWorkbook.Units, suPoints)]);
|
|
||||||
end;
|
|
||||||
|
|
||||||
// Row height (to be considered in first column)
|
// Row height (to be considered in first column)
|
||||||
if j = 0 then
|
if j = 0 then
|
||||||
begin
|
lRowHeightStr := Format(' height="%.0fpt"', [
|
||||||
lRow := FWorksheet.FindRow(i);
|
FWorkbook.ConvertUnits(FWorksheet.GetRowHeight(j), FWorkbook.Units, suPoints)
|
||||||
if (lRow <> nil) and (lRow^.RowHeightType <> rhtDefault) then
|
]);
|
||||||
lRowHeightStr := Format(' height="%.0fpt"',
|
|
||||||
[FWorkbook.ConvertUnits(lRow^.Height, FWorkbook.Units, suPoints)]);
|
|
||||||
end;
|
|
||||||
|
|
||||||
// Font
|
// Font
|
||||||
lFont := FWorkbook.GetDefaultFont;
|
lFont := FWorkbook.GetDefaultFont;
|
||||||
if (uffFont in lCurUsedFormatting) then
|
if (uffFont in lCurUsedFormatting) and (fmt <> nil) then
|
||||||
begin
|
begin
|
||||||
lFont := FWorksheet.ReadCellFont(lCell);
|
lFont := FWorkbook.GetFont(fmt^.FontIndex);
|
||||||
if fssBold in lFont.Style then lCurStr := '<b>' + lCurStr + '</b>';
|
if fssBold in lFont.Style then lCurStr := '<b>' + lCurStr + '</b>';
|
||||||
if fssItalic in lFont.Style then lCurStr := '<i>' + lCurStr + '</i>';
|
if fssItalic in lFont.Style then lCurStr := '<i>' + lCurStr + '</i>';
|
||||||
if fssUnderline in lFont.Style then lCurStr := '<u>' + lCurStr + '</u>';
|
if fssUnderline in lFont.Style then lCurStr := '<u>' + lCurStr + '</u>';
|
||||||
@ -513,9 +513,12 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Background color
|
// Background color
|
||||||
if uffBackground in lCurUsedFormatting then
|
if (fmt <> nil) and (uffBackground in lCurUsedFormatting) then
|
||||||
begin
|
begin
|
||||||
lCurColor := FWorksheet.ReadBackgroundColor(lCell);
|
if (fmt^.Background.Style = fsSolidFill) then
|
||||||
|
lCurColor := fmt^.Background.FgColor
|
||||||
|
else
|
||||||
|
lCurColor := fmt^.Background.BgColor;
|
||||||
lStyleStr := Format('background-color:%s;color:%s;', [
|
lStyleStr := Format('background-color:%s;color:%s;', [
|
||||||
ColorToHTMLColorStr(lCurColor),
|
ColorToHTMLColorStr(lCurColor),
|
||||||
ColorToHTMLColorStr(lFont.Color)
|
ColorToHTMLColorStr(lFont.Color)
|
||||||
@ -523,9 +526,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// Horizontal alignment
|
// Horizontal alignment
|
||||||
if uffHorAlign in lCurUsedFormatting then
|
if (fmt <> nil) and (uffHorAlign in lCurUsedFormatting) then
|
||||||
begin
|
begin
|
||||||
horAlign := FWorksheet.ReadHorAlignment(lCell);
|
horAlign := fmt^.HorAlignment;
|
||||||
if horAlign = haDefault then
|
if horAlign = haDefault then
|
||||||
case lCell^.ContentType of
|
case lCell^.ContentType of
|
||||||
cctNumber,
|
cctNumber,
|
||||||
@ -541,9 +544,9 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// vertical alignment
|
// vertical alignment
|
||||||
if uffVertAlign in lCurUsedFormatting then
|
if (fmt <> nil) and (uffVertAlign in lCurUsedFormatting) then
|
||||||
begin
|
begin
|
||||||
vertAlign := FWorksheet.ReadVertAlignment(lCell);
|
vertAlign := fmt^.VertAlignment;
|
||||||
case vertAlign of
|
case vertAlign of
|
||||||
vaTop : lStyleStr := lStyleStr + 'vertical-align:top;';
|
vaTop : lStyleStr := lStyleStr + 'vertical-align:top;';
|
||||||
vaCenter : lStyleStr := lStyleStr + 'vertical-align:center;';
|
vaCenter : lStyleStr := lStyleStr + 'vertical-align:center;';
|
||||||
@ -552,17 +555,18 @@ begin
|
|||||||
end;
|
end;
|
||||||
|
|
||||||
// borders
|
// borders
|
||||||
if uffBorder in lCurUsedFormatting then
|
if (fmt <> nil) and (uffBorder in lCurUsedFormatting) then
|
||||||
begin
|
begin
|
||||||
borders := FWorksheet.ReadCellBorders(lCell);
|
borders := fmt^.Border;
|
||||||
|
// borders := FWorksheet.ReadCellBorders(lCell);
|
||||||
if (cbWest in borders) then
|
if (cbWest in borders) then
|
||||||
lStyleStr := lStyleStr + DoBorder(cbWest, lCell);
|
lStyleStr := lStyleStr + DoBorder(fmt, cbWest);
|
||||||
if (cbEast in borders) then
|
if (cbEast in borders) then
|
||||||
lStyleStr := lStyleStr + DoBorder(cbEast, lCell);
|
lStyleStr := lStyleStr + DoBorder(fmt, cbEast);
|
||||||
if (cbNorth in borders) then
|
if (cbNorth in borders) then
|
||||||
lStyleStr := lStyleStr + DoBorder(cbNorth, lCell);
|
lStyleStr := lStyleStr + DoBorder(fmt, cbNorth);
|
||||||
if (cbSouth in borders) then
|
if (cbSouth in borders) then
|
||||||
lStyleStr := lStyleStr + DoBorder(cbSouth, lCell);
|
lStyleStr := lStyleStr + DoBorder(fmt, cbSouth);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
// Merged cells
|
// Merged cells
|
||||||
|
Loading…
Reference in New Issue
Block a user