Hey 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
So lets 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
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}rn";
}
Here is what Im working with so far.
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.
Rileyblue3 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.