Skip to content
GitLab
    • GitLab: the DevOps platform
    • Explore GitLab
    • Install GitLab
    • How GitLab compares
    • Get started
    • GitLab docs
    • GitLab Learn
  • Pricing
  • Talk to an expert
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
    • Switch to GitLab Next
    Projects Groups Snippets
  • Sign up now
  • Login
  • Sign in / Register
  • Lazarus Lazarus
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
    • Locked Files
  • Issues 2,112
    • Issues 2,112
    • List
    • Boards
    • Service Desk
    • Milestones
    • Iterations
  • Merge requests 14
    • Merge requests 14
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
    • Test Cases
  • Deployments
    • Deployments
    • Releases
  • Packages and registries
    • Packages and registries
    • Container Registry
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Code review
    • Insights
    • Issue
    • Repository
  • External wiki
    • External wiki
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • FPC
  • LazarusLazarus
  • LazarusLazarus
  • Issues
  • #30623
Closed
Open
Issue created Sep 20, 2016 by FPC Admin account@fpc_adminOwner

TStringGrid copy/paste to/from MS Excel and OO Calc bug

Original Reporter info from Mantis: K155LA3
  • Reporter name:

Description:

When copy cell with quote symbol procedure TCustomStringGrid.CopyCellRectToClipboard get string as " but after function QuoteText it will converted to """".
When paste from clipboard to StringGrid it set cell data to ".
When paste from clipboard to OO Calc it set cell data to "".

When copy cell with " from OO Calc clipboard contained this data: "# 13#10
When paste from clipboard to StringGrid it clear cell data (make empty cell).
When paste from clipboard to OO Calc it set cell data to ".

Symbol "1" in cell:
StringGrid -> clipboard = """1"""# 13# 10
OO Calc -> clipboard = "1"# 13# 10
MS Excel -> clipboard = "1"# 13# 10

StringGrid -> MS Excel = "1"
StringGrid -> OO Calc = ""1""

OO Calc -> MS Excel = "1"
MS Excel -> OO Calc = "1"

But...

When I copy "1"# 13# 10 to clipboard from text file:

clipboard -> StringGrid = 1
clipboard -> OO Calc = 1
clipboard -> MS Excel = 1

When I copy """1"""# 13# 10 to clipboard from text file:

clipboard -> StringGrid = "1"
clipboard -> OO Calc = ""1""
clipboard -> MS Excel = "1"

If fill 3x3 cells in Excel and Calc:
1 1 1
1 1 1
1 1 1

And fill 3x3 cells in StringGrid:
2 2 2
2 2
2

And copy it from StringGrid and paste for replace cells:
Excel:
2 2 2
2 2
2
Calc:
2 2 2
2 2 1
2 1 1

If copy 3x3 cells from Excel:
2 2 2
2 2
2
And paste it to Calc:
2 2 2
2 2
2

Steps to reproduce:

1 Place StringGrid to form.
2 Set in Options goEditing.
3 Run programm.
4 Place symbol " in one cell
5 Try copy/paste to/from MS Excel or OO Calc.
6 Fill 3x3 cell as above.
7 Try copy/paste to/from MS Excel or OO Calc.

Additional information:

MS Excel and OO Calc when copy cells to clipboard set this clipboard flag:

CF_Text = True
CF_Bitmap = False
CF_Picture = True
CF_MetaFilePict = False
CF_Object = False
CF_Component = False
CF_HTML = True

If CF_HTML = True then, MS Excel and OO Calc ignore text data and parse HTML data from clipboard.

Fix (only copy cells from StringGrid to Excel/Calc):

procedure TCustomStringGrid.CopyCellRectToClipboard(const R: TRect);
var
-  SelStr: String;
+  SelStr, SelHTMLStr: String;
+  rflags: TReplaceFlags;
  aRow,aCol,k: LongInt;
  function QuoteText(s: string): string;
  begin
    DoCellProcess(aCol, aRow, cpCopy, s);
    if (pos(#9, s)>0) or
       (pos(#10, s)>0) or
       (pos(#13, s)>0) or
       (pos('"', s)>0)
    then
      result := AnsiQuotedStr(s, '"')
    else
      result := s;
  end;
begin
  SelStr := '';
+  SelHTMLStr := '<table>';
  for aRow:=R.Top to R.Bottom do begin
+    SelHTMLStr := SelHTMLStr + '<tr>';

    for aCol:=R.Left to R.Right do begin

      if Columns.Enabled and (aCol>=FirstGridColumn) then begin

        k := ColumnIndexFromGridColumn(aCol);
        if not Columns[k].Visible then
          continue;

if (aRow=0) and (FixedRows>0) then
- SelStr := SelStr + QuoteText(Columns[k].Title.Caption)
+ begin
+ SelStr := SelStr + QuoteText(Columns[k].Title.Caption);
+ SelHTMLStr := SelHTMLStr + '&LtPos;td>' + Columns[k].Title.Caption + '&LtPos;/td>';
+ end
else
+ begin
SelStr := SelStr + QuoteText(Cells[aCol,aRow]);
+ SelHTMLStr := SelHTMLStr + '&LtPos;td>' + Cells[aCol,aRow] + '&LtPos;/td>';
+ end;

end else
+ begin
SelStr := SelStr + QuoteText(Cells[aCol,aRow]);
+ SelHTMLStr := SelHTMLStr + '&LtPos;td>' + Cells[aCol,aRow] + '&LtPos;/td>';
+ end;

      if aCol<>R.Right then
        SelStr := SelStr + #9;
    end;

SelStr := SelStr + sLineBreak;
+ SelHTMLStr := SelHTMLStr + '&LtPos;/tr>';
end;
+ rflags := [rfReplaceAll, rfIgnoreCase];
+ SelHTMLStr := StringReplace(SelHTMLStr, '"', '"', rflags) + '&LtPos;/table>';
- Clipboard.AsText := SelStr;
+ Clipboard.SetAsHtml(SelHTMLStr, SelStr);
end;

P.S.: To fix paste cells from Excel/Calc to StringGrid I think that need to parse HTML clipboard content in procedure TCustomStringGrid.SelectionSetText(TheText: String) or remove function QuoteText from procedure TCustomStringGrid.CopyCellRectToClipboard and correct operations with quote symbol in procedure LoadFromCSVStream.

Mantis conversion info:

  • Mantis ID: 30623
  • OS: Windows
  • OS Build: 7
  • Build: rev. 52995
  • Version: 1.7 (SVN)
  • Fixed in version: 2.1 (SVN)
  • Fixed in revision: 54001 (#14145bdd), 59960 (#ecffcbf5)
  • Target version: 2.0
Assignee
Assign to
Time tracking