c 讀取excel中的資料(winform)

2022-05-22 07:06:09 字數 1112 閱讀 8405

1、開啟選擇檔案對話方塊

1

string path = ""

;2 system.windows.forms.openfiledialog fd = new

openfiledialog();

3 fd.title = "

選擇檔案

";//

選擇框名稱

4 fd.filter = "

xls files (*.xls)|*.xls

";//

選擇檔案的型別為xls**

5if (fd.showdialog() == dialogresult.ok)//

當點選確定

6

2、連線所選檔案並獲取資料存放在dataset中。

1

string mystring = "

provider=microsoft.jet.oledb.4.0;data source='";

2 mystring +=path.tostring();

3 mystring += "

';user id=admin;password=;extended properties='excel 8.0;imex=1;hdr=no;'";

4 oledbconnection cnnxls = new

oledbconnection(mystring);

5 oledbdataadapter myda = new oledbdataadapter("

select * from [sheet1$]

", cnnxls);

6 dataset myds = new

dataset();

7 myda.fill(myds);//

資料存放在myds中了

3、需要使用的時候從dataset。

例如得到excel中第i行第0列的資料的語句為:myds.tables[0].rows[i].itemarray[0].tostring()  注意都是從0開始的。

C 讀取EXCEL中的資料(2)

我們已經得到了檔名,下面我們就讀取檔案裡面的資料放在資料網格檢視中。顯示資料 如下 連線的是excel8.0,hdr yes 有兩個值 yes no,yes說了你是否能直接讀列名,no,只可以讀下標,imex 1 解決數字與字元混合時,識別不正常的情況 oledbconnection connect...

讀取Excel檔案中的資料

string strsource file1.value string connstr provider microsoft.jet.oledb.4.0 data source strsource extended properties excel 8.0 string query select f...

讀取Excel表中資料

1 匯入python的excel包 pip install xlsx 2 在工程中建立乙個 3 讀取excel表中資料,如下 import xlrd 這裡使用的excel檔案中資料為 文字 格式 開啟excel表 excel xlrd.open workbook 介面測試 data.xlsx 定位其...