讀取Excel資料寫入資料庫… |
答題得分者是:FrederickPau
|
channel
尊榮會員 發表:67 回覆:707 積分:854 註冊:2002-05-02 發送簡訊給我 |
|
andersonhsieh
版主 發表:33 回覆:531 積分:439 註冊:2002-06-10 發送簡訊給我 |
|
andersonhsieh
版主 發表:33 回覆:531 積分:439 註冊:2002-06-10 發送簡訊給我 |
|
FrederickPau
資深會員 發表:4 回覆:161 積分:268 註冊:2002-11-04 發送簡訊給我 |
我自己做了一個簡單的 ... 請參考
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 發送簡訊給我 |
|
kan0515
中階會員 發表:56 回覆:120 積分:50 註冊:2002-06-24 發送簡訊給我 |
|
richcomp
中階會員 發表:18 回覆:66 積分:51 註冊:2002-10-18 發送簡訊給我 |
以下是我從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.
|
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |