HRESULT: 0x800A03EC on Worksheet.range

2018-12-31 14:55发布

问题:

I am getting HRESULT: 0x800A03EC on Worksheet.range method. Number of rows are more than 70K. Office 2007.

Code:

Microsoft.Office.Interop.Excel.Range neededRange
    = currentWS.Range[cell.Cells[1, 1], cell.Cells[nRowCount, nColumnCount]];

Here my rowcount is more than 65530 . Breaks on this function. I have observed that it breaks only when row count goes more than 65530.

回答1:

This problem occurs if you are using a backwards compatible sheet (a .xls) instead of a .xlsx

To allow sheets to be opened in pre office 2007 version it can\'t contain more than 65k rows. You can check the number of rows in your sheet by using ctrl+arrowdown till you hit the bottom. If you try to get a range larger than that number of rows it will create an error



回答2:

We were receiving the same. The exception was

Stacktrace: at Microsoft.Office.Interop.Excel._Workbook.SaveAs(Object Filename, Object FileFormat, Object Password, Object WriteResPassword, Object ReadOnlyRecommended, Object CreateBackup, XlSaveAsAccessMode AccessMode, Object ConflictResolution, Object AddToMru, Object TextCodepage, Object Text VisualLayout, Object Local)`

with an inner exception of

Exception from HRESULT: 0x800A03EC 2012-11-01 10:37:59`

We were able to resolve the problem with information from this post, which I quote here for convenience...

  1. Login to the server as a administrator.
  2. Go to \"Start\" -> \"Run\" and enter \"taskmgr\"
  3. Go to the process tab in task manager and check \"Show Processes from all users\"
  4. If there are any \"Excel.exe\" entries on the list, right click on the entry and select \"End Process\"
  5. Close task manager.
  6. Go to \"Start\" -> \"Run\" and enter \"services.msc\"
  7. Stop the service automating Excel if it is running.
  8. Go to \"Start\" -> \"Run\" and enter \"dcomcnfg\"
  9. This will bring up the component services window, expand out \"Console Root\" -> \"Computers\" -> \"DCOM Config\"
  10. Find \"Microsoft Excel Application\" in the list of components.
  11. Right click on the entry and select \"Properties\"
  12. Go to the \"Identity\" tab on the properties dialog.
  13. Select \"The interactive user.\"
  14. Click the \"OK\" button.
  15. Switch to the services console
  16. Start the service automating Excel
  17. Test you application again.


回答3:

I encountered this issue.

Discovered that somewhere in my code I was asking it to count starting from 0 (as you would in a C# code).

Turns out Excel counting starts at 1.



回答4:

Looking at the various responses above, and drawing on my own recent experience (I got this error code doing something completely unrelated -- setting Application.Calculation) I conclude that the same error code is used to indicate multiple unrelated problems. So @Garreh you should probably be asking a new question (not that anyone will be able to help based on the error code alone). I\'ve seen the same thing working with Word interop from C#, where the same HRESULT seems to be used for almost every kind of error. I\'ve never found any satisfactory Microsoft documentation on what the codes might mean.



回答5:

This could also be caused if you have no room on the partition you are saving to.

I checked my HD and foind it was maxed. Moving some un-needed files to a different partition resolved my problem.



回答6:

Simply, the excel file is corrupt. Best solution is change/repair the file.(make a copy of the existing file and rename it)



回答7:

I don\'t understand the issue. But here is the thing that solved my issue.

Go to Excel Options > Save > Save Files in this format > Select \"Excel Workbook(*.xlsx)\". Previously, my WorkBooks were opening in [Compatibuility Mode] And now they are opening in normal mode. Range function works fine with that.



回答8:

Just FYI, got the error trying to apply row style....

wSheet.Rows(y).Style = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Red)


回答9:

This isn\'t directly answering the question, but I was getting this error when opening an xlsx file. The problem was that I was using forward slashes in my file path. See also https://stackoverflow.com/a/24635904/5932003. It used to work in previous versions of Excel, but not with Version 1711 (Build 8730.2127).

I was able to diagnose the problem using IDispatch->Invoke(..., EXCEPINFO, ...). The EXCEPINFO object contained a useful description of what went wrong. I was in C++ land, but I suspect that C# code similar to this SO post will do the trick: Packaging IDispatch Invoke with Parameters in C# (with DISPPARAMS).



回答10:

EDIT: THIS IS WAY BETTER!!! You don\'t need that old function, sorry. Just do as follows:

Microsoft.Office.Interop.Excel.Range neededRange = currentWS.Range[\"A1\", ((Microsoft.Office.Interop.Excel.Range)currentWS.Cells[nRowCount, nColumnCount])];

That should work like a charm. And for future reference, put the relevant code that you are using inside of your question. Don\'t make people ask for it in comments. I imagine that\'s why you got downvoted.



回答11:

I had an error with exact code when I tried to assigned array of cells to range.Value. In my case it was the problem with wrong data format. The cell\'s data format was set as DATE but the user made an error and instead of \"20.02.2013\" entered date \"20.02.0213\". The Excel\'s COM object refused taking year \'0213\' and threw exception with this error.



回答12:

I also faced the same issue, when I was developing a application which exports project contents into excel file.

I could not found the resolution in forums for my problem, then I check the maximum capacity of excel and found below link which says

\"Worksheet size 1,048,576 rows by 16,384 columns\" and this was the issue in my case, I was exporting more than that rows. Refer below link for details

http://answers.microsoft.com/en-us/office/forum/office_2013_release-excel/with-excel-2013how-many-rows-will-this-contain/271264fb-3ab8-4c5b-aa0d-7095c5ac6108

Regards Prashant Neve



回答13:

Not being able to reply to/endorse this answer, so posting here:

Indeed, the format of the source/destination ranges when moving data from one range to another might cause this error as well.

In my case, the range I wanted to copy contained a date formatted column, and the column contained one cell with an invalid date value (it was not even formatted due to its value, which was a negative integer). So the copy operation between the two ranges was halting at the said cell yielding the very error message discussed here.

The solution in my case was to use Range.Value2 instead of Range.Value, which caused Excel to bypass formatting the cell as a date (more details here). However, this will render your date and time columns to display as integers and decimals. You will, however, be able to change the formats to the desired ones if you know where to expect the date and time values by setting their Range/Column/Cell.NumberFormat property accordingly.



回答14:

I had the same error code when executing the following statement:

sheet.QueryTables.Add(\"TEXT\" & Path.GetFullPath(fileName), \"1:1\", Type.Missing)

The reason was the missing semicolon (;) after \"TEXT\".

Here is the correct one:

sheet.QueryTables.Add(\"TEXT;\" & Path.GetFullPath(fileName), \"1:1\", Type.Missing)


回答15:

I got this exception because I typed:

ws.get_Range(\"K:K\").EntireColumn.AutoFit();
ws.get_Range(\"N:N\").EntireColumn.AutoFit();
ws.get_Range(\"0:0\").EntireColumn.AutoFit();

See a mistake? Hint: Excel is accepting indexing from 1, but not from 0 as C# does.



回答16:

I got this error because I tried to rename a sheet with too many characters



回答17:

I agree with Hugh W post \"I conclude that the same error code is used to indicate multiple unrelated problems\"

Other posts have not mentioned that this error occurs frequently if the worksheet is locked. While I haven\'t tested every scenario, it seems that anything that you can not do in excel when a worksheet is locked with throw this error if you attempt to do it via VSTO/Com while the sheet is locked. E.G. Changing any style artifact (font, font size, colour, underline), changing the Excel Validation, changing the column widths, row heights, formulas



回答18:

This type of error also occurs when you try to open your excel sheet and if it is prompting any error message. simply you can say when your excel file is corrupted.



回答19:

I resolved this issue by using the code below. Please do not use other parameters in these functions.

mWorkBook = xlApp.Workbooks.Open(FilePath)

mWorkBook.Save();

RESOLVED