增加剪贴板内容复杂到 cxgrid表格中
This commit is contained in:
parent
d48f5f7110
commit
7d605e0d94
|
@ -4,7 +4,7 @@ interface
|
|||
|
||||
uses
|
||||
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
|
||||
Dialogs, ComCtrls, ToolWin, StdCtrls, BtnEdit, cxStyles, cxCustomData,
|
||||
Dialogs, ComCtrls, ToolWin, StdCtrls, BtnEdit, cxStyles, cxCustomData,System.Types,
|
||||
cxGraphics, cxFilter, cxData, cxDataStorage, cxEdit, DBGrids, DB, cxDBData,
|
||||
cxGridLevel, cxClasses, cxControls, cxGridCustomView, ADODB, StrUtils, Midas,
|
||||
cxGridCustomTableView, cxGridTableView, cxGridDBTableView, cxTimeEdit,
|
||||
|
@ -20,6 +20,8 @@ type
|
|||
S: string;
|
||||
end;
|
||||
|
||||
procedure pasteDatatTocxGrid(Tv1:TcxGridDBTableView);
|
||||
function Split(const s: string; Separator: char): TStringDynArray;
|
||||
// 调用DLL文件
|
||||
procedure InitDllEvt(FromFile: string; FormID: Integer; Para: string; FormType: Integer; Title: string; Def1: string; Def2: string; Def3: string; Def4: string; Def5: string; Def6: string; Def7: string; Def8: string; Def9: string; Def10: string);
|
||||
|
||||
|
@ -2699,9 +2701,12 @@ begin
|
|||
begin
|
||||
mDir := ExtractFilePath(application.ExeName) + 'Layout\' + filePack;
|
||||
mFileName := mDir + '\' + Trim(fileName) + '.dbg';
|
||||
|
||||
//从布局文件中恢复
|
||||
if FileExists(mFileName) then
|
||||
begin
|
||||
cxGrid.RestoreFromIniFile(mFileName, false, false);
|
||||
end;
|
||||
exit;
|
||||
end;
|
||||
|
||||
|
@ -2741,7 +2746,8 @@ begin
|
|||
begin
|
||||
//cxgrid.find
|
||||
mcxGridDbColumn1 := cxGrid.GetColumnByFieldName(trim(fieldByName('fieldName').asstring));
|
||||
if (mcxGridDbColumn1 <> nil) and (lowercase(mcxGridDbColumn1.Name) = lowercase(trim(fieldByName('columnName').asstring))) then
|
||||
|
||||
if (mcxGridDbColumn1 <> nil) then //and (lowercase(mcxGridDbColumn1.Name) = lowercase(trim(fieldByName('columnName').asstring)))
|
||||
begin
|
||||
mcxGridDbColumn1.Visible := fieldByName('Visible').AsBoolean;
|
||||
mcxGridDbColumn1.Width := fieldByName('width').asInteger;
|
||||
|
@ -3922,5 +3928,99 @@ begin
|
|||
end;
|
||||
|
||||
end;
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////
|
||||
/// 粘贴剪贴板中的数据到表格
|
||||
///
|
||||
procedure pasteDatatTocxGrid(Tv1:TcxGridDBTableView);
|
||||
var
|
||||
SelectedCount: Integer;
|
||||
ClipboardText: string;
|
||||
StringList: TStringList;
|
||||
RowData: TStringDynArray;
|
||||
i, j: Integer;
|
||||
startColIndex:integer;
|
||||
startrowIndex:integer;
|
||||
begin
|
||||
startColIndex:= Tv1.Controller.CellSelectionAnchor.Index;
|
||||
|
||||
// 获取剪贴板中的文本
|
||||
ClipboardText := Clipboard.AsText;
|
||||
// showMessage(inttostr(startColIndex));
|
||||
// 将文本按行拆分
|
||||
StringList := TStringList.Create;
|
||||
try
|
||||
StringList.Text := ClipboardText;
|
||||
|
||||
// 遍历每一行
|
||||
for i := 0 to StringList.Count - 1 do
|
||||
begin
|
||||
if i>tv1.Controller.SelectedRowCount-1 then break;
|
||||
|
||||
// 将每行按制表符(或其他分隔符)拆分为单元格数据
|
||||
RowData := Split(StringList[i], #9); // 假设使用制表符作为分隔符
|
||||
Tv1.Controller.FocusedRow := Tv1.Controller.SelectedRows[i];
|
||||
|
||||
// 遍历每一列,并将数据填充到cxGrid
|
||||
for j := 0 to Length(RowData) - 1 do
|
||||
begin
|
||||
if j>tv1.Controller.SelectedColumnCount-1 then break;
|
||||
|
||||
// 假设cxGrid已经初始化,且有足够的行和列
|
||||
TV1.DataController.Values[Tv1.Controller.FocusedRecordIndex, startColIndex+j] := RowData[j];
|
||||
|
||||
Tv1.DataController.DataSet.Edit;
|
||||
Tv1.DataController.DataSet.FieldByName(Tv1.Columns[startColIndex+j].DataBinding.FieldName).AsString := RowData[j];
|
||||
|
||||
TV1.Controller.EditingController.ShowEdit;
|
||||
end;
|
||||
|
||||
end;
|
||||
finally
|
||||
|
||||
StringList.Free;
|
||||
|
||||
end;
|
||||
end;
|
||||
|
||||
// 分割字符串函数
|
||||
function Split(const s: string; Separator: char): TStringDynArray;
|
||||
var
|
||||
i, ItemIndex: Integer;
|
||||
len: Integer;
|
||||
SeparatorCount: Integer;
|
||||
Start: Integer;
|
||||
begin
|
||||
len := Length(s);
|
||||
if len = 0 then
|
||||
begin
|
||||
Result := nil;
|
||||
Exit;
|
||||
end;
|
||||
|
||||
// 计算分隔符数量
|
||||
SeparatorCount := 0;
|
||||
for i := 1 to len do
|
||||
if s[i] = Separator then
|
||||
Inc(SeparatorCount);
|
||||
|
||||
SetLength(Result, SeparatorCount + 1);
|
||||
ItemIndex := 0;
|
||||
Start := 1;
|
||||
|
||||
// 拆分字符串
|
||||
for i := 1 to len do
|
||||
begin
|
||||
if s[i] = Separator then
|
||||
begin
|
||||
Result[ItemIndex] := Copy(s, Start, i - Start);
|
||||
Inc(ItemIndex);
|
||||
Start := i + 1;
|
||||
end;
|
||||
end;
|
||||
|
||||
Result[ItemIndex] := Copy(s, Start, len - Start + 1);
|
||||
end;
|
||||
end.
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user