gpt4 book ai didi

excel - Delphi 导出到 Excel - IDE 中编译代码的错误错误

转载 作者:行者123 更新时间:2023-12-04 20:03:37 25 4
gpt4 key购买 nike

在 Delphi 10.3.3 中为 Excel 编码时,我在 IDE 中收到错误错误,因为代码编译和工作得很好。
错误消息...

Undeclaired identifier 'Range' at line xxx
Undeclaired identifier 'Cells' at line xxx
...对于两个 excel 变量的每次出现。
这是完整的代码:
procedure tmainform.ExportToExcel;
var
xls, wb, MyRange, CompletionRow: OLEVariant;
arrData: Variant;
ColCount, CurrRow, CurrCol: Integer;
begin
ColCount:= 6;
arrData:= VarArrayCreate([1, TotOrders+1, 1, ColCount], varVariant);

for CurrCol:= 1 to ColCount do case currcol of
1: arrData[1,1]:= 'ORDER#';
2: arrData[1,2]:= 'DATE';
3: arrData[1,3]:= 'ITEM';
4: arrData[1,4]:= 'QTY';
5: arrData[1,5]:= 'COST';
6: arrData[1,6]:= 'RECEIVED?';
end;

for CurrRow:= 1 to TotOrders do begin
for CurrCol:= 1 to ColCount do begin
case currcol of
1: arrData[CurrRow+1,1]:= Orders[1].Number;
2: arrData[CurrRow+1,2]:= Orders[2].Date;
3: arrData[CurrRow+1,3]:= Orders[3].Name;
4: arrData[CurrRow+1,4]:= Orders[4].Qty;
5: arrData[CurrRow+1,5]:= Orders[5].Cost;
6: arrData[CurrRow+1,6]:= Orders[6].Received;
end;
end;
end;

xls:= CreateOLEObject('Excel.Application');
wb:= xls.Workbooks.Add;
{THIS LINE} MyRange:= wb.WorkSheets[1].Range[wb.WorkSheets[1].Cells[1, 1],wb.WorkSheets[1].Cells[TotOrders+1, ColCount]]; // THIS LINE
MyRange.Value:= arrData;
MyRange.EntireColumn.Autofit;
{THIS LINE} CompletionRow:= wb.WorkSheets[1].Range[wb.WorkSheets[1].Cells[1, 1],wb.WorkSheets[1].Cells[1, ColCount]]; // THIS LINE
CompletionRow.font.bold := true;
{THIS LINE} CompletionRow:= wb.WorkSheets[1].Range[wb.WorkSheets[1].Cells[2, 5],wb.WorkSheets[1].Cells[TotOrders+1, 5]]; // THIS LINE
CompletionRow.NumberFormat:= '$#,##0.00';
xls.Visible:= True;
xls.ActiveWindow.Activate;
end;
全局变量是:
  Orders: array of ordertype;
TotOrders: integer;
同样,这段代码运行得很好,但我想摆脱那些总是显示在左上角的虚假错误。
fake errors - code compiles

最佳答案

这是 Delphi 中的一个已知错误。除了升级到版本“10.4 Sydney”(或更高版本)Reference 之外,您无能为力.

关于excel - Delphi 导出到 Excel - IDE 中编译代码的错误错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63660950/

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