Note that there are some explanatory texts on larger screens.

plurals
  1. POWhen Excel file is opened externally during C# application, an exception occurs
    primarykey
    data
    text
    <p>I wrote a C# application that queries a DB and puts the results in an excel file. The program itself works fine. However if I open a second completely unrelated excel file while the application is running, an exception occurs and the process stops.</p> <p>Now, in the program itself I've set the visibility to false, and after opening the second unrelated Excel file, the one that was being generated is suddenly open and visible, and then I get the exception.</p> <p>Anyone know what is causing the problem or how to resolve it?</p> <p>The relevant parts of the code is as follows, the exception occurs at the line worksheet.get_Range(currCol.GetString() + excelRow, Missing.Value).Formula = item.ToString();</p> <p>The exception itself is : "Exception from HRESULT: 0x800AC472"</p> <pre><code> Application exc = new Application(); //Makes the Excel file not visible exc.Visible = false; exc.UserControl = false; exc.DisplayAlerts = false; Workbooks workbooks = exc.Workbooks; Workbook workbook = workbooks.Add(XlWBATemplate.xlWBATWorksheet); Sheets sheets = workbook.Worksheets; Worksheet worksheet = (Worksheet)sheets.get_Item(1); int excelRow = 1; ExcelChar currCol = new ExcelChar('A'); System.Data.DataTable testTable = dbConnection.searchQuery("Select * from testTable").Copy(); if (worksheet == null) { Console.WriteLine("ERROR: worksheet == null"); } foreach (System.Data.DataRow row in testTable.Rows) { foreach (var item in row.ItemArray) { worksheet.get_Range(currCol.GetString() + excelRow, Missing.Value).Formula = item.ToString(); currCol.Add(1); } excelRow++; currCol = new ExcelChar('A'); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload