2012-07-27 21 views
14

Potrebbe mi punto nella giusta direzione su come leggere uno spreasheet Excel, ciclo attraverso tutte le righe e colonne per prelevare valore utilizzando EPPlus e MVC qualcuno? Così tariffa vedo esempi per creare una spreasheet, ma non ho trovato alcun sull'apertura di un file excel e leggere i valori da esso. Qualsiasi aiuto sarebbe apprezzato.lettura Excel spreasheet utilizzando EPPlus

TIA Sue ..

risposta

18

esempio semplice

// Get the file we are going to process 
var existingFile = new FileInfo(filePath); 
// Open and read the XlSX file. 
using (var package = new ExcelPackage(existingFile)) 
{ 
    // Get the work book in the file 
    var workBook = package.Workbook; 
    if (workBook != null) 
    { 
     if (workBook.Worksheets.Count > 0) 
     { 
      // Get the first worksheet 
      var currentWorksheet = workBook.Worksheets.First(); 

      // read some data 
      object col1Header = currentWorksheet.Cells[1, 1].Value; 
+0

awesome..thanks..i può toglierlo per le mie esigenze da qui. – sansid

+8

noti che indice per righe e colonne iniziare a 1, in modo da "Cellule [0, 1]" dovrebbe essere "Cellule [1, 1]" – amcdrmtt

+1

Per gli sviluppatori nuovi a questo argomento, avrete bisogno di "usare" dichiarazioni a System; System.IO; e OfficeOpenXml; per eseguire questo esempio. – David

Problemi correlati