Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
datetime(2015, 1, 20, 23, 28, 30), "Sports"]
]
}
for upload_file_type in ['xls']:
with app.app_context():
db.drop_all()
db.create_all()
print("Uploading %s" % upload_file_type)
file_name = "test.%s" % upload_file_type
io = pe.save_book_as(bookdict=data,
dest_file_type=upload_file_type)
response = self.app.post('/upload/all',
buffered=True,
data={"file": (io, file_name)},
content_type="multipart/form-data")
ret = pe.get_book_dict(file_type="xls", file_content=response.data)
self.assertEqual(data['category'], ret['category'])
sheet = pe.Sheet(data['post'], name_columns_by_row=0)
sheet.column.format("pub_date", lambda d: d.isoformat())
sheet2 = pe.Sheet(ret['post'], name_columns_by_row=0)
for key in sheet.colnames:
if key == "category":
continue
assert sheet.column[key] == sheet2.column[key]
assert sheet2.column['category_id'] == [1, 2]
def test_save_book_to_memory_from_sql(self):
test_file = pe.save_book_as(
dest_file_type="xls",
session=Session(),
tables=[Signature, Signature2],
)
book_dict = pe.get_book_dict(
file_content=test_file.getvalue(), file_type="xls"
)
expected = OrderedDict()
expected.update({"signature": [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]})
expected.update(
{"signature2": [["A", "B", "C"], [1, 2, 3], [4, 5, 6]]}
)
assert book_dict == expected
def test_update_classic(in_file, test_file, out_file, request):
in_file = test_file(in_file)
assert isinstance(in_file, Path)
shutil.copy(str(in_file.absolute()), str(out_file(out_base=request.node.name, out_format=".xlsx").absolute()))
data = pyexcel.get_book_dict(file_name=str(in_file.absolute()))
debugger_logger.debug(data)
data['TagDict'].append([
'new rosai-dorfman disease',
'''Typically massive lymph node involvement that may also involve extranodal sites
Associated with systemic symptoms (fever, leukocytosis, anemia)
Large histiocytes with abundant pale eosinophilic cytoplasm, mildly atypical round
vesicular nuclei
Lymphocytophagocytosis (emperipolesis) in background of mature lymphocytes and
plasma cells''',
'“Dorfman disease” emperipolesis, HNB'
])
pyexcel_export.save_data(out_file(out_base=request.node.name, out_format=".xlsx", do_overwrite=True), data)
def test_issue_8_hidden_sheet():
test_file = get_fixtures("hidden_sheets.xlsx")
book_dict = pe.get_book_dict(file_name=test_file,
library="pyexcel-xlsx")
assert "hidden" not in book_dict
eq_(book_dict['shown'], [['A', 'B']])
def test_get_book_dict(self):
content = _produce_ordered_dict()
io = pe.save_book_as(dest_file_type="xls", bookdict=content)
adict = pe.get_book_dict(file_content=io.getvalue(), file_type="xls")
assert adict == content
def test_save_book_as_file_from_sql(self):
test_file = "book_from_sql.xls"
pe.save_book_as(
dest_file_name=test_file,
session=Session(),
tables=[Signature, Signature2],
)
book_dict = pe.get_book_dict(file_name=test_file)
expected = OrderedDict()
expected.update({"signature": [["X", "Y", "Z"], [1, 2, 3], [4, 5, 6]]})
expected.update(
{"signature2": [["A", "B", "C"], [1, 2, 3], [4, 5, 6]]}
)
assert book_dict == expected
os.unlink(test_file)
def excel_to_json(file_path: str, sheet_name: str = None, want_sheet_names: bool = False) -> dict:
"""
This function reads the excel file and converts it to JSON
:param file_path:
:param sheet_name:
:param want_sheet_names:
:return:
"""
sheet_data = {'columnDefs': [{'headerName': "", 'field': "^", 'pinned': "left"}], 'rowData': []}
column_index_map = {}
result = dict()
if not sheet_name or want_sheet_names:
result['sheetNames'] = list()
book_dict = pyexcel.get_book_dict(file_name=file_path)
for sheet in book_dict.keys():
result['sheetNames'].append(sheet)
if not sheet_name:
sheet_name = result['sheetNames'][0]
else:
result["sheetNames"] = None
result["currSheetName"] = sheet_name
add_row_in_data_file(file_path, sheet_name)
book = pyexcel.get_book(file_name=file_path)
sheet = book[sheet_name]
for i in range(len(sheet[0])):
column = get_column_letter(i + 1)
column_index_map[i + 1] = column
sheet_data['columnDefs'].append({'headerName': column_index_map[i + 1], 'field': column_index_map[i + 1]})
for row in range(len(sheet)):
r = {'^': str(row + 1)}
def get_book_dict(self, **keywords):
"""Get a dictionary of two dimensional array from the file
:param keywords: additional key words
:returns: A dictionary of two dimensional arrays
"""
params = self.get_params(**keywords)
return pe.get_book_dict(**params)
def _load_pyexcel_xlsx(self):
updated_data = pyexcel.get_book_dict(file_name=str(self.in_file.absolute()))
self.meta.setdefault('_styles', dict())['excel'] = ExcelFormatter(self.in_file).data
return self._set_updated_data(updated_data)