Advertisement
nex036ara

read_excel_c#

Oct 29th, 2013
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.55 KB | None | 0 0
  1.  class DataArtist
  2.     {
  3.         public static List<Izvodjac> RegistarIzvodjaca;
  4.        
  5.         public static void ucitajRegistarIzvodjaca(string filePath) {
  6.        
  7.             if (!File.Exists(filePath))
  8.             {
  9.                 throw new FileNotFoundException();
  10.             }
  11.             RegistarIzvodjaca = new List<Izvodjac>();
  12.  
  13.  
  14.  
  15.                 Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
  16.                 ExcelApp.Visible = false;
  17.  
  18.              Workbook wb = null;
  19.  
  20.                 try
  21.                 {
  22.                     wb = ExcelApp.Workbooks.Open(filePath, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
  23.                     Sheets sheets = wb.Worksheets;
  24.                     Worksheet ws = (Worksheet)sheets.get_Item("artists-21k");
  25.                     Console.WriteLine("sheetName: " + ws.Name);
  26.                     Range excelRange = (Range)ws.get_Range("A", "H");
  27.                  
  28.                     string zellwert = excelRange.Value2;
  29.                     Console.WriteLine(zellwert);
  30.                
  31.                 }
  32.                 catch (Exception e)
  33.                 {
  34.                     Console.WriteLine(e.Message);
  35.                 }
  36.                 finally
  37.                 {
  38.                     wb.Close(false, null, null);
  39.                     ExcelApp.Quit();
  40.                 }
  41.  
  42.             }
  43.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement