Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88126

C# Find empty cells and write them inside with ClosedXml

$
0
0

I have this problem, I have installed ClosedXml:

I have an Excel file already created and populated, now I should find the blank line below the already populated one and write some data

Example:

[A, 1] = name; [B, 1] = surname;

the next line will be empty and I will pass some variables to populate the cells going to the right.

OpenFileDialog FileExcel = new OpenFileDialog();

        if (FileExcel.ShowDialog() == DialogResult.OK)
        {
            try
            {
                var sr = new StreamReader(FileExcel.FileName);
            }
            catch (SecurityException ex)
            {
                MessageBox.Show($"Security error.\n\nError message: {ex.Message}\n\n" +
                $"Details:\n\n{ex.StackTrace}");
            }
        }


using (var excelWorkbook = new XLWorkbook(FileExcel.FileName))
        {
            var nonEmptyDataRows = excelWorkbook.Worksheet(Convert.ToInt32(comboBox1.SelectedItem)).RowsUsed();

            foreach (var dataRow in nonEmptyDataRows)
            {
                //for row number check
                if (dataRow.RowNumber() >= 1 && dataRow.RowNumber() <= 100)
                {

                }
            }
        }

Viewing all articles
Browse latest Browse all 88126

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>