Forum > Windows

Clipboard formatted text

(1/1)

Paolo:
The attempt is to copy text in clipboard with "Tab" separator for successive Ctrl+V in word document, then selecting it inside Word add a grid around that text.
I did the code below and this works


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---var  StrGrdExc : TStringGrid; procedure TFrmMain.ToolButton4Click(Sender: TObject);var  iR, iC : integer;  Str1 : string;begin  Clipboard.AsText:='';  for iR:=1 to StrGrdExc.RowCount-1 do begin    Str1:='';    for iC:=1 to StrGrdExc.ColCount-1 do begin      Str1:=Str1+StrGrdExc.Cells[iC, iR];      if iC <> StrGrdExc.ColCount-1 then        Str1:=Str1+#9    end;    Clipboard.AsText:=Clipboard.AsText+Str1+#13#10;  end;end;  
is that the right way to do that ?

(Windows 10, LAZ 2.0.12, FPC 3.0.2)

thank you in advance.

wp:
I would use a temporary string variable rather than repeatedly calling Clipboard.AsText.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---procedure TFrmMain.ToolButton4Click(Sender: TObject);var  clipboardStr: String;  ...begin  clipboardStr := '';  for iR := 1 to StdGrdExc.RowCount-1 do begin    ...    clipboardStr := clipboardStr + Str1 + LineEnding;  end;  Clipboard.AsText := clipboardStr;end;

Paolo:
thanks, the updated code working perfectly.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- procedure TFrmMain.ToolButton4Click(Sender: TObject);var  iR, iC : integer;  Str1 : string;begin  Str1:='';  for iR:=1 to StrGrdExc.RowCount-1 do begin    for iC:=1 to StrGrdExc.ColCount-1 do begin      Str1:=Str1+StrGrdExc.Cells[iC, iR];      if iC <> StrGrdExc.ColCount-1 then        Str1:=Str1+#9    end;    Str1:=Str1+LineEnding;  end;  ClipBoard.AsText:=Str1end; 

Navigation

[0] Message Index

Go to full version