c# - Exception while import from excel using openXML -


i deserialize data excel file list.

i using code

class excelimport {     workbook workbook;     sharedstringtable sharedstrings;     ienumerable<sheet> worksheets;     worksheetpart custsheet;     worksheetpart ordersheet;     string filepath;     excelstorage provider;     stiker[] ans;     list<stiker> stikerlist;      public excelimport(string fp)     {         filepath = fp;       }         public list<stiker> dothejob()     {         using (spreadsheetdocument document =     spreadsheetdocument.open(filepath, true))         {             stikerlist= new list<stiker>();             workbook = document.workbookpart.workbook;             worksheets = workbook.descendants<sheet>();             sharedstrings = document.workbookpart.sharedstringtablepart.sharedstringtable;             stikerlist = stiker.loadstiker(custsheet.worksheet, sharedstrings);             return stikerlist;         }     } 

but reson exception in line:sharedstrings = document.workbookpart.sharedstringtablepart.sharedstringtable;

that "object reference not set instance of object.".

after above saggestion found the

if (sharedstringtablepart == null) { // report problem } 

rerurn null

any idea?

one of properties in source line "null" , have no value.

you'll want either use debugger figure out (set breakpoint on line , hover mouse on each property), or break down line separate statements. like:

var workbookpart = document.workbookpart;  if (workbookpart == null) {     // report problem }  var sharedstringtablepart = workbookpart.sharedstringtablepart; if (sharedstringtablepart == null) {     // report problem }  sharedstrings = sharedstringtablepart.sharedstringtable; 

this way code can determine @ run-time if there's issue: kind of "defensive" idea idea when working data created system other own.


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -