{"id":150,"date":"2015-07-08T19:05:00","date_gmt":"2015-07-08T23:05:00","guid":{"rendered":"http:\/\/www.dev-notes.com\/blog\/2015\/07\/08\/insert-microsoft-word-content-into-oracle-database\/"},"modified":"2015-07-08T19:05:00","modified_gmt":"2015-07-08T23:05:00","slug":"insert-microsoft-word-content-into-oracle-database","status":"publish","type":"post","link":"https:\/\/www.dev-notes.com\/blog\/2015\/07\/08\/insert-microsoft-word-content-into-oracle-database\/","title":{"rendered":"Insert Microsoft Word content into Oracle database"},"content":{"rendered":"<p>The following sample is over-simplified, but it shows how we can iterate through tables (and their columns and rows) to extract text, and in turn inserting them into an Oracle table.<\/p>\n<pre class=\"code\">\nOption Explicit\n\nPublic Sub InsertIntoOracle()\n    Dim cn As ADODB.Connection\n    Dim source, user, password, str As String\n    Dim aTable As Table\n    Dim tbl, row, col As Long\n\n    source = \"database\"\n    user = \"scott\"\n    password = \"tiger\"\n    tbl = 0\n\n    Set cn = New ADODB.Connection\n    cn.Open \"Provider = OraOLEDB.Oracle; Data Source=\" & source & \"; User Id=\" & user & \"; Password=\" & password & \"\"\n    cn.BeginTrans\n    For Each aTable In ActiveDocument.Tables\n        tbl = tbl + 1\n        For row = 1 To aTable.Rows.Count\n            For col = 1 To aTable.Columns.Count\n                str = Trim(aTable.Cell(row, col).Range.Text)\n                If (Len(str) > 2) Then\n                    cn.Execute \"insert into document_content values('\" & tbl & \"-\" & row & \"-\" & col & \": \" & str & \"')\"\n                End If\n            Next\n        Next\n    Next\n\n    If cn.Errors.Count = 0 Then\n        cn.CommitTrans\n    Else\n        cn.RollbackTrans\n    End If\n\n    cn.Close\nEnd Sub\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Using MS Word&#8217;s built-in macro capability, we can extract and manipulate Word content for insertion into a database.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[20,16],"tags":[],"class_list":["post-150","post","type-post","status-publish","format-standard","hentry","category-oracle","category-word"],"_links":{"self":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/150","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/comments?post=150"}],"version-history":[{"count":0,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/posts\/150\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/media?parent=150"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/categories?post=150"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dev-notes.com\/blog\/wp-json\/wp\/v2\/tags?post=150"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}