我正在使用 Window Service 项目.必须按顺序将数据写入 Excel 文件中的工作表.
I am working with Window Service project. that have to write data to a sheet in Excel file in a sequence times.
但有时,只是有时,服务在尝试使用单元格名称获取范围时抛出异常Exception from HRESULT: 0x800A03EC".
But sometimes, just sometimes, the service throw out the exception "Exception from HRESULT: 0x800A03EC" while it's trying to get range with cell's name.
我已经把打开excel表格的代码放在这里了.
I have put the code of opening excel sheet, and getting cell here.
1:打开excel表格
1: Opening excel sheet
m_WorkBook = m_WorkBooks.Open(this.FilePath, 0, false, 5,
"", "", true, Excels.XlPlatform.xlWindows, ";",
true, false, 0, true, 0, 0);
2:让单元格写入
protected object m_MissingValue = System.Reflection.Missing.Value;
Range range = m_WorkSheet.get_Range(cell.CellName, m_MissingValue);
// error from this method, and cell name is string.
错误码0x800A03EC
(或-2146827284)表示NAME_NOT_FOUND;换句话说,你已经要求了一些东西,而 Excel 找不到它.
The error code 0x800A03EC
(or -2146827284) means NAME_NOT_FOUND; in other words, you've asked for something, and Excel can't find it.
这是一个通用代码,它可以应用于很多它找不到的东西,例如.当 PivotItem 未应用过滤器时,使用当时无效的属性(如 PivotItem.SourceNameStandard
)会抛出此错误.Worksheets["BLAHBLAH"]
在工作表不存在等情况下会抛出此错误.通常,您要求的是具有特定名称且不存在的内容.至于为什么,这需要你自己去挖掘.
This is a generic code, which can apply to lots of things it can't find e.g. using properties which aren't valid at that time like PivotItem.SourceNameStandard
throws this when a PivotItem doesn't have a filter applied. Worksheets["BLAHBLAH"]
throws this, when the sheet doesn't exist etc. In general, you are asking for something with a specific name and it doesn't exist. As for why, that will taking some digging on your part.
检查您的工作表是否确实有您要求的范围,或者 .CellName
肯定会返回您要求的范围的名称.
Check your sheet definitely does have the Range you are asking for, or that the .CellName
is definitely giving back the name of the range you are asking for.
这篇关于Excel 错误 HRESULT: 0x800A03EC 尝试使用单元格名称获取范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!