Rileyblue3
Rileyblue3

Reputation: 1

Ignoring rows that have Null in a cell. C# IronXL

I am working on a project where I want to make my program read an Excel sheet, and read out the information to a textbox, however I have been able to do this but I want it so if any cell in a row has no information skip the row.

enter image description here

Let's say C3 is empty, I want it so if that happens either A: Display a message box to break it or B: Skip the line and read the next one.

Also the Excel sheet is not filled in on purpose

Here is what I'm working with so far:

private void btnSummarize_Click(object sender, EventArgs e)
{
    txtOutput.Clear();
    OpenFileDialog openFileDialog = new OpenFileDialog();
    openFileDialog.Filter = "Excel Files|*.xls;*.xlsx;*.xlsm";

    if (openFileDialog.ShowDialog() == DialogResult.OK)
    {
        string filePath = openFileDialog.FileName;
        WorkBook workbook = WorkBook.Load(filePath);
        WorkSheet sheet = workbook.GetWorkSheet("Main");

        foreach (var cell in sheet["C3"])
        {
            txtOutput.Text += $"Cost was: {cell.Text}\r\n";
        }
        // ....
    }
}

Also links to your references will helpful please.

I tried doing if statements to say if a certain cell is null display a message box and break the reading cycle.

Upvotes: 0

Views: 61

Answers (0)

Related Questions