gpt4 book ai didi

excel - 如何访问 Excel 中的一系列行?

转载 作者:行者123 更新时间:2023-12-03 00:07:34 26 4
gpt4 key购买 nike

我正在尝试将此 Excel VBA 代码转换为 Delphi:

ActiveSheet.Rows(r & ":5000").WrapText = True
ActiveSheet.Rows(r & ":5000").AutoFit

但是在Delphi的Excel2010单元中_Worksheet.Rows是一个对象,而不是函数或数组对象,我也找不到任何Items 属性或类似属性。

uses
Excel2010;

procedure Test;
var
Sheet: ExcelWorksheet;
R: Integer;
begin
R := 3;
Sheet.Rows[R.ToString + ':5000'].WrapText := True;
// Sheet.Rows.WrapText := True;
end;

编译器消息是:

[dcc32 Error] Unit1.pas(110): E2149 Class does not have a default property

VBA 代码的正确翻译是什么?

如何访问 Excel 中的特定范围的行?

最佳答案

通过早期绑定(bind),选择 A 列(第 3..5000 行)并使用 EntireRow,例如如下所示:

uses Excel2010;

procedure TForm14.Button1Click(Sender: TObject);
var
Excel: ExcelApplication;
Wbook: ExcelWorkbook;
Sheet: ExcelWorksheet;
begin
Excel := CoExcelApplication.Create;
Wbook := Excel.Workbooks.Add(EmptyParam, LOCALE_USER_DEFAULT);
Sheet := Wbook.ActiveSheet as ExcelWorksheet;

Excel.Visible[LOCALE_USER_DEFAULT] := True;

Sheet.Range['A3','A5000'].EntireRow.WrapText := True;
Sheet.Range['A3','A5000'].EntireRow.AutoFit;

//...
end;

关于excel - 如何访问 Excel 中的一系列行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52477696/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com