【发布时间】: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 不同,但这是一个小步骤......
我做错了什么?
【问题讨论】: