【问题标题】:Delphi and Excel - Using AutofillDelphi 和 Excel - 使用自动填充
【发布时间】:2017-03-23 11:29:55
【问题描述】:

在 Delphi 10 / 西雅图,使用 Excel 2013... 我正在尝试:

  • 添加一列(AJ 列),并设置其标题文本(代码有效)
  • 将第 2 行的列值设置为 AutoSum(代码有效)
  • 将计算从第 2 行复制到所有剩余行。 (不起作用)

在“复制计算”步骤中,我使用的是 AutoFill 方法。我收到错误“范围类的自动填充方法失败。”但我不知道为什么......(请注意,变量 aws 被全局设置为活动工作表。)

        const
        TOTAL_TOUCHES = 'AJ';
        ...

    var
            ColumnHeader : OleVariant;
            SecondRow    : OleVariant;
            ColRange     : OleVariant;
            myAddr, myAddr2 : String;
            LastCell : string;

begin
              // This routine adds the header 'Total Touches' and then puts an AutoSum in that column for all rows
              // Set the header
              myAddr := TOTAL_TOUCHES + '1';
              ColumnHeader := aws.Range[ myAddr, myAddr];
              ColumnHeader.FormulaR1C1 := 'Total Touches';

              // Put the first occurance of the Autosum in Row 2
              myAddr := TOTAL_TOUCHES + '2';
              SecondRow := aws.Range[ myAddr, myAddr];
              SecondRow.FormulaR1C1 := '=SUM(RC[-6]:RC[-1])';


               SecondRow.Autofill(aws.range['AJ3:AJ50', EmptyParam], xlFillCopy);

一旦它开始工作,我会将它设置为复制到行中的所有列(与 AJ3:AJ50 不同,但这是一个小步骤......

我做错了什么?

【问题讨论】:

    标签: excel delphi com autofill


    【解决方案1】:

    The documentation 表示AutoFill 的目标参数,即第一个参数,“必须包括源范围”。在您的情况下,源范围是 AJ2,但 AJ3:AJ50 不包括该单元格。

    【讨论】:

    • 就是这样!谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-23
    • 1970-01-01
    • 1970-01-01
    • 2017-07-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多