Excel Exception from HRESULT: 0x800AC472
-
Excel Exception from HRESULT: 0x800AC472 I am exporting data to excel thru C# code. while export is in progress, if I open any excel file (not necessariliy the one being created), I get the above error. Earlier I was exporting on a background thread, but after reading various comments on google, I removed the background thread but the problem still exists.
Gurpreet
-
Excel Exception from HRESULT: 0x800AC472 I am exporting data to excel thru C# code. while export is in progress, if I open any excel file (not necessariliy the one being created), I get the above error. Earlier I was exporting on a background thread, but after reading various comments on google, I removed the background thread but the problem still exists.
Gurpreet
-
this probably can help you: http://social.msdn.microsoft.com/forums/en-US/vsto/thread/9168f9f2-e5bc-4535-8d7d-4e374ab8ff09/[^]
I have created a simple application to show the problem:
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{Microsoft.Office.Interop.Excel.Application \_objAppln; Workbook \_objWorkBook; Workbooks \_objWorkBooks; Worksheet \_objWorkSheet; public Form1() { InitializeComponent(); InitializeExcelObjectModel(); } ~Form1() { DisposeExcelObjects(); } void SaveExcel() { \_objAppln.DisplayAlerts = false;//Since, we are using SaveFileDialog's overwrite prompt(control is on view). \_objWorkBook.SaveAs("C:\\\\tmp.xls", XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, false, Type.Missing, XlSaveAsAccessMode.xlNoChange, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing); \_objWorkBook.Close(true, "C:\\\\tmp.xls", false); \_objAppln.DisplayAlerts = true;//restore back for other display alerts } private void InitializeExcelObjectModel() { \_objAppln = new Microsoft.Office.Interop.Excel.Application(); // To initialize excel file //\_objAppln.Visible = true; if (\_objAppln != null) { \_objWorkBooks = \_objAppln.Workbooks; \_objWorkBook = \_objWorkBooks.Add(Type.Missing); // To add workbook with sheets in excel file \_objWorkSheet = (Worksheet)\_objAppln.ActiveSheet; // To get the current active sheet in excel file } } public void DisposeExcelObjects() { System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objWorkSheet); System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objWorkBook); System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objWorkBooks); System.Runtime.InteropServices.Marshal.ReleaseComObject(\_objAppln); \_objWorkSheet = null; \_objWorkBooks = null; \_objWorkBooks = null; \_objAppln = null; } private void button1\_Click(object sender, EventArgs e) { string cell1 = string.Empty, cell2 = string.Empty; string\[\] chars = { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T" }; for (int row = 1; row < 1000; row++) { for (int column = 0; column < 20; column++) { cell1 = chars\[column\] + row.ToString(); Range objRange = \_objWorkSheet.get\_Range(cell1, cell1); objRange.Value2 = cell1; System.Runtime.Interop