Copying table data from clipboard into RichView table
Posted: Thu Jan 11, 2007 3:39 pm
Hi!
RichViewEdit's default behaviour when copying table (Excel/Word) from clipboard into table seems to be creating new table inside currently edited table cell.
Is there a simple way to copy table data from clipboard into richview table cell by cell?
I tried to bypass the problem by using template, hidden RichViewEdit, into which I paste data from clipboard, search for table, than try to copy cell data for each cell from template RichViewEdit to visible RichViewEdit. It throws "access violation" in one of the richview units (it does not happen in procedure bellow nor in any of my units). Can anybody tell me what am I doing wrong?
My RichView version is 1.9.15
LP, Primoz
p.s. I call following procedure in OnPaste event of RichViewEdit, after setting DoDefault variable to false.
[/code]
RichViewEdit's default behaviour when copying table (Excel/Word) from clipboard into table seems to be creating new table inside currently edited table cell.
Is there a simple way to copy table data from clipboard into richview table cell by cell?
I tried to bypass the problem by using template, hidden RichViewEdit, into which I paste data from clipboard, search for table, than try to copy cell data for each cell from template RichViewEdit to visible RichViewEdit. It throws "access violation" in one of the richview units (it does not happen in procedure bellow nor in any of my units). Can anybody tell me what am I doing wrong?
My RichView version is 1.9.15
LP, Primoz
p.s. I call following procedure in OnPaste event of RichViewEdit, after setting DoDefault variable to false.
Code: Select all
procedure TfmeTableNew.PasteExcelTableDataIntoRVTable;
var
tmpTable: TRVTableItemInfo;
tmpTablePasted: TRVTableItemInfo;
intRow, intCol: integer;
intRowIndex, intColIndex: integer;
MS: TMemoryStream;
oldps, oldts: TRVFReaderStyleMode;
UnusedColor: TColor;
begin
UnusedColor := clNone;
rve.BeginUpdate;
try
try
tmpRVE.Clear;
tmpRVE.Paste;
tmpTable := GetTableObject(rve);
tmpTablePasted := GetTableObject(tmpRVE);
if tmpTable = nil then exit
else begin
if (tmpTable.GetEditedCell(intRow, intCol)) <> nil then begin
if tmpTablePasted <> nil then begin
oldps := rve.RVFParaStylesReadMode;
oldts := rve.RVFTextStylesReadMode;
rve.RVFParaStylesReadMode := rvf_sIgnore;
rve.RVFTextStylesReadMode := rvf_sIgnore;
SendMessage(rve.Handle, WM_SETREDRAW, 0, 0);
try
intRowIndex := 0;
while intRowIndex < tmpTablePasted.Rows.Count do begin
intColIndex := 0;
while intColIndex < tmpTablePasted.Rows[intRowIndex].Count do begin
if (tmpTablePasted.Cells[intRowIndex, intColIndex] <> nil) and
(tmpTable.Cells[intRow + intRowIndex, intCol + intColIndex] <> nil) then begin
MS := TMemoryStream.Create;
try
tmpTablePasted.Cells[intRowIndex, intColIndex].GetRVData.SaveRVFToStream(ms, False, UnusedColor, nil, nil);
ms.Position := 0;
tmpTable.Cells[intRow + intRowIndex, intCol + intColIndex].Edit;
rve.TopLevelEditor.SelectAll;
rve.TopLevelEditor.InsertRVFFromStreamEd(ms);
finally
MS.Free;
end;
end;
Inc(intColIndex);
end;
Inc(intRowIndex);
end;
finally
rve.RVFParaStylesReadMode := oldps;
rve.RVFTextStylesReadMode := oldts;
SendMessage(rve.Handle, WM_SETREDRAW, 1, 0);
while rve <> nil do begin
rve.Invalidate;
rve := TRichViewEdit(rve.InplaceEditor);
end;
end;
end
else begin
rve.PasteText;
end;
end;
end;
except
on e: Exception do
ShowMessage('Error copying data '+e.Message);
end;
finally
rve.EndUpdate;
rve.ClearUndo;
end;
end;