-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow to make OBI Excel sheet for editing templates (#1351)
* Add workflow to make OBI Excel sheet for templates * Add workflow to README
- Loading branch information
1 parent
1e0818a
commit d9b8be2
Showing
6 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ | |
build/ | ||
catalog-v001.xml | ||
junk/ | ||
*.xlsx |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
openpyxl |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import csv | ||
import os | ||
|
||
from openpyxl import Workbook | ||
|
||
parser = argparse.ArgumentParser(description="Merge TSV files into Excel") | ||
parser.add_argument("output", type=str, help="Excel file to create") | ||
parser.add_argument("inputs", type=str, nargs="+", help="TSV files to include") | ||
args = parser.parse_args() | ||
|
||
wb = Workbook() | ||
wb.remove(wb.active) | ||
|
||
for path in args.inputs: | ||
title, extension = os.path.splitext(os.path.basename(path)) | ||
ws = wb.create_sheet(title) | ||
with open(path, "r") as tsvin: | ||
tsv = csv.reader(tsvin, delimiter="\t", quoting=csv.QUOTE_NONE, escapechar='"') | ||
for row in tsv: | ||
ws.append(row[:]) | ||
|
||
wb.save(args.output) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#!/usr/bin/env python3 | ||
|
||
import argparse | ||
import csv | ||
import os | ||
|
||
from openpyxl import load_workbook | ||
|
||
parser = argparse.ArgumentParser(description="Read TSV from Excel") | ||
parser.add_argument("input", type=str, help="Excel file to read") | ||
parser.add_argument("sheet", type=str, help="Sheet name to read") | ||
parser.add_argument("output", type=str, help="TSV file to output") | ||
args = parser.parse_args() | ||
|
||
wb = load_workbook(args.input) | ||
ws = wb[args.sheet] | ||
|
||
rows = [] | ||
for row in ws: | ||
values = [] | ||
for cell in row: | ||
if cell.value is None: | ||
values.append("") | ||
else: | ||
values.append(cell.value) | ||
if row: | ||
rows.append(values) | ||
|
||
with open(args.output, "w") as f: | ||
writer = csv.writer(f, delimiter="\t", lineterminator="\n", quoting=csv.QUOTE_NONE, escapechar='"') | ||
writer.writerows(rows) |