delphi 复制粘贴excel的单元格内容到stringgrid

delphi xe10.4.2, window 10, excel 2016

从stringgrid复制到粘贴板时,如果stringgrid的单元格内有换行的话,或者有双引号,或者有逗号,空格的话,都需要在字符串的前后加上双引号,并且行内的换行符替换为#10,因为delphi认可#13#10,而excel用#10表示换行", 

Procedure CopySelectCells(sg: tstringgrid);
var
    i, j: integer;
    s, s2, cellStr: string;
begin
    clipboard.Clear;
    clipboard.Open;
    s2 := '';
    for i := sg.Selection.Top to sg.Selection.Bottom do
    begin
        s := '';
        for j := sg.Selection.Left to sg.Selection.Right do
        begin
            cellStr := sg.Cells[j, i];
            // 需要循环把字符串中双引号重复一次
            // cellStr := stringreplace(cellStr, '"', '""',
            // [rfignorecase, rfReplaceAll]);
            // 当读取commatext时,如果字符串中有空格,逗号和引号的话,都会在首尾加上双引号。
            // When retrieving CommaText, any string in the list that include spaces, commas 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值