全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:7391
推到 Plurk!
推到 Facebook!

讀取Excel資料寫入資料庫…

答題得分者是:FrederickPau
channel
尊榮會員


發表:67
回覆:707
積分:854
註冊:2002-05-02

發送簡訊給我
#1 引用回覆 回覆 發表時間:2002-11-26 22:58:51 IP:218.163.xxx.xxx 未訂閱
各位Delphi高手、先進們: 如何利用Delphi讀取Excel資料寫入資料庫?感激不盡!!
------
~小弟淺見,參考看看~
andersonhsieh
版主


發表:33
回覆:531
積分:439
註冊:2002-06-10

發送簡訊給我
#2 引用回覆 回覆 發表時間:2002-11-26 23:39:35 IP:211.23.xxx.xxx 未訂閱
搜尋一下以前的文章吧 @@~~飛翔在天際的精靈~~@@
------
@@~~飛翔在天際的精靈~~@@
andersonhsieh
版主


發表:33
回覆:531
積分:439
註冊:2002-06-10

發送簡訊給我
#3 引用回覆 回覆 發表時間:2002-11-26 23:44:54 IP:211.23.xxx.xxx 未訂閱
引言: 各位Delphi高手、先進們: 如何利用Delphi讀取Excel資料寫入資料庫?感激不盡!!
參考一下吧 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=22937 @@~~飛翔在天際的精靈~~@@
------
@@~~飛翔在天際的精靈~~@@
FrederickPau
資深會員


發表:4
回覆:161
積分:268
註冊:2002-11-04

發送簡訊給我
#4 引用回覆 回覆 發表時間:2002-11-27 00:25:43 IP:61.228.xxx.xxx 未訂閱
我自己做了一個簡單的 ... 請參考
procedure TForm1.BitBtn1Click(Sender: TObject);
var
    i: Integer;
    BoxNo: String;
    MsExcel, MsExcelWorkBook, MsExcelWorkSheet: Variant;
begin
    MsExcel := CreateOleObject( 'Excel.Application');
    MsExcelWorkBook := msExcel.Workbooks.Open( 'c:\book.xls');
    MsExcelWorkSheet := msExcel.Worksheets.Item[1];        Table1.Open;
    for i := 1 to MsExcelWorkSheet.Rows.Count do
    begin
        BoxNo := MsExcelWorkSheet.Range[Chr(65)   IntToStr(i)].Value;
        if BoxNo <> '' then
        begin
            Table1.Append;
            Table1.FieldByName('BOX_NO').AsString := BoxNo;
            Table1.FieldByName('BOX_DESC').AsString := MsExcelWorkSheet.Range[Chr(66)   IntToStr(i)].Value;
            Table1.Post;
        end
        else
            Break;
    end;
    Table1.Close;
    MsExcel.Quit;
end;
bookworm
中階會員


發表:63
回覆:161
積分:82
註冊:2002-08-03

發送簡訊給我
#5 引用回覆 回覆 發表時間:2002-11-27 01:00:12 IP:210.85.xxx.xxx 未訂閱
其實你也可以像我一樣很笨的把access打開,將excel匯入,再做進一步的處理..
kan0515
中階會員


發表:56
回覆:120
積分:50
註冊:2002-06-24

發送簡訊給我
#6 引用回覆 回覆 發表時間:2002-11-27 14:00:57 IP:211.23.xxx.xxx 未訂閱
你可以參考一下這一篇 http://delphi.ktop.com.tw/topic.php?TOPIC_ID=19947 我正好之前也在寫將excel的資料轉至access中 所以也有程式碼可以參考~~
richcomp
中階會員


發表:18
回覆:66
積分:51
註冊:2002-10-18

發送簡訊給我
#7 引用回覆 回覆 發表時間:2002-11-27 17:56:07 IP:61.177.xxx.xxx 未訂閱
以下是我從Borland網站下載的ADO連接EXCEL説明,希望對你有用 Create a simple spreadsheet viewer using ADO. 1. Start Delphi and create a new application.    2. Drop an ADODataSet onto the form.    3. Set the CommandType property to cmdTableDirect    An ADODataSet is similar to the BDEDataSet used to access database tables. With ADO, you describe the data source and then use data-aware controls to display the data in your application. The first property to set is the CommandType. This property tells the ADO engine what type of command you are going to be calling.    4. Set the ConnectionString property.    The ConnectionString property tells ADO how to connect to the datasource. Click the ellipse to display the ConnectionString dialog. We are going to build the string ourselves so select Use Connection String and click the Build button to display the Data Link Properties dialog. The first choice to make is what data provider are we going to use to get the data. To access Excel we use the Microsoft Jet OLEDB 4.0 Provider, select it and click Next. The next piece is what are we going to connect to. In this case we want to access an Excel file. Use the Browse button and find an Excel file on your system or use Forecast.xls provided in the ADOExcel.zip file. Before we can test the connection we need to enter an Extended Property to the connection string. Click OK to go back the ConnectionString dialog and type 'Extended Properties=Excel 8.0;' without the quotes at the end of the connection string (remember, all ConnectionString entries must be separated by semi-colons. This tells ADO that we need Excel support and use the type library associated with Excel 8.0. Go ahead and click Build again and then Test the connection. If you get Test Connection Succeeded, you did everything right. Close the ConnectionString dialog. The last property to set is the CommandText property.    5. Set the CommandText property.    This property now becomes a combobox that allows you to select the tables defined in the datasource. Choose the name of the spreadsheet with a $ appended to it.    6. Drop a Datasource component from the Data Access tab and a DBGrid from the Data Controls tab.    Now we want to hook up the ADODataset to a grid for display. Connect the Grid to the datasource by setting the DataSource property to DataSource1 and connect the DataSource to the ADODataset by setting the DataSet property to ADODataSet1.    7. Set the Active property of the ADODataSet to True.    We can now test the query in design mode by activating the ADODataSet. The data from the spreadsheet will be displayed in the grid.
系統時間:2024-05-14 5:01:52
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!