Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Read excel

2025-03-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/03 Report--

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

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report