2

I have written a C# program that does a lot of iterative calculations and then returns a huge list of data. Because the data changes each time I run the program, I draw it in an Excel spreadsheet with predefined functions and graphs that are useful to interpret the data. However, all my charts in the spreadsheet depend on a single column of data, through with other columns and axis are calculated using formulas. However, the total amount of data is not always constant.

For instance, sometimes I get 22 elements of data in the list, and sometimes the number flows into 100s. To have a stable bound, I cap the charts to graph only the first 50 rows of data, and in my program, I fill the remaining columns with the value "#N/A". However, when I open the spreadsheet, the rows with superfluous data is graphed as 0s. I want the charts to graph only the rows with valid data.

Here is what my code looks like, it is relatively very simple, so I am not going to modify this, I want to know what changes I can make in the spreadsheet.

            FileInfo newFile = new FileInfo("Report.xlsx");
        ExcelPackage pack = new ExcelPackage(newFile);
        ExcelWorksheet ws = pack.Workbook.Worksheets[1];        

        int cellCount = 2;
        for(int i = 0; i < 49; i++)
        {
            String cell = "B" + cellCount;
            if (i < data.Count)
                ws.Cells[cell].Value = data.ElementAt(i);
            else
                ws.Cells[cell].Value = "#N/A";

            cellCount++;

        }

      Console.Out.WriteLine("saving");
        pack.Save();
        System.Diagnostics.Process.Start("Report.xlsx");

To access the Excel documents, I use EPPLUS. Here is what my charts look like:

how my charts look

As the graph shows, the last 5-6 rows contain NULL values, however, they are graphed as well, with values of 0. The blue line represents the data in the third column, and red line represents the last column (that is never going to be null because it's dependant on a fixed row).

How do I force Excel to ignore the last few NULL rows?

4

0 回答 0