-
テスト内容 1
- 確認事項 1
-
テスト内容 2
- 確認事項 2
-
テスト内容 3
- 確認事項 3
-
テスト内容 4
- 確認事項 4
-
テスト内容 5
- 確認事項 5-1
- 確認事項 5-2
-
テスト内容 6
- 確認事項 6-1
- 確認事項 6-2
- 確認事項 6-3
source "https://rubygems.org" | |
gem 'redcarpet' | |
gem 'rubyXL' |
require 'bundler/setup' | |
Bundler.require | |
file = File.open('./demo.md').read | |
renderer = Redcarpet::Render::HTML.new | |
markdown = Redcarpet::Markdown.new(renderer) | |
html = markdown.render(file) | |
REGEXP_PATTERNS = { | |
category: %r{\A<h2>(?<text>.*)</h2>\Z}, | |
feature: %r{\A<h3>(?<text>.*)</h3>\Z}, | |
case: %r{\A<li><p>(?<text>.*)</p>\Z}, | |
check: %r{\A<li>(?<text>.*)</li>\Z} | |
} | |
check_list = [] | |
check_item = {} | |
html.each_line do |line| | |
REGEXP_PATTERNS.each do |k, v| | |
if m = line.match(v) | |
text = m[:text] | |
check_item[k] = text | |
check_list.push(check_item.clone) if k == :check | |
end | |
end | |
end | |
puts check_list | |
workbook = RubyXL::Parser.parse('template.xlsx') | |
worksheet = workbook[0] | |
worksheet.sheet_name = 'テストシート' | |
# ヘッダーの行数分ずらす | |
base_row = 1 | |
check_list.each.with_index do |item, index| | |
row = index + base_row | |
%i(category feature case check).each.with_index do |k, i| | |
worksheet.add_cell(row, i, item[:category]) | |
end | |
end | |
workbook.write('demo.xlsx') |