Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 22nd, 2012  |  syntax: None  |  size: 0.75 KB  |  hits: 20  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. How can I extract a string from an excel cell?
  2. Excel.ApplicationClass excelApp = new Excel.ApplicationClass();
  3.  
  4.         excelApp.Visible = true;
  5.  
  6.         Excel.Workbook excelWorkbook = excelApp.Workbooks.Open("C:\Users\user\Desktop\list.xls", 0, false, 5, "", "",
  7.         false, Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
  8.  
  9.         Excel.Sheets excelSheets = excelWorkbook.Worksheets;
  10.  
  11.         string currentSheet = "Sheet1";
  12.         Excel.Worksheet xlws = (Excel.Worksheet)excelSheets.get_Item(currentSheet);
  13.        
  14. xlws.Cells[1,1].Value.ToString();
  15.        
  16. Range range = xlws.get_range("A1", "A1");
  17. object[] data = range.get_Value(XlRangeValueDataType.xlRangeValueDefault);
  18. string str = (string)data[0];
  19.        
  20. var cellValue = xlws.Cells[1,1].Value