Commit 5090e388 authored by Recolic Keghart's avatar Recolic Keghart 🎱

allow PROG ALPHA open xlsx and csv

parent 542cdb7d
......@@ -14,7 +14,7 @@ if os.name == 'nt':
from uniqer import *
from utils import *
import material
import csv_preprocess
import csv_preprocess, xlsx_conv
import numpy as np
from io import StringIO
......@@ -36,8 +36,7 @@ def _main():
junk_material_words = ['(厚)', '(宽)', '(单件重)']
junk_part_words = []
with open(fname, mode='r') as fd:
fcontent = fd.read()
fcontent = xlsx_conv.read_as_csv(fname)
fcontent = csv_preprocess.clean_csv(fcontent)
fcontent = csv_preprocess.clean_csv_2(fcontent)
......
......@@ -31,8 +31,7 @@ def execute_program_alpha(mypath, parent_arg1):
print('EXEC =======================>', args)
ret = subprocess.run(args, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
for line in ret.stdout:
print(line)
print(ret.stdout)
if ret.returncode != 0:
raise RuntimeError('SubProcess returned in status ' + str(ret.returncode))
print('EXEC SUBPROC EXITED =======================>')
......
......@@ -55,3 +55,4 @@ def try_copy(file_path, out_dir, dst = None):
shutil.copy(file_path, os.path.join(out_dir, name))
import xlrd
import csv
import config
import csv, io
def xlsx2csv(xlsxPath, sheetIndex, outputFd):
wb = xlrd.open_workbook(xlsxPath)
......@@ -10,4 +9,14 @@ def xlsx2csv(xlsxPath, sheetIndex, outputFd):
for rownum in range(sh.nrows):
wr.writerow(sh.row_values(rownum))
def read_as_csv(fname):
is_xlsx = lambda fname: fname.endswith('.xlsm') or fname.endswith('.xlsx') or fname.endswith('.xls') or fname.endswith('.XLSM') or fname.endswith('.XLSX') or fname.endswith('.XLS')
# read xlsx or csv
if is_xlsx(fname):
buf = io.StringIO()
xlsx2csv(fname, 0, buf)
return buf.getvalue()
else:
with open(fname, mode='r') as fd:
return fd.read()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment