Last active
May 21, 2021 14:30
-
-
Save jmrenouard/62123a0a590e810facd2ff70024fab29 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/python3 | |
import glob | |
import sys | |
import csv | |
from xlsxwriter.workbook import Workbook | |
tsvs = sys.argv[2:] | |
xlsx_file=sys.argv[1] | |
print("File to merge :" +str(tsvs)) | |
print("Result File :" +xlsx_file) | |
# Create an XlsxWriter workbook object and add a worksheet. | |
workbook = Workbook(xlsx_file) | |
for tsv_file in tsvs: | |
worksheet = workbook.add_worksheet() | |
# Create a TSV file reader. | |
tsv_reader = csv.reader(open(tsv_file,'rt'),delimiter="\t") | |
# Read the row data from the TSV file and write it to the XLSX file. | |
for row, data in enumerate(tsv_reader): | |
worksheet.write_row(row, 0, data) | |
# Close the XLSX file. | |
workbook.close() |
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
# pip3 install xlsxwriter | |
or | |
# apt install python3-xlsxwriter | |
# merge_tsv_xlsx.py result_file.xlsx *.tsv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment