Excel 插件 - Delphi 相当于 VB
我正在将一个 Excel 插件从 Visual VB 移植到 Delphi 2006。它的大部分工作正常,但我被困在这两条 VB 行上:
oXL.Selection.QueryTable
oXL.Selection <> ""
其中 oXL 被定义为 Excel.Application。
在 Delphi ExcelApplication.Selection 中需要索引,但在 VB 中不需要。我在 C# 中也找不到类似的东西。我尝试过 ExcelApplication.ActiveCell,只要存在现有查询,它就可以工作,否则 Excel 会崩溃。
有谁知道这对 Delphi 或 C# 意味着什么?
另外,如果 oXL.Selection 是一个接口,那么如何执行 oXL.Selection <> “”?
谢谢。
I'm porting an Excel add-in from visual VB to Delphi 2006. Most of it is working but I am stuck on these two VB lines:
oXL.Selection.QueryTable
oXL.Selection <> ""
where oXL is defined as Excel.Application.
In Delphi ExcelApplication.Selection requires an index but in VB it doesn't. I couldn't find anything similar in C# either. I have tried ExcelApplication.ActiveCell which works as long as there is an existing query, otherwise Excel crashes.
Does anyone know what this translates into for Delphi, or C#?
Also if oXL.Selection is an interface, how can you perform oXL.Selection <> ""?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
当使用接口从 Delphi 自动化 Excel 时,许多方法都采用 LCID。您可以使用
LOCALE_USER_DEFAULT
来实现此目的。When automating Excel from Delphi using interfaces, a lot of methods take a LCID. You can use
LOCALE_USER_DEFAULT
for that.不用担心,我忘记了您可以将应用程序 IDispatch 接口强制转换为 OleVariant,然后调用该方法。
但我所做的只是以下
这似乎是使其工作而不崩溃 Excel 的唯一方法。
No worries, I had forgotten that you can just cast the application IDispatch interface to an OleVariant and then call the method.
But what I've done instead is just the following
This seems to be the only way to make it work without crashing excel.
这个问题我已经遇到过很多次了,解决办法很简单。
始终使用
0
作为 localeID,一切都会正常工作。这将使 Excel 填充其默认区域设置。
您可以使用变体,然后就不会遇到此要求,但在这种情况下:
请注意,
selection
与cells
一样返回一个 IDispatch,您必须将其转换为 Olevariant,才能使用它。在 VBA 中也会发生同样烦人的事情,只不过强制转换是隐式的。
I've run across this problem a lot of times, the solution is very simple.
Always use
0
for the localeID and everything will work as excepted.This will make Excel fill in its default locale.
You can use variants and then you don't suffer this requirement, but in that case:
Note that
selection
, likecells
returns a IDispatch, that you have to cast to a Olevariant, in order to work with it.The same annoying thing happens in VBA, except there the cast is implicit.