Get the App
SLTechnology News&Howtos  ›  Servers  › 

Read excel

Shulou Source: shulou.com Published: 2022-06-03 07:21:35 10月03日 Update

Procedure TfrmBuyingItems.barsaveClick (Sender: TObject)

Var excelx,excely: string

ExcelApp,WorkBook:oleVariant

ExcelRowCount,i:integer

Begin

OpenDialog1.Title: = 'Please select the correct excel file'

OpenDialog1.Filter: = 'Excel (* .xls) | * .xls'

If OpenDialog1.Execute then

Begin

Try

ExcelApp: = CreateOleObject ('Excel.Application')

WorkBook: = CreateOleObject ('Excel.Sheet')

WorkBook: = ExcelApp.WorkBooks.Open (opendialog1.FileName); / / specify using the opendialog dialog box

/ / excel file path

ExcelApp.Visible: = false

ExcelRowCount: = WorkBook.WorkSheets [1] .UsedRange.Rows.Count

For I: = 1 to excelrowcount + 1 do

Begin

Excelx: = excelapp.Cells [iMetro 1] .value

Excely: = excelapp.Cells [iMagazine 2] .value

If ((excelapp.Cells [iMagne1] .value =') and (ExcelApp.Cells [iMagne2] .Value ='') then

/ / specify line I of the excel file, line 1jin2 (as the case may be) and exit if it is empty. This setting had better be yours.

/ / archival power these two lines / / corresponding to the data in the database that cannot be empty

Exit

Else

With adoquery1 do

Begin

Close

Sql.clear

Sql.add ('insert into test (name,address) values (: name,:address)')

The first column of the Parameters.parambyname ('name') .value: = excelx;//excel file is inserted into the name field of the test table

The second column of the Parameters.parambyname ('address') .value: = excely;//excel file is inserted into the address field of the test table

Execsql

End

End

Finally

WorkBook.Close

ExcelApp.Quit

ExcelApp: = Unassigned

WorkBook: = Unassigned

End

End

End

Tags: Data dialog box situation database file best file path depends dialog select Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MySQL Redmi Docker Microsoft Shulou Technology