Reading an Excel 2007 cell formula value using C# -


i've got large , complex excel 2007 file , cell formula references cell in worksheet. i've tried many things try value (as in 1 can see when loaded in excel itself) related trying child objects of openxmlpart's. value of cell 40178, there no list in file many indices. formula in cell "'input control sheet'!$f$8". i'm (perhaps stupidly) assuming string can used directly on openxml api read value cell referenced string, wrong?

if tell me how value correct cell out based on formula happy - i've been basing work far on code provided microsoft (terrible) page: http://msdn.microsoft.com/en-us/library/cc850837.aspx

thanks,

matt.

probably u can use code read each cell value. u can modify code accordingly, code reading values excel file , returning list of values read:

first put this: using excel = microsoft.office.interop.excel;

private list<string> getkeywordslist(string xlsfilepath)     {         excel.application xlapp;         excel.workbook xlworkbook;         excel.worksheet xlworksheet;         excel.range range;         string str;         int rcnt = 0;         int ccnt = 0;          list<string> keywords = new list<string>();         xlapp = new excel.applicationclass();         xlworkbook = xlapp.workbooks.open(xlsfilepath, 0, true, 5, "", "", true, microsoft.office.interop.excel.xlplatform.xlwindows, "\t", false, false, 0, true, 1, 0);         xlworksheet = (excel.worksheet)xlworkbook.worksheets.get_item(1);          range = xlworksheet.usedrange;         (rcnt = 1; rcnt <= range.rows.count; rcnt++)         {             (ccnt = 1; ccnt <= range.columns.count; ccnt++)             {                  if (!(((range.cells[rcnt, ccnt] excel.range).value2) == null))                 {                     if ((range.cells[rcnt, ccnt] excel.range).value2.gettype().tostring() == "system.double")                     {                         double d1 = (double)(range.cells[rcnt, ccnt] excel.range).value2;                         str = convert.tostring(d1);                         keywords.add(str);                     }                     else                     {                         str = (string)(range.cells[rcnt, ccnt] excel.range).value2;                         keywords.add(str);                     }                 }             }          }          xlworkbook.close(true, null, null);         xlapp.quit();          releaseobject(xlworksheet);         releaseobject(xlworkbook);         releaseobject(xlapp);         return keywords;      }  private void releaseobject(object obj)     {         try         {             system.runtime.interopservices.marshal.releasecomobject(obj);             obj = null;         }         catch (exception ex)         {             obj = null;         }                 {             gc.collect();         }     } 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -