I'm trying to select the "used range". I get the worksheet's UsedRange, then I invoke the Select function on it. I receive HRESULT 0x800a03ec on the select call.
我正在尝试选择“使用范围”。我得到工作表的UsedRange,然后我调用它上面的Select函数。我在select call上收到HRESULT 0x800a03ec。
Here's the code:
这是代码:
COleVariant result;
HRESULT hr = AutoWrap(DISPATCH_METHOD, &result, irange, L"Select", 0);
HRESULT hr = AutoWrap(DISPATCH_METHOD,&result,irange,L“Select”,0);
I won't bother posting the code for the AutoWrap function (unless someone asks). It's pretty well-known and I haven't modified it.
我不打算发布AutoWrap功能的代码(除非有人问)。这是众所周知的,我没有修改它。
I'm pretty sure that irange is good, because I tried some calls on it to verify that it has what I expect, and it does. If I iterate through it, I can see the content of each cell (and it's correct); the number of rows and columns returned is correct, and the "Address" property returned checks out.
我很确定irange是好的,因为我尝试了一些调用来验证它是否符合我的预期,而且确实如此。如果我遍历它,我可以看到每个单元格的内容(并且它是正确的);返回的行数和列数是正确的,返回的“Address”属性检出。
Worksheet is not locked.
工作表未锁定。
I've seen other problems posted having to do with Locale, and my system is set to U.S. English as is my user account. Neither has been changed.
我发现其他问题与Locale有关,我的系统设置为美国英语,我的用户帐户也是如此。两者都没有改变。
Hope someone can help!
希望有人可以帮忙!
Update: I have also tried
更新:我也试过了
hr = iRange->Select(vResult);
This does return S_OK, but it does not select the range. Normally, I can't directly call the functions in the iRange struct; the result is a gpf or access violation -- so I have to use the autowrap function (to drive an Invoke call). I'm not surprised this call doesn't work.
这确实返回S_OK,但它没有选择范围。通常,我不能直接调用iRange结构中的函数;结果是gpf或访问冲突 - 所以我必须使用autowrap函数(来驱动一个Invoke调用)。这个电话不起作用我并不感到惊讶。
I have also tried opening the excel file in non-ReadOnly mode, in case I was locked. This didn't fix the problem. I can select individual cells by getting a single item (cell) from the range, and calling its Select, but I can't select the range.
我还尝试在非ReadOnly模式下打开excel文件,以防我被锁定。这并没有解决问题。我可以通过从范围中获取单个项目(单元格)来选择单个单元格,并调用其选择,但我无法选择范围。
1 个解决方案
#1
3
I found the answer to this question. This only appears to be a problem when used in the DSOFRAMER sample (Microsoft KB 311765). DSOFramer is a general purpose ActiveX control for embedding MS Office documents. The problem also only happens in a debug build; release builds are fine.
我找到了这个问题的答案。在DSOFRAMER示例(Microsoft KB 311765)中使用时,这似乎只是一个问题。 DSOFramer是用于嵌入MS Office文档的通用ActiveX控件。问题也只发生在调试版本中;发布版本很好。
I also found a workaround that works on release or debug build: get any cell in the range (using get_Item), then call select on that item, then select again to de-select it. Once that's done, the select can be called on the range. Apparently, select cannot be called on the range if there is a cell already selected (or perhaps if the selection state is undefined).
我还发现了一个适用于发布或调试版本的解决方法:获取范围内的任何单元格(使用get_Item),然后调用该项目上的select,然后再次选择以取消选择它。完成后,可以在范围上调用选择。显然,如果已经选择了一个单元格(或者如果选择状态未定义),则无法在该范围上调用select。
#1
3
I found the answer to this question. This only appears to be a problem when used in the DSOFRAMER sample (Microsoft KB 311765). DSOFramer is a general purpose ActiveX control for embedding MS Office documents. The problem also only happens in a debug build; release builds are fine.
我找到了这个问题的答案。在DSOFRAMER示例(Microsoft KB 311765)中使用时,这似乎只是一个问题。 DSOFramer是用于嵌入MS Office文档的通用ActiveX控件。问题也只发生在调试版本中;发布版本很好。
I also found a workaround that works on release or debug build: get any cell in the range (using get_Item), then call select on that item, then select again to de-select it. Once that's done, the select can be called on the range. Apparently, select cannot be called on the range if there is a cell already selected (or perhaps if the selection state is undefined).
我还发现了一个适用于发布或调试版本的解决方法:获取范围内的任何单元格(使用get_Item),然后调用该项目上的select,然后再次选择以取消选择它。完成后,可以在范围上调用选择。显然,如果已经选择了一个单元格(或者如果选择状态未定义),则无法在该范围上调用select。