Note that there are some explanatory texts on larger screens.

plurals
  1. POReading an dynamic Excel File with C# error
    primarykey
    data
    text
    <p>I am trying to read an excel file with C# and display every cell in the sheet inside a messagebox using the <code>messagebox.Show()</code> method. Problem is that my excel file has 5 rows and 3 columns. here is my excel sheet: <a href="http://postimg.org/image/xts9n1kif" rel="nofollow">http://postimg.org/image/xts9n1kif</a>.</p> <p>It displays everything until "roof" and after that stops leaving behind "light" and "iron", but if i fill the stuff3 column it reads everything perfectly fine. As is my case, the file may change. It may have more columns or rows in it, and some of them may be empty. </p> <p>Any idea why it is not working?</p> <p>Here is my code: </p> <pre><code>using System; using System.Windows.Forms; using Excel = Microsoft.Office.Interop.Excel; namespace ReadFromExcell { public partial class Form1 : Form { public Form1() { InitializeComponent(); this.Load += new System.EventHandler(this.Form1_Load); } private void Form1_Load(object sender, EventArgs e) { Excel.Application xlApp = new Excel.Application(); Excel.Workbook xlWorkbook = xlApp.Workbooks.Open("C:\\Users\\User1\\Desktop\\ItemDB.xlsx"); Excel._Worksheet xlWorksheet = xlWorkbook.Sheets[1]; Excel.Range xlRange = xlWorksheet.UsedRange; int rowCount = xlRange.Rows.Count; int colCount = xlRange.Columns.Count; for (int i = 1; i &lt;= rowCount; i++) { for (int j = 1; j &lt;= colCount; j++) { MessageBox.Show(xlRange.Cells[i, j].Value2.ToString()); } } //Close the excel file after reading it. xlWorkbook.Close(); } } } </code></pre>
    singulars
    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