Note that there are some explanatory texts on larger screens.

plurals
  1. POI want to Read Multiple excel sheets in one file without using OLEDB in C#
    primarykey
    data
    text
    <p>Im reading an Excel document from C# Windows Form.. There are 25 worksheets in Excel Workbook.. i can read 1st worksheet successfully.. But when i change it to worksheet 2.. it won't working at all.. Im not using OLEDB..</p> <p>I want to read 100 Row in every sheet.. following is my code...</p> <pre><code>` dt.Columns.Add("Amount", typeof(double)); dt.Columns.Add("ChequeNo", typeof(int)); dt.Columns.Add("month", typeof(int)); int AmountRow = 100; int ChequeNoRow = 101; int Column = 3; xlApp = new Excel.ApplicationClass(); xlWorkBook = xlApp.Workbooks.Open(path, 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Sheets[2];\\This place is the changing worksheets range = xlWorkSheet.UsedRange; double chequeAmount; double chequeNo; for (int i = Column; i &lt; 15; i++) { chequeAmount = (double)(range.Cells[AmountRow, i] as Excel.Range).Value2; chequeNo = (double)(range.Cells[ChequeNoRow, i] as Excel.Range).Value2; if (chequeNo != 0.0) { dt.Rows.Add(Convert.ToDouble(chequeAmount), Convert.ToInt32(chequeNo), i); } } dataGridView1.DataSource = dt; xlWorkBook.Close(true, null, null); xlApp.Quit(); releaseObject(xlWorkSheet); releaseObject(xlWorkBook); releaseObject(xlApp);` </code></pre> <p>releaseObject methods are not here.. those working perfectly... </p> <pre><code> `xlWorkSheet = (Excel.Worksheet)xlWorkBook.Sheets[1];` </code></pre> <p>This is how i change my worksheets.. The following line gives an exception..[Null point Exception]</p> <p><code>chequeAmount = (double)(range.Cells[AmountRow, i] as Excel.Range).Value2;</code></p> <p>Hope you'll know answers..</p>
    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.
    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