Created
November 8, 2017 19:07
-
-
Save SyntheticDream/23d62e72aa7787a8fc3ca9d6767fe21c 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
from openpyxl import Workbook | |
from pathlib import Path | |
import csv, sys | |
expdir = Path(sys.argv[1]) | |
datfile = expdir / 'Component.dat' | |
__datalen__ = 103 | |
wb = Workbook() | |
ws = wb.active | |
with open(datfile, 'r') as f: | |
l = f.readline() | |
molecules = [m for m in l.split(" ") if m != ''] | |
filtered_molecules = [m for m in molecules if (m is not "E") and ("C" not in m) and ("N" not in m)] | |
print('Only these colums', filtered_molecules) | |
ws.append(filtered_molecules) | |
for row in f: | |
formated_row = [m for m in row.split(" ") if m != ''] | |
filteredrow = [] | |
for i, molecule in enumerate(formated_row): | |
if (molecules[i] is not "E") and ("N" not in molecules[i]) and ("C" not in molecules[i]): | |
filteredrow.append(molecule.replace(".", ",")) | |
ws.append(filteredrow) | |
alphabet = list("ABCDEFGHIJKLMNOPQRSTUVWXYZ") | |
for i in range(1, len(filtered_molecules)+1): | |
for j in range(1, __datalen__+1): | |
c = ws.cell(row=j + 6 + __datalen__, column=i) | |
c.value = f"={alphabet[i-1]}{j}/1" | |
print(c.value) | |
wb.save('testconvert.xlsx') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment