2012-09-05 52 views
0

我正在製作MVC3應用程序,我需要使用Ole db連接讀取excel文件,但無法獲得某些機器上的所有excel行,並且可以獲取其他人的所有數據。下面是我的代碼:使用Ole db讀取Excel文件無法讀取所有excel行

var connectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0 Xml", serverPath); 

      //Fill the dataset with information from the Hoja1 worksheet. 
      string SqlCommand="SELECT * FROM [sheet1$] "; 

      var adapter = new OleDbDataAdapter(SqlCommand, connectionString); 
      var ds = new DataSet(); 
      adapter.Fill(ds, "results"); 
      DataTable data = ds.Tables["results"]; 

我孢知道這個problm原因 非常感謝

+0

您是否在所有機器上使用相同的文件和相同版本的Excel? –

+0

可讀寫使用Oledb&Odbs不跨平臺(不支持所有Win版本(x64和x86)),請嘗試使用OpenXML選項!,所有機器都沒有問題。並且不區分web和win應用程序。 – Elyor

回答

0

是的,良好的齊這次研究您的問題;更是選項, 例如我明白了!寫:

1)WindowsBase &核心優化 - enter link description here

2)OpenXML的SDK(從Microsoft Project下載見鏈接click here,它的MS辦公室閱讀&寫使用XML & XSLT格式化,沒有問題在Win & Web應用程序中工作)。 不,1-bad部分它工作MS 2007,2010,... version.Not在MS 1997,2003上工作? 對於所示例的文章,但 - Article-1Article-2Article-3,...

,多又選擇...

試試熱門文章!

+0

官方文檔還有更多的例子,[點擊這裏](http://msdn.microsoft.com/en-us/library/office/gg575571.aspx)以及來自ms blog [簡單閱讀](http:// blogs。 msdn.com/brian_jones/archive/2008/11/10/reading-data-from-spreadsheetml.aspx) – Elyor