{"id":713,"date":"2009-11-05T20:26:00","date_gmt":"2009-11-05T12:26:00","guid":{"rendered":""},"modified":"2013-11-17T16:58:59","modified_gmt":"2013-11-17T08:58:59","slug":"delphi%e5%ae%9e%e7%8e%b0%e6%93%8d%e4%bd%9cexcel%e7%a4%ba%e4%be%8b","status":"publish","type":"post","link":"https:\/\/kyle.ai\/blog\/713.html","title":{"rendered":"Delphi\u5b9e\u73b0\u64cd\u4f5cExcel\u793a\u4f8b"},"content":{"rendered":"<p>\u7b80\u5355\u5b9e\u73b0\u8bfb\u5199Excel\uff0c\u7528C#\u4e5f\u53ef\u4ee5\u5b9e\u73b0\uff0c\u4e0d\u8fc7\u6ca1\u6709Delphi\u65b9\u4fbf\u7b80\u5355\u3002<\/p>\n<pre class=\"brush: delphi; title: ; notranslate\" title=\"\">\r\nimplementation\r\nuses ComOBJ;\r\n\r\n{$R *.dfm}\r\n\r\nprocedure TForm1.Button1Click(Sender: TObject);\r\nvar ExcelAPP1:Variant;\r\n    ExcelApp2:Variant;\r\n    I,j: Integer;\r\n    ID,IDX:string;\r\nbegin\r\ntry\r\n  ExcelAPP1:=CreateOleObject('Excel.Application');\r\n  ExcelAPP1.Workbooks.Open('D:\\Program Files\\Embarcadero\\Projects\\\u64cd\u4f5cExcel\\\u5956.xls');\r\n  ExcelAPP2:=CreateOleObject('Excel.Application');\r\n  ExcelApp2.Workbooks.Open('D:\\Program Files\\Embarcadero\\Projects\\\u64cd\u4f5cExcel\\\u8d2b2.xls');\r\n  for I := 2 to 610 do\r\n  begin\r\n    Label1.Caption:=IntToStr(i)+'\u884c';\r\n    ID:=trim(ExcelAPP1.cells&#x5B;I,2].value);\r\n    for j := 4 to 549 do\r\n    begin\r\n      IDX:=trim(ExcelAPP2.cells&#x5B;j,4].value);\r\n      if (IDX=ID) then\r\n      begin\r\n        ExcelAPP1.cells&#x5B;i,12].value:='\u5df2\u5efa\u6863';\r\n        Break;\r\n      end;\r\n    end;\r\n  end;\r\n  Label1.Caption:='\u5168\u90e8\u5b8c\u6210,\u6b63\u5728\u4fdd\u5b58......';\r\n  ExcelAPP1.Save;\r\n  Label1.Caption:='\u5168\u90e8\u5b8c\u6210,\u5df2\u4fdd\u5b58';\r\nfinally\r\n  ExcelAPP1.WorkBooks.Close;\r\n  ExcelAPP1.Quit;\r\n  ExcelApp2.WorkBooks.Close;\r\n  ExcelAPP2.Quit;\r\nend;\r\nend;\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u7b80\u5355\u5b9e\u73b0\u8bfb\u5199Excel\uff0c\u7528C#\u4e5f\u53ef\u4ee5\u5b9e\u73b0\uff0c\u4e0d\u8fc7\u6ca1\u6709Delphi\u65b9\u4fbf\u7b80\u5355\u3002 implementation use [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[],"class_list":["post-713","post","type-post","status-publish","format-standard","hentry","category-code_related"],"_links":{"self":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/713","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/comments?post=713"}],"version-history":[{"count":1,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/713\/revisions"}],"predecessor-version":[{"id":4714,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/posts\/713\/revisions\/4714"}],"wp:attachment":[{"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/media?parent=713"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/categories?post=713"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/kyle.ai\/blog\/wp-json\/wp\/v2\/tags?post=713"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}