arep
public static Cell GetCell(WorksheetPart workSheetPart, string cellAddress)
{
return workSheetPart.Worksheet.Descendants<Cell>().SingleOrDefault(c => cellAddress.Equals(c.CellReference));
}
System.NullReferenceException: Object reference not set to an instance of an object.
at DetailReport.GenData.<>c__DisplayClass1.
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at DetailReport.GenData.GetCell(WorksheetPart workSheetPart, String cellAddress) in c:\CLI\CS\DetailReport\GenData.cs:line 122
at DetailReport.Program.ExtractData(String product, String reporttitle, String whereClause, String lob) in c:\CLI\CS\DetailReport\Program.cs:line 168
at DetailReport.Program.GenDetailReports() in c:\CLI\CS\DetailReport\Program.cs:line 114
at DetailReport.Program.Main(String[] args) in c:\CLI\CS\DetailReport\Program.cs:line 36
It is called this way:
VulpesPosted Apr 14, 2013, 12:49 PM
A RepaskyPosted Apr 13, 2013, 11:04 PM
Border border1 = GenData.GenerateBorder();Fill fill1 = GenData.GenerateFill();
string celladdress = null;
Cell cell7 = GenData.GetCell(wsp1, celladdress);
uint styleIndex = 7;
CellFormat cf1 = GenData.GetCellFormat(wbp1, styleIndex);
uint cfcount = GenData.InsertCellFormat(wbp1, cf1);
GenData.SetBorderAndFill(wbp1, wsp1);
Is the cell address like "K5"? That is the cell reference I thought. Are these calls out of order? I just used 7 for styleIndex. Just picked a number.
VulpesPosted Apr 13, 2013, 1:57 PM
If 'query' isn't null, then the only other thing that could produce an exception if it's null is the parameter 'cellAddress'.
So, are you sure that this isn't null when you pass it in?
A RepaskyPosted Apr 13, 2013, 12:08 PM
return query.SingleOrDefault(c => cellAddress.Equals(c.CellReference));
System.NullReferenceException: Object reference not set to an instance of an object.
at DetailReport.GenData.<>c__DisplayClass1.
at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source, Func`2 predicate)
at DetailReport.GenData.GetCell(WorksheetPart workSheetPart, String cellAddress) in c:\CLI\CS\DetailReport\GenData.cs:line 126
at DetailReport.Program.ExtractData(String product, String reporttitle, String whereClause, String lob) in c:\CLI\CS\DetailReport\Program.cs:line 168
at DetailReport.Program.GenDetailReports() in c:\CLI\CS\DetailReport\Program.cs:line 114
at DetailReport.Program.Main(String[] args) in c:\CLI\CS\DetailReport\Program.cs:line 36
I think maybe I am putting it in the wrong place in the program. Here is the article that I am using as a basis for this.
http://stackoverflow.com/questions/15791732/openxml-sdk-having-borders-for-cell
VulpesPosted Apr 13, 2013, 6:39 AM