這次遇到的問題是當excel中欄位數超過255欄時,以前用oledb讀入的方式會產生錯誤,執行到fill(ds)時就會掛掉了,連用try-catch都抓不出錯誤,就直接給我罷工(氣死)!!
經過google後援會一番商討後,終於看到了點希望,就在差點搞掛電腦ㄉ危險下終於ok!! 呼~~~
讓我寫下這可歌可泣ㄉ一面
~step1~加入參考1 .NET System.Data.OracleClient.dll2. COM Microsoft Excel 11.0 Object Library
~step2~
加入namespace
using Excel;
using System.Configuration;
using System.Reflection;
using System.Diagnostics;
~step3~
object missing = Missing.Value;
Excel.ApplicationClass app;
Excel.Workbook book;
Excel.Worksheet sheet;
int excelcount;
app = new ApplicationClass();
try
{
book = app.Workbooks.Open(Files[j],missing,missing,missing,missing,missing,
missing,missing,missing,missing,missing,missing,missing,missing,missing);
}
catch (Exception e)
{
throw e;
}
//得到WorkSheet
sheet = (Excel.Worksheet)book.Sheets.get_Item(1);
//得到使用過的欄位數目
excelcount = sheet.UsedRange.Columns.Count;
book.Close(false,false,false);
app.Workbooks.Close();
app.Quit();
ps:記得application一定要關!! 不然會一直執行!! 無法測試,必須重開機,以上!!