Note that there are some explanatory texts on larger screens.

plurals
  1. PO"Exception from HRESULT: 0x800A01A8"
    text
    copied!<p>I've written this code to count the number of rows that are populated in an excel worksheet. It works until it gets yo a certain number of rows (not the total). Then comes up with the error message "Exception from HRESULT: 0x800A01A8" Any help much appreciated </p> <pre><code>namespace ConsoleApplication1 { class ExcelClass { /// &lt;summary&gt; /// The main entry point for the application. /// &lt;/summary&gt; [STAThread] static void Main(string[] args) { Excel.Application excelApp = new Excel.Application(); // Creates a new Excel Application excelApp.Visible = true; // Makes Excel visible to the user. // The following code opens an existing workbook string workbookPath = "D:\\RSG_D.xls"; // Add your own path here Excel.Workbook excelWorkbook = excelApp.Workbooks.Open(workbookPath, 0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false); // The following gets the Worksheets collection Excel.Sheets excelSheets = excelWorkbook.Worksheets; // The following gets Sheet1 for editing string currentSheet = "Sheet1"; Excel.Worksheet excelWorksheet = (Excel.Worksheet)excelSheets.get_Item(currentSheet); //declare a variable to hold the CurrentCulture System.Globalization.CultureInfo oldCI; //get the old CurrenCulture and set the new, en-US //void SetNewCurrentCulture() //{ oldCI = System.Threading.Thread.CurrentThread.CurrentCulture; System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US"); //} int rowCounter = 1; while ( rowCounter != null) { Excel.Range countRows = (Excel.Range)excelWorksheet.Cells[rowCounter, 1] as Excel.Range; object CountRows = countRows.Value; rowCounter++; Console.WriteLine(CountRows); } excelWorkbook.Close(0); excelApp.Quit(); //reset Current Culture back to the originale System.Threading.Thread.CurrentThread.CurrentCulture = oldCI; } } } </code></pre>
 

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