当前位置:网站首页>如何将Excel中的数据粘贴到cxGrid中
如何将Excel中的数据粘贴到cxGrid中
2022-07-17 01:31:00 【蝈蝈(GuoGuo)】
本文介绍了如何将Excel中的数据粘贴到cxGrid中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个Delphi应用程序使用DevExpress cxGrid(连接到数据库)。
我需要能够将Excel中的数据复制到网格中。
这可能吗?如果是这样,怎么做,我需要哪些额外的组件?
解决方案
使用 Clipboard.HasFormat(CF_TEXT)检查格式
使用 Clipboard.AsText 提取文本。
拆分为 StringList.Text:= Clipboard.AsText 的行。字符串列表中的每个项目现在是剪贴板中的一行。
使用拆分功能将每行拆分为单独的单元格:
function Split(const s:string; Separator:char):TStringDynArray; var i,ItemIndex:Integer; len:整数; SeparatorCount:Integer; 开始:整数; begin len:=长度; 如果len = 0,则开始结果:= nil; 退出; 结束 SeparatorCount:= 0; for i:= 1 to len do begin if s [i] = Separator then begin inc(SeparatorCount); 结束结束 SetLength(Result,SeparatorCount + 1); ItemIndex:= 0; 开始:= 1; for i:= 1 to len do begin 如果s [i] =分隔符然后开始结果[ItemIndex]:=复制(s,开始,我开始); inc(ItemIndex); 开始:= i + 1; 结束结束结果[ItemIndex]:=复制(s,开始,len-start + 1); 结束 I have a Delphi application using DevExpress cxGrid (which is connected to database).
I require to be able to copy-paste data from Excel into the grid.
Is this possible? If so, how to do it, which additional components do i need?
解决方案
Check the format with Clipboard.HasFormat(CF_TEXT).
Extract the text with Clipboard.AsText.
Split into rows with StringList.Text := Clipboard.AsText. Each item in the string list is now a row from the clipboard.
Split each row into individual cells using a Split function:
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 begin
if s[i]=Separator then begin
inc(SeparatorCount);
end;
end;
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;
这篇关于如何将Excel中的数据粘贴到cxGrid中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
边栏推荐
- Es6 notes d'étude - station B Xiao Ma Ge
- Oracle queries the host name and the corresponding IP address
- [MySQL] MHA high availability
- Vscode+ros2 environment configuration
- D. Permutation restoration (greedy / double pointer /set)
- Ncnn thread
- Wdog and power mode of fs32k148 commissioning
- Theoretical basis and code implementation of dueling dqn [pytoch + pendulum-v0]
- leetcode:50. Pow(x, n)
- In depth understanding of machine learning - unbalanced learning: sample sampling technology - [adasyn sampling method of manual sampling technology]
猜你喜欢

Wechat applet -- Summary of problems in the actual development of taro framework

MySQL interview questions (2022)

Transaction and storage engine in MySQL database

Through openharmony compatibility evaluation, the big brother development board and rich teaching and training resources have been ready

Vs code problem: launch:program '... \ vscode\launch. exe‘ dose not exist

S32k148evb about eNet loopback experiment

通过Dao投票STI的销毁,SeekTiger真正做到由社区驱动

Data source object management (third-party object resources) & load properties file

IEEE754 standard floating point format

Labelme starts normally, but cannot be opened
随机推荐
Face key point detection
Rhce8 Study Guide Chapter 2 use of basic commands
Display zabbix6.0 information using grafana8.5.2
[template record] string hash to judge palindrome string
IEEE754 standard floating point format
In depth understanding of machine learning - unbalanced learning: sample sampling technology - [smote sampling method and borderline smote sampling method of manual sampling technology]
The fifth day of the third question of Luogu daily
Theoretical basis of double Q-learning and its code implementation [pendulum-v0]
2002 - Can‘t connect to server on ‘127.0.0.1‘ (36)
leetcode:78. 子集
Unity solves the problem of Z-fighting caused by overlapping objects with the same material
第二章 线性表
Leetcode: multiple knapsack problem in dynamic programming [one template solves all ~]
mysqldump: [Warning] Using a password on the command line interface can be insecure.
Dive Into Deep Learning——2.2数据预处理
Yolov5 ncnn reasoning
Pure virtual function
oracle 查询非自增长分区的最大分区
Ubuntu clear CUDA cache
[NoSQL] redis high availability and persistence