{"id":12103,"date":"2019-07-17T09:26:39","date_gmt":"2019-07-17T00:26:39","guid":{"rendered":"https:\/\/elleneast.com\/?p=12103"},"modified":"2019-08-22T19:50:42","modified_gmt":"2019-08-22T10:50:42","slug":"%e3%80%90vb-net%e3%80%91closedxml%ef%bc%9a%e3%83%86%e3%83%bc%e3%83%96%e3%83%ab%e3%81%ae%e4%bd%9c%e6%88%90%ef%bc%88%ef%bc%93%ef%bc%89","status":"publish","type":"post","link":"https:\/\/elleneast.com\/?p=12103","title":{"rendered":"\u3010VB.NET\u3011ClosedXML\uff1a\u30c6\u30fc\u30d6\u30eb\u306e\u4f5c\u6210\uff08\uff13\uff09"},"content":{"rendered":"[include-page id=\u201d11760\u2033]\n<p>\u4e0b\u56f3\u306e\u3088\u3046\u306a\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n<p><a href=\"https:\/\/elleneast.com\/wp\/wp-content\/uploads\/programming_topics\/ClosedXML\/ClosedXml_57.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-12105 bigshadow\" src=\"https:\/\/elleneast.com\/wp\/wp-content\/uploads\/programming_topics\/ClosedXML\/ClosedXml_57.png\" alt=\"\" width=\"793\" height=\"214\" srcset=\"https:\/\/elleneast.com\/wp\/wp-content\/uploads\/programming_topics\/ClosedXML\/ClosedXml_57.png 793w, https:\/\/elleneast.com\/wp\/wp-content\/uploads\/programming_topics\/ClosedXML\/ClosedXml_57-300x81.png 300w, https:\/\/elleneast.com\/wp\/wp-content\/uploads\/programming_topics\/ClosedXML\/ClosedXml_57-768x207.png 768w\" sizes=\"auto, (max-width: 793px) 100vw, 793px\"><\/a><\/p>\n<p>&nbsp;<\/p>\n<pre class=\"lang:vbnet decode:true \">Dim wb = new XLWorkbook\nDim ws = wb.Worksheets.Add(\"\u9854\u6587\u5b57\")\n \n'\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\nDim dataList = New List(Of String())\ndataList.Add(New String() {\"\u5e73\u9759\", \"\u30b9\u30de\u30a4\u30eb\", \"\u72fc\u72fd\", \"\u54c0\u3057\u307f\", \"\u6012\u308a\"})\ndataList.Add(New String() {\"(*\u00b4\u03c9\uff40*)\", \"(*^_^*)\", \"(;^\u03c9^)\", \"( \uff1b\u2200\uff1b)\", \"(# \uff9f\u0414\uff9f)\"})\ndataList.Add(New String() {\"\uff08\u30fb\uff3f\u30fb\uff09\", \"(*^\u25bd^*)\", \"(~_~;)\", \"\uff08\uff34\uff3f\uff34\uff09\", \"(; \uff65`\u0434\uff65\u00b4)\"})\nws.Cell(\"B2\").Value = dataList '\u30b7\u30fc\u30c8\u306b\u30c7\u30fc\u30bf\u3092\u633f\u5165\n\n'\u30b7\u30fc\u30c8\u4e0a\u306e\u30c7\u30fc\u30bf\u7bc4\u56f2\u3092\u53d6\u5f97\nDim range = ws.Range(ws.FirstCellUsed, ws.LastCellUsed)\n\n'\u53d6\u5f97\u3057\u305f\u30c7\u30fc\u30bf\u7bc4\u56f2\u3092\u30c6\u30fc\u30d6\u30eb\u3068\u3057\u3066\u81ea\u52d5\u7684\u306b\u88c5\u98fe\u3057\u3066 IXLTable \u3092\u8fd4\u3059\u3002\nDim orgTable = range.CreateTable '\u30c6\u30fc\u30d6\u30eb\u540d\uff08\u540d\u524d\u4ed8\u304d\u7bc4\u56f2\uff09\u306f \"Table1\" \u306b\u306a\u308b\u3002\n'\u30b7\u30fc\u30c8\u4e0a\u306b\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u305f\u304f\u306a\u3044\u5834\u5408\u306f range.AsTable \u3092\u4f7f\u7528\u3057\u3066\n'\u30c6\u30fc\u30d6\u30eb\u3068\u3057\u3066\u7bc4\u56f2\u3092\u64cd\u4f5c\u3059\u308b\u3053\u3068\u3082\u3067\u304d\u307e\u3059\u3002\n\n\n\n'\uff12\u3064\u76ee\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u3001\u6700\u521d\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u30d8\u30c3\u30c0\u30fc\u3092\u5168\u3066\u30b3\u30d4\u30fc\u3059\u308b\nDim SecondTblStartColNum As Int32 = orgTable.LastColumn.ColumnNumber + 2\nDim currentRow As Int32 = orgTable.FirstCell.WorksheetRow.RowNumber\nDim secondTblTitle As String = \"\u30d8\u30c3\u30c0\u4e00\u89a7\"\nws.Cell(currentRow, SecondTblStartColNum).Value = secondTblTitle\nFor Each cell In orgTable.HeadersRow.Cells\n  currentRow += 1\n  ws.Cell(currentRow, SecondTblStartColNum).Value = cell.Value\nNext\n\nDim secondTblFirstCell = ws.Cell(orgTable.FirstCell.WorksheetRow.RowNumber, SecondTblStartColNum)\nDim secondTblLastCell = ws.Cell(currentRow, SecondTblStartColNum)\n'\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u3066 IXLTable \u3092\u53d6\u5f97\u3002 '\u30c6\u30fc\u30d6\u30eb\u540d\uff08\u540d\u524d\u4ed8\u304d\u7bc4\u56f2\uff09\u306f \"\u30d8\u30c3\u30c0\u30c7\u30fc\u30bf\" \u306b\u306a\u308b\u3002\nDim secondTable = ws.Range(secondTblFirstCell, secondTblLastCell).CreateTable(\"\u30d8\u30c3\u30c0\u30c7\u30fc\u30bf\")\n'\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30b6\u30a4\u30f3\u3092\u5909\u3048\u308b\nsecondTable.Theme = XLTableTheme.TableStyleLight10\n'\u5217\u30bf\u30a4\u30c8\u30eb\u306b\u30aa\u30fc\u30c8\u30d5\u30a3\u30eb\u30bf\u30fc\u306f\u4ed8\u3051\u306a\u3044\nsecondTable.ShowAutoFilter = False\n\n'\uff12\u3064\u76ee\u306e\u30c6\u30fc\u30d6\u30eb\u306b\u30ab\u30b9\u30bf\u30e0\u306e\u5f0f\u3092\u8ffd\u52a0\nsecondTable.ShowTotalsRow = True\nsecondTable.Field(0).TotalsRowFormulaA1 = \"CONCATENATE(\"\"\u5408\u8a08\uff1a\"\", CountA([\" &amp; secondTblTitle &amp; \"]))\"\n\n\n\n'\uff13\u3064\u76ee\u306e\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u3001\u6700\u521d\u306e\u30c6\u30fc\u30d6\u30eb\u306e\u9854\u6587\u5b57\u306e\u4e00\u90e8\u3092\u30b3\u30d4\u30fc\u3059\u308b\nDim ThirdTblStartColNum As Int32 = SecondTblStartColNum + 2\ncurrentRow = orgTable.RangeAddress.FirstAddress.RowNumber 'currentRow \u3092\u30ea\u30bb\u30c3\u30c8\nws.Cell(currentRow, ThirdTblStartColNum).Value = \"\u5e73\u9759\uff06\u30b9\u30de\u30a4\u30eb\"\nFor Each row In orgTable.DataRange.Rows\n  currentRow += 1\n  Dim kao1 = row.Field(\"\u5e73\u9759\").GetString '\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\u3092\u4f7f\u3063\u3066\u30bb\u30eb\u306b\u30a2\u30af\u30bb\u30b9\n  Dim kao2 = row.Field(\"\u30b9\u30de\u30a4\u30eb\").GetString '\u30d5\u30a3\u30fc\u30eb\u30c9\u540d\u3092\u4f7f\u3063\u3066\u30bb\u30eb\u306b\u30a2\u30af\u30bb\u30b9\n  Dim kaokao = String.Format(\"{0} {1}\", kao1, kao2)\n  ws.Cell(currentRow, ThirdTblStartColNum).Value = kaokao\nNext\n\nDim ThirdTblFirstCell = ws.Cell(orgTable.RangeAddress.FirstAddress.RowNumber, ThirdTblStartColNum)\nDim ThirdTblLastCell = ws.Cell(currentRow, ThirdTblStartColNum)\n'\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u3066 IXLTable \u3092\u53d6\u5f97\u3002 '\u30c6\u30fc\u30d6\u30eb\u540d\uff08\u540d\u524d\u4ed8\u304d\u7bc4\u56f2\uff09\u306f \"Table2\" \u306b\u306a\u308b\u3002\nDim thirdTable = ws.Range(ThirdTblFirstCell, ThirdTblLastCell).CreateTable\n'\u30c6\u30fc\u30d6\u30eb\u306e\u30c7\u30b6\u30a4\u30f3\u3092\u5909\u3048\u308b\nthirdTable.Theme = XLTableTheme.TableStyleLight12\n'\u5217\u30bf\u30a4\u30c8\u30eb\u306b\u30aa\u30fc\u30c8\u30d5\u30a3\u30eb\u30bf\u30fc\u306f\u4ed8\u3051\u306a\u3044\nthirdTable.ShowAutoFilter = False\n\n\n\n'\u30b3\u30f3\u30c6\u30f3\u30c4\u306b\u5408\u308f\u305b\u3066\u5217\u5e45\u3092\u8abf\u6574\n'\u30b3\u30f3\u30c6\u30f3\u30c4\u304c\u65e5\u672c\u8a9e\u306e\u5834\u5408\u306f\u65e5\u672c\u8a9e\u30d5\u30a9\u30f3\u30c8\u306b\u3057\u3066\u304a\u304b\u306a\u3044\u3068 AdjustToContents \u304c\u6b63\u3057\u304f\u52d5\u4f5c\u3057\u306a\u3044\nws.Style.Font.FontName = \"\u6e38\u30b4\u30b7\u30c3\u30af\";\nws.Columns.AdjustToContents\n'\u8907\u6570\u306e\u5217\u5e45\u3092\u8a2d\u5b9a\nws.Columns(\"A,G,I\").Width = 3\n\nwb.SaveAs(\"C:\\test\\KaoTables.xlsx\")<\/pre>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/elleneast.com\/?cat=90\">\u300c\u3010VB.NET\u3011ClosedXML \u306e\u4f7f\u3044\u65b9\u300d\u306e\u4e00\u89a7\u3092\u8868\u793a<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>[include-page id=\u201d11760\u2033] \u4e0b\u56f3\u306e\u3088\u3046\u306a\u30c6\u30fc\u30d6\u30eb\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002 &nbsp; Dim wb = new XLWorkbook Dim ws = wb.Worksheets.Add(&#8220;\u9854\u6587\u5b57&#8221;) &#8216; &#8230; <\/p>\n","protected":false},"author":1,"featured_media":2656,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[90],"tags":[],"class_list":{"0":"post-12103","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-closedxml"},"_links":{"self":[{"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/posts\/12103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/elleneast.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=12103"}],"version-history":[{"count":3,"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/posts\/12103\/revisions"}],"predecessor-version":[{"id":12956,"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/posts\/12103\/revisions\/12956"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/elleneast.com\/index.php?rest_route=\/wp\/v2\/media\/2656"}],"wp:attachment":[{"href":"https:\/\/elleneast.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=12103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/elleneast.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=12103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/elleneast.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=12103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}