开发者

HRESULT: 0x800A03EC on Worksheet.range

开发者 https://www.devze.com 2023-03-29 08:47 出处:网络
I am getting HRESULT: 0x800A03EC on Worksheet.range method. Number of rows are more than 70K. Office 2007.

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 开发者_StackOverflow中文版my rowcount is more than 65530 . Breaks on this function. I have observed that it breaks only when row count goes more than 65530.


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


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.


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.


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.


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.


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


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.


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

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


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.


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).


I received this error code 0x800A03EC when trying to save an Excel file created within my .Net application in VS 2017. I changed the Excel.Application object property Visible=True and let it run until the point of failure. Tried to finish the steps manually in Excel and then discovered I could not save the file because of missing folder permissions. I added the Write permission to the folder, and the error went away.


For others like me, who have the same exception:

It can also happen if you try to pass a null value instead of Missing.Value (or Type.Missing)

e.g.

Worksheet worksheet = ...;
return worksheet.Range["A1", null]; //This call generates the error 0x800A03EC

return worksheet.Range["A1", Missing.Value]; //This works correctly


in 2021, when i got this problem. the reason actually is:

for a Excel range or cell, i was trying to add/delete comment directly without checking whether there is a comment binding with it or not.

error code is:

if ( comments_string.Length != 0)
{     range.AddComment( comments_string);
}

working code is:

if ( comments_string.Length != 0)
{     if (range.Comment != null) range.Comment.Delete();
     range.AddComment(comments_string);
}


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.


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.


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


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)


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.


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


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


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


Seems like this i s a pretty generic error for "something went wrong" with the operation you attempted. I have observed that will also occur if you have a formula error and are assigning that formula into a cell. E.g. "=fubar()"


I've come across it several different times and every time it was always some error with either duplicating a tab name or in this current case it just occurred because I simply had a typo in the get_Range where I tried to get a Cell by number and number instead of the letter and number.
Drove me crazy because the error pointed me to a few lines down but I had commented out all of the creation of the other sheets above the "error line" and the ones in the line and below were created with no issue.
Happened to scan up a few lines above and saw that I put 6 + lastword, C + lastrow in my get_Range statement and of course you can't have a cell starting with a number it's always letter than number.


I ran in to the same error. For me it was while trying to set a CountIf and CountIfs respectively that I got the error.

After some trial an error I found out it was an issue I had with all formulas using multiple parameters.

It turns out that the parameter separator ";" (semicolon), which I use in excel is not the correct one for me to use in code behind. If I use "," (comma) in stead, the formula is correctly used. Note: When viewed in Excel afterwards, it is shown as ";" (semicolon).

My trial and error process included trying to set a bunch of different formulas, and this was the 'fix' I ended up with. I am running an English windows, but I am located in Denmark, I have no idea if there is some kind of localization involved with my issue.

CultureInfo.CurrentCulture.TextInfo.ListSeparator is ";", and this works correctly for separating validator rule values. Perhaps this is the reason why my parameter separator is something else.

Anyways; the formula could be wrong because you need to use a different parameter separator character.


I had this same error code. Turns out a comment here helped me. Count does not start from 0. The commented out line was throwing this error.

string cell = (string)range.Cells[3, 3].Value; This line worked fine

string QuestionID = (string)range.Cells[1, 0].Value;This line threw this error


I know this is old but I had the same error when trying to set a spreadsheet range as follows:

rngSumFormula = mxlWorksheet.Range(strFormulaRange)

There were plenty of mxlWorksheet.Range statements before this one but it failed every time. It turned out, after a ton of digging that the difference between my range value in strFormulaRange and the other values is that it had commas in the range i.e. "B2,C2,D2:E2". Before this statement all the ranges values simple had a colon i.e. "D2:E2".

So why was this an issue? Because I don't use comma as my default separator in Windows 10 instead I use a pipe character (|) as I deal with a lot of SQL bulk loads of description fields which contain lots of commas that aren't separators. Once I changed my default separator back to a comma my error disappeared.

This probably won't help very many people as I don't think separator changes are very common but since it was my solution I wanted to share. Just for reference you change your separator in Windows 10 here:

Region Settings>Additional Date, Time & Regional Settings>Change Date, Time or Number Formats>Additional Settings and then scroll down to List separator.


This type of error can also occur when the excel file is corrupted for some reason

0

精彩评论

暂无评论...
验证码 换一张
取 消