我在jqgrid表中加载客户详细信息。 使用Open XML我正在导出我的网格数据。这是问题所在。我的一个单元格在数据库中具有null值。现在,在导出时,我将对象引用未设置为实例。如何忽略这个问题?
请帮帮我。尝试使用谷歌搜索但无法找到任何解决方案。
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("ListReport");
worksheet.Cell(1, 1).Value = "Customer Id";
worksheet.Cell(1, 2).Value = "First Name";
worksheet.Cell(1, 3).Value = "Last Name";
worksheet.Cell(1, 4).Value = "Email";
worksheet.Cell(1, 5).Value = "Department";
worksheet.Cell(1, 6).Value = "Supervisor";
int i = 2;
foreach (EList ExpReport in List)
{
worksheet.Cell(i, 1).SetValue(ExpReport.CustomerId);
worksheet.Cell(i, 2).SetValue(ExpReport.FirstName); //*Here is where I am having error*
worksheet.Cell(i, 3).SetValue(ExpReport.LastName);
worksheet.Cell(i, 4).SetValue(ExpReport.Email);
worksheet.Cell(i, 5).SetValue(ExpReport.Department);
worksheet.Cell(i, 6).SetValue(ExpReport.Supervisor);
++i;
}
worksheet.Columns().AdjustToContents();
Session["Workbook"] = workbook;
string filename;
filename = "Product-Report";
return filename;
}
示例:
For Example:
CustomerId FirstName LastName Email Department Supervisor
123654 Adam Ad aa@abc.com IT Mike
456987 Ferna tf@abc.com BA Alferd
78931 Smith Lopez sl@abc.com BA Alfred
123456 John Horvath jh@abc.com IT Micheal
456789 Cruise cc@abc.com BA Alferd
78931 Jackson Ville JV@abc.com BA Alfred