{"id":6033,"date":"2017-09-22T08:15:51","date_gmt":"2017-09-21T23:15:51","guid":{"rendered":"http:\/\/excelwork.info\/excel\/?p=6033"},"modified":"2017-09-22T08:15:51","modified_gmt":"2017-09-21T23:15:51","slug":"csvado","status":"publish","type":"post","link":"https:\/\/excelwork.info\/excel\/csvado\/","title":{"rendered":"CSV\u30d5\u30a1\u30a4\u30eb\u306b\u63a5\u7d9a\uff08ADO\uff09"},"content":{"rendered":"<h2>ADO\u3067CSV\u30d5\u30a1\u30a4\u30eb\u306b\u63a5\u7d9a<\/h2>\n<div class=\"m30-l\">\n<p>ADO \u3092\u4f7f\u7528\u3057\u3066CSV\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002CSV\u30d5\u30a1\u30a4\u30eb\u3092\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u30c6\u30fc\u30d6\u30eb\u3068\u307f\u306a\u3057\u3001SQL\u6587\u3092\u4f7f\u3046\u3053\u3068\u304c\u51fa\u6765\u307e\u3059\u3002<\/p>\n<br \/>\n<div class=\"kkbox\"><strong>\u3010\u63a5\u7d9a\u6587\u5b57\u5217\u3011<\/strong><\/p>\n<p>    <span class=\"red\"><strong>\uff1cConnectionString\uff08ADO\uff09\u306b\u8a2d\u5b9a\u3059\u308b\u6587\u5b57\u5217\uff1e<\/strong><\/span><br \/>\n    <strong>Provider<\/strong> = <strong>Microsoft.Jet.OLEDB.4.0<\/strong>;<br \/>\n    <strong>Data Source<\/strong> = <em>DBFileName<\/em>;<br \/>\n    <strong>Extended Properties<\/strong> = <em>EXProperties<\/em>;<\/p><\/div>\n<br \/>\n<h4>\u5f15\u6570\u30fb\u623b\u308a\u5024<\/h4>\n<div class=\"m30-l\">\n<ul style=\"margin-top:0;margin-bottom:0;padding-top:0;padding-bottom:0;\">\n<li>DBFileName&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\u5bfe\u8c61\u3068\u306a\u308bCSV\u30d5\u30a1\u30a4\u30eb\u306e\u30d1\u30b9\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\uff08\u203b\u30d5\u30a1\u30a4\u30eb\u540d\u306f\u4e0d\u8981\u3067\u3059\u3002\u307e\u305f\u3001\u30d1\u30b9\u306e\u6700\u5f8c\u306b\u306f\u300c\\\u300d\u304c\u5fc5\u8981\u3067\u3059\u3002\uff09<\/li>\n<li>EXProperties&nbsp;&nbsp;\u30fb\u30fb\u30fb&nbsp;&nbsp;\uff13\u3064\u306e\u30d7\u30ed\u30d1\u30c6\u30a3\u5024\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002\u5404\u30d7\u30ed\u30d1\u30c6\u30a3\u5024\u306f\u300c;\uff08\u30bb\u30df\u30b3\u30ed\u30f3\uff09\u300d\u3067\u533a\u5207\u308a\u307e\u3059\u3002\u5168\u4f53\u3092\u300c&#8221;\u300d\u3067\u62ec\u308a\u307e\u3059\u3002<br \/>\n\t\uff08\u4f8b\uff09Extended Properties = &#8220;Text;HDR=Yes;FMT=Delimited&#8221;<\/li>\n<\/ul><\/div>\n<br \/>\n<p class=\"caution4\"><strong>Extended Properties<\/strong> \u306b\u6307\u5b9a\u3059\u308b\u5404\u30d7\u30ed\u30d1\u30c6\u30a3\u5024\u306b\u3064\u3044\u3066<br \/>\n      \u30fb<strong>Text<\/strong> \u306f\u3001\u30c7\u30fc\u30bf\u30d9\u30fc\u30b9\u306e\u7a2e\u985e\u3092\u8868\u3057\u3066\u3044\u307e\u3059\uff08\u30c6\u30ad\u30b9\u30c8\u30d5\u30a1\u30a4\u30eb\uff09\u3002<br \/>\n      \u30fb<strong>HDR<\/strong> \u306f\u3001CSV\u30d5\u30a1\u30a4\u30eb\u306e\uff11\u884c\u76ee\u3092\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\u3068\u3057\u3066\u6271\u3046\u304b\u3069\u3046\u304b\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<strong>No<\/strong> \u3092\u6307\u5b9a\u3057\u305f\u5834\u5408\u3001\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\u306f\u3001F1\u3001F2\u3001F3 \u306e\u3088\u3046\u306b <strong>F[\u5217\u756a\u53f7]<\/strong> \u3067\u8868\u793a\u3055\u308c\u307e\u3059\u3002<br \/>\n      \u30fb<strong>FMT<\/strong> \u306f\u3001\u30d5\u30a1\u30a4\u30eb\u306e\u30d5\u30a9\u30fc\u30de\u30c3\u30c8\u3092\u6307\u5b9a\u3057\u307e\u3059\u3002CSV\u30d5\u30a1\u30a4\u30eb\u306e\u5834\u5408\u3001<strong>Delimited<\/strong> \u3092\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p class=\"caution4\">CSV\u30d5\u30a1\u30a4\u30eb\u540d\u306f\u3001\u30c6\u30fc\u30d6\u30eb\u540d\u3068\u3057\u3066\u6271\u3044\u307e\u3059\u3002<br \/>\n    \uff08\u4f8b\uff09Select * from [CSV\u30d5\u30a1\u30a4\u30eb\u540d];<\/p>\n<\/div>\n<br \/><br \/>\n<h2>CSV\u30d5\u30a1\u30a4\u30eb\u3078\u63a5\u7d9a\u3059\u308b\u4f8b<\/h2>\n<div class=\"m30-l\">\n<h3 id=\"vba_sample\">\u30b5\u30f3\u30d7\u30ebVBA\u30bd\u30fc\u30b9<\/h3>\n<pre class=\"lang:vb mark:0 decode:true \" title=\"CSV \u30d5\u30a1\u30a4\u30eb \u3078\u63a5\u7d9a\uff08\u53c2\u7167\u8a2d\u5b9a\uff09\" data-url=\"http:\/\/example.co.jp\" >\r\n\u3000\r\nSub Sample_ADO_CSV()\r\n\r\n    Dim cn As New ADODB.Connection\r\n    Dim rs As New ADODB.Recordset\r\n    Dim constr As String\r\n    Dim DBFilePath As String\r\n    Dim DBFileName As String\r\n    Dim EXProperties As String\r\n    Dim strSQL As String\r\n    Dim i As Long\r\n    Dim j As Long\r\n    \r\n    DBFilePath = ActiveWorkbook.Path & \"\\\"\r\n    DBFileName = \"mydb1.csv\"\r\n    EXProperties = \"\"\"Text;HDR=Yes;FMT=Delimited\"\"\"\r\n    \r\n    constr = \"Provider=Microsoft.Jet.OLEDB.4.0;\" & _\r\n             \"Data Source=\" & DBFilePath & \";Extended Properties=\" & EXProperties\r\n    \r\n    cn.ConnectionString = constr\r\n    cn.Open\r\n    \r\n    strSQL = \"Select * from \" & DBFileName & \" order by ID;\"\r\n    rs.Source = strSQL\r\n    rs.ActiveConnection = cn\r\n    rs.Open\r\n    \r\n    With Worksheets(\"csv\")\r\n    \r\n        .Cells.Clear\r\n        i = 1\r\n        Do Until rs.EOF\r\n            For j = 0 To rs.Fields.Count - 1\r\n                If i = 1 Then .Cells(i, j + 1) = rs.Fields(j).Name\r\n                .Cells(i + 1, j + 1) = rs(j).Value\r\n            Next j\r\n            rs.MoveNext\r\n            i = i + 1\r\n        Loop\r\n    \r\n    End With\r\n    \r\n    rs.Close\r\n    Set rs = Nothing\r\n    \r\n    cn.Close\r\n    Set cn = Nothing\r\n    \r\nEnd Sub\r\n\u3000\r\n  <\/pre>\n<br \/>\n<h3>\u5b9f\u884c\u7d50\u679c<\/h3>\n<p><a href=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/cvsado_01.jpg?ssl=1\" rel=\"lightbox[6033]\"><img loading=\"lazy\" src=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/cvsado_01.jpg?resize=545%2C333&#038;ssl=1\" alt=\"CSV\u30d5\u30a3\u30a2\u30eb\u306b\u63a5\u7d9a\uff08ADO\uff09\" width=\"545\" height=\"333\" class=\"alignnone size-full wp-image-6038\" srcset=\"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/cvsado_01.jpg?w=545&amp;ssl=1 545w, https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/cvsado_01.jpg?resize=400%2C244&amp;ssl=1 400w\" sizes=\"(max-width: 545px) 100vw, 545px\" data-recalc-dims=\"1\" \/><\/a><\/p>\n<\/div>\n<br \/><br \/>\n","protected":false},"excerpt":{"rendered":"<p>ADO\u3067CSV\u30d5\u30a1\u30a4\u30eb\u306b\u63a5\u7d9a ADO \u3092\u4f7f\u7528\u3057\u3066CSV\u30d5\u30a1\u30a4\u30eb\u3092\u8aad\u307f\u8fbc\u307f\u307e\u3059\u3002C &#8230; <\/p>\n","protected":false},"author":1,"featured_media":6038,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"amp_status":"","spay_email":"","jetpack_publicize_message":""},"categories":[948],"tags":[950,963,954,964,952,951,814,955,949],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/excelwork.info\/excel\/wp\/wp-content\/uploads\/2017\/07\/cvsado_01.jpg?fit=545%2C333&ssl=1","jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/s4Ye9i-csvado","_links":{"self":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6033"}],"collection":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/comments?post=6033"}],"version-history":[{"count":12,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6033\/revisions"}],"predecessor-version":[{"id":6427,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/posts\/6033\/revisions\/6427"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media\/6038"}],"wp:attachment":[{"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/media?parent=6033"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/categories?post=6033"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/excelwork.info\/excel\/wp-json\/wp\/v2\/tags?post=6033"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}