Delphi-manipulating Excel

Source: Internet
Author: User

Because work needs, need to operate Excel, first understand how to read Excel this, did a demo, notes here

One, read Excel

UnitUnit1;InterfaceusesWindows, Messages, sysutils, variants, Classes, Graphics, Controls, Forms, Dialogs, stdctrls,comobj;typeTForm1=class(tform) Btn1:tbutton;    Dlgopen1:topendialog; procedureBtn1click (Sender:tobject); Private    {Private Declarations}   Public    {Public Declarations}  End;varForm1:tform1;Implementation{$R *.DFM}procedureTform1.btn1click (sender:tobject);varexcelapp,workbook:olevariant;  Excelrowcount,i:integer; Strname,strage:string;begin  ifDlgopen1.execute Then  beginExcelapp:= Createoleobject ('Excel.Application'); WorkBook:=ExcelApp.WorkBooks.Open (dlgopen1.filename); Excelrowcount:= workbook.worksheets[1].    UsedRange.Rows.Count; //ShowMessage (IntToStr (Excelrowcount));     fori:=1  toexcelrowcount+1  Do    beginStrName:= Excelapp.cells[i,1].      Value; Strage:= Excelapp.cells[i,2].      Value; {exits if one row is empty}      if((strname="') and(strage="')) ThenExitElse      beginShowMessage (strName);      ShowMessage (strage); End; End; End; {finally close the connection}Workbook.close;  Excelapp.quit; Excelapp:=Unassigned; WorkBook:=Unassigned;End;End.

read out the data, insert the database statement, Baidu on the internet to.

   with  do           begin                 Close;                Sql.clear;sql.add (INSERT INTO Test (name,address) VALUES (: name,:address));      Parambyname ('name'). asstring: = excelx;      Parambyname ('address'). asstring: = excely;      Execsql;             End;

Delphi-manipulating Excel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.