1

I have a select option value as

<select id="FilterOptions" role="ListBox">
   <option value="7">1 Week</option>
   <option value="14">2 Week</option>
   <option value="28">4 Week</option>
   <option value="90">2 Months</option>
   <option value="182">6 Months</option>
   <option value="365">All</option>
</select>

I have an Icon to export to excel and below is the functionality.

My JqGrid works fine with all the option. But here is the problem. After Selecting ALL and All records are loaded without any error. But after exporting to excel I receive "Object Reference not set to an instance on the line specified below"

How can I solve this error?

public string ExportReport(int cp, int noOfOrders)
{
    string conndb=ConfigurationManager.AppSettings["Db"];
    const string Ids ="0";
    Company pList = _items.GetByCID(cp);
    IQueryable<Product> List

    List=product.SQLDatabase().GetListByCompandIds(cp, Convert.ToInt32(noOfOrders), conndb, Ids)

    XLWorkbook workbook = new XLWorkbook(XLEventTracking.Disabled);
    IXLWorksheet worksheet = workbook.Worksheets.Add("ExportReport");




        worksheet.Cell(1, 1).Value = "Received";
        worksheet.Cell(1, 2).Value = "Customer Email";
        worksheet.Cell(1, 3).Value = "First Name";
        worksheet.Cell(1, 4).Value = "Last Name";
        worksheet.Cell(1, 5).Value = "Company Name";
        worksheet.Cell(1, 6).Value = "Product Name";


        int i = 2;
        foreach (EReport ExpReport in List)
        {
            worksheet.Cell(i, 1).SetValue(ExpReport.received);
            worksheet.Cell(i, 2).SetValue(ExpReport.Email);
            worksheet.Cell(i, 3).SetValue(ExpReport.FirstName); // *Here is the line where I am receiving an error*
            worksheet.Cell(i, 4).SetValue(ExpReport.LastName);
            worksheet.Cell(i, 5).SetValue(ExpReport.CompanyName);
            worksheet.Cell(i, 6).SetValue(ExpReport.ProductName);
            ++i;
        }


        worksheet.Columns().AdjustToContents();
        Session["Workbook"] = workbook;
        string filename;
        filename = "Product-Report";
        return filename;
}
  1. How to export with sorting with a specific column received?
  • Look at the code fron [the answer](http://stackoverflow.com/a/13957161/315935) and [this one](http://stackoverflow.com/a/9349688/315935) which I use in my code for exporting data to Excel. It uses just the original Open XML SDK 2.5 for Microsoft Office available as free download from Microsoft. – Oleg Sep 16 '15 at 08:41
  • @Oleg I didn't get it. I am calling all records from database. And only when I select all option and export it shows Object Reference not set to an instance. My Gird loads properly but not excel. –  Sep 16 '15 at 15:08
  • Thing is I call to export is same as loading a grid. Is there any other option to export. –  Sep 16 '15 at 15:16
  • Also I found out that a cells is null that's the reason it is showing this message. And Jqgrid doesnot show any data in the table. I don't know how to solve this issue, any solution and help I can get. –  Sep 16 '15 at 15:24

0 Answers0