HRESULT: 0x800A03EC on Worksheet.range

前端 未结 23 2093
Happy的楠姐
Happy的楠姐 2020-11-22 07:42

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

Code:

Microsoft.Office.Interop.Excel.Range         


        
相关标签:
23条回答
  • 2020-11-22 08:11

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

    0 讨论(0)
  • 2020-11-22 08:14

    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.

    0 讨论(0)
  • 2020-11-22 08:16

    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()"

    0 讨论(0)
  • 2020-11-22 08:17

    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.

    0 讨论(0)
  • 2020-11-22 08:17

    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)
    
    0 讨论(0)
  • 2020-11-22 08:18

    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.

    0 讨论(0)
提交回复
热议问题