You've already forked lazarus-ccr
fpspreadsheet: Use HTML conversion to enter rich-text in the visual TsCellEdit control
git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@4271 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -988,47 +988,54 @@ begin
|
|||||||
// NOTE: This is a simple version: every opened tag is closed afterwards!
|
// NOTE: This is a simple version: every opened tag is closed afterwards!
|
||||||
// In a more advanced version, shared properties should be kept. This is
|
// In a more advanced version, shared properties should be kept. This is
|
||||||
// what FChangedParams was introduced for!
|
// what FChangedParams was introduced for!
|
||||||
if [cfFontName, cfFontSize, cfFontColor] * FChangedparams[i] <> [] then
|
if not SameFont(FBaseFont, FFonts[i]) then
|
||||||
begin
|
begin
|
||||||
Result := Result + '<font';
|
if [cfFontName, cfFontSize, cfFontColor] * FChangedparams[i] <> [] then
|
||||||
if cfFontName in FChangedParams[i] then
|
begin
|
||||||
Result := Result + ' face="' + FFonts[i].FontName + '"';
|
Result := Result + '<font';
|
||||||
if cfFontSize in FChangedParams[i] then
|
if cfFontName in FChangedParams[i] then
|
||||||
Result := Result + ' size="' + Format('%.gpt', [FFonts[i].Size], FPointSeparatorSettings) + '"';
|
Result := Result + ' face="' + FFonts[i].FontName + '"';
|
||||||
if cfFontColor in FChangedParams[i] then
|
if cfFontSize in FChangedParams[i] then
|
||||||
Result := Result + ' color="' + ColorToHTMLColorStr(FFonts[i].Color) + '"';
|
Result := Result + ' size="' + Format('%.gpt', [FFonts[i].Size], FPointSeparatorSettings) + '"';
|
||||||
end;
|
if cfFontColor in FChangedParams[i] then
|
||||||
if (cfBold in FChangedParams[i]) then
|
Result := Result + ' color="' + ColorToHTMLColorStr(FFonts[i].Color) + '"';
|
||||||
Result := Result + '<b>';
|
Result := Result + '>';
|
||||||
if (cfItalic in FChangedParams[i]) then
|
end;
|
||||||
Result := Result + '<i>';
|
if (cfBold in FChangedParams[i]) then
|
||||||
if (cfUnderline in FChangedParams[i]) then
|
Result := Result + '<b>';
|
||||||
Result := Result + '<u>';
|
if (cfItalic in FChangedParams[i]) then
|
||||||
if (cfStrikeout in FChangedParams[i]) then
|
Result := Result + '<i>';
|
||||||
Result := Result + '<s>';
|
if (cfUnderline in FChangedParams[i]) then
|
||||||
if (cfFontPosition in FChangedParams[i]) then
|
Result := Result + '<u>';
|
||||||
begin
|
if (cfStrikeout in FChangedParams[i]) then
|
||||||
if FFonts[i].Position = fpSuperscript then Result := Result + '<sup>';
|
Result := Result + '<s>';
|
||||||
if FFonts[i].Position = fpSubscript then Result := Result + '<sub>';
|
if (cfFontPosition in FChangedParams[i]) then
|
||||||
|
begin
|
||||||
|
if FFonts[i].Position = fpSuperscript then Result := Result + '<sup>';
|
||||||
|
if FFonts[i].Position = fpSubscript then Result := Result + '<sub>';
|
||||||
|
end;
|
||||||
end;
|
end;
|
||||||
// Add the node text
|
// Add the node text
|
||||||
Result := Result + GetTextOfRichTextParam(i);
|
Result := Result + GetTextOfRichTextParam(i);
|
||||||
// Add closing tags (reverse order as opening!)
|
// Add closing tags (reverse order as opening!)
|
||||||
if (cfFontPosition in FChangedParams[i]) then
|
if not SameFont(FBaseFont, FFonts[i]) then
|
||||||
begin
|
begin
|
||||||
if FFonts[i].Position = fpSubscript then Result := Result + '</sub>';
|
if (cfFontPosition in FChangedParams[i]) then
|
||||||
if FFonts[i].Position = fpSuperscript then Result := Result + '</sup>';
|
begin
|
||||||
|
if FFonts[i].Position = fpSubscript then Result := Result + '</sub>';
|
||||||
|
if FFonts[i].Position = fpSuperscript then Result := Result + '</sup>';
|
||||||
|
end;
|
||||||
|
if (cfStrikeout in FChangedParams[i]) then
|
||||||
|
Result := Result + '</s>';
|
||||||
|
if (cfUnderline in FChangedParams[i]) then
|
||||||
|
Result := Result + '</u>';
|
||||||
|
if (cfItalic in FChangedParams[i]) then
|
||||||
|
Result := Result + '</i>';
|
||||||
|
if (cfBold in FChangedParams[i]) then
|
||||||
|
Result := Result + '</b>';
|
||||||
|
if [cfFontName, cfFontSize, cfFontColor] * FChangedParams[i] <> [] then
|
||||||
|
Result := Result + '</font>';
|
||||||
end;
|
end;
|
||||||
if (cfStrikeout in FChangedParams[i]) then
|
|
||||||
Result := Result + '</s>';
|
|
||||||
if (cfUnderline in FChangedParams[i]) then
|
|
||||||
Result := Result + '</u>';
|
|
||||||
if (cfItalic in FChangedParams[i]) then
|
|
||||||
Result := Result + '</i>';
|
|
||||||
if (cfBold in FChangedParams[i]) then
|
|
||||||
Result := Result + '</b>';
|
|
||||||
if [cfFontName, cfFontSize, cfFontColor] * FChangedParams[i] <> [] then
|
|
||||||
Result := Result + '</font';
|
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
@@ -4183,6 +4183,8 @@ var
|
|||||||
numFmtParams: TsNumFormatParams;
|
numFmtParams: TsNumFormatParams;
|
||||||
maxDig: Integer;
|
maxDig: Integer;
|
||||||
isMixed: Boolean;
|
isMixed: Boolean;
|
||||||
|
rtParams: TsRichTextParams;
|
||||||
|
plain: String;
|
||||||
begin
|
begin
|
||||||
if ACell = nil then
|
if ACell = nil then
|
||||||
exit;
|
exit;
|
||||||
@@ -4252,7 +4254,8 @@ begin
|
|||||||
exit;
|
exit;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
WriteUTF8Text(ACell, AValue);
|
HTMLToRichText(FWorkbook, ReadcellFont(ACell), AValue, plain, rtParams);
|
||||||
|
WriteUTF8Text(ACell, plain, rtParams);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
|
@@ -212,6 +212,7 @@ type
|
|||||||
TsCellEdit = class(TMemo, IsSpreadsheetControl)
|
TsCellEdit = class(TMemo, IsSpreadsheetControl)
|
||||||
private
|
private
|
||||||
FWorkbookSource: TsWorkbookSource;
|
FWorkbookSource: TsWorkbookSource;
|
||||||
|
FShowHTMLText: Boolean;
|
||||||
function GetSelectedCell: PCell;
|
function GetSelectedCell: PCell;
|
||||||
function GetWorkbook: TsWorkbook;
|
function GetWorkbook: TsWorkbook;
|
||||||
function GetWorksheet: TsWorksheet;
|
function GetWorksheet: TsWorksheet;
|
||||||
@@ -234,6 +235,7 @@ type
|
|||||||
{@@ Refers to the underlying worksheet to which the edited cell belongs. }
|
{@@ Refers to the underlying worksheet to which the edited cell belongs. }
|
||||||
property Worksheet: TsWorksheet read GetWorksheet;
|
property Worksheet: TsWorksheet read GetWorksheet;
|
||||||
published
|
published
|
||||||
|
property ShowHTMLText: Boolean read FShowHTMLText write FShowHTMLText default true;
|
||||||
{@@ Link to the WorkbookSource which provides the workbook and worksheet. }
|
{@@ Link to the WorkbookSource which provides the workbook and worksheet. }
|
||||||
property WorkbookSource: TsWorkbookSource read FWorkbookSource write SetWorkbookSource;
|
property WorkbookSource: TsWorkbookSource read FWorkbookSource write SetWorkbookSource;
|
||||||
end;
|
end;
|
||||||
@@ -462,7 +464,7 @@ implementation
|
|||||||
|
|
||||||
uses
|
uses
|
||||||
Types, Math, TypInfo, LCLType, LCLProc, Dialogs, Forms,
|
Types, Math, TypInfo, LCLType, LCLProc, Dialogs, Forms,
|
||||||
fpsStrings, fpsUtils, fpsNumFormat;
|
fpsStrings, fpsUtils, fpsNumFormat, fpsHTMLUtils;
|
||||||
|
|
||||||
{@@ ----------------------------------------------------------------------------
|
{@@ ----------------------------------------------------------------------------
|
||||||
Registers the spreadsheet components in the Lazarus component palette,
|
Registers the spreadsheet components in the Lazarus component palette,
|
||||||
@@ -1577,6 +1579,7 @@ end;
|
|||||||
constructor TsCellEdit.Create(AOwner: TComponent);
|
constructor TsCellEdit.Create(AOwner: TComponent);
|
||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
|
FShowHTMLText := True;
|
||||||
WantReturns := false;
|
WantReturns := false;
|
||||||
WantTabs := false;
|
WantTabs := false;
|
||||||
AutoSize := true;
|
AutoSize := true;
|
||||||
@@ -1748,6 +1751,14 @@ begin
|
|||||||
Lines.Text := FormatDateTime('ddddd', ACell^.DateTimevalue)
|
Lines.Text := FormatDateTime('ddddd', ACell^.DateTimevalue)
|
||||||
else // both
|
else // both
|
||||||
Lines.Text := FormatDateTime('c', ACell^.DateTimeValue);
|
Lines.Text := FormatDateTime('c', ACell^.DateTimeValue);
|
||||||
|
cctUTF8String:
|
||||||
|
if FShowHTMLText then
|
||||||
|
begin
|
||||||
|
RichTextToHTML(Workbook, Worksheet.ReadCellFont(ACell),
|
||||||
|
ACell^.UTF8StringValue, ACell^.RichTextParams, s);
|
||||||
|
Lines.Text := s;
|
||||||
|
end else
|
||||||
|
Lines.Text := ACell^.UTF8StringValue;
|
||||||
else
|
else
|
||||||
Lines.Text := Worksheet.ReadAsUTF8Text(ACell);
|
Lines.Text := Worksheet.ReadAsUTF8Text(ACell);
|
||||||
end;
|
end;
|
||||||
|
Reference in New Issue
Block a user