I write this code for open an excel file:
private readonly object _missing = Type.Missing;
private IEnumerable<CellModel> GetUsedCells(string fileName)
{
SetNewCurrentCulture();//set "en-US" culture
var application = new Application();
var workbooks = application.Workbooks;
Workbook workbook = null;
try
{
workbook = workbooks
.Open(fileName,
0, false, _missing, "", "",
true, XlPlatform.xlWindows, _missing, false, false,
_missing, false, false, XlCorruptLoad.xlNormalLoad
);
}
finally
{
//realocate memory
if(workbook != null)
{
ReleaseComObject(workbook);
workbook = null;
}
workbooks.Close();
ReleaseComObject(workbooks);
workbooks = null;
application.Quit();
ReleaseComObject(application);
application = null;
GC.GetTotalMemory(false);
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
GC.GetTotalMemory(true);
ResetCurrentCulture();//reset old culture
}
}
and in Open method this error has occured : "Exception from HRESULT: 0x800A03EC"
notes:
I use vs2012 and Target Framework of my project is 4 and version of Microsoft.Office.Interop.Excel is 14.0.0.0
Server info: Windows Server 2008 32-bit, IIS7, Excel 2010
I create Desktop folder in "C:\Windows\System32\config\systemprofile" and set permission to "Network Services" and "Users"
Change Permissions in DCOM Config in "Microsoft Excel Application" and select "Interactive User"
Set permission to "Network Services" and "Users" for "C:\Windows\Temp"
I'm very confused. help me please!