예제 #1
0
def uploadFile():
    form = request.form.to_dict()
    id = form.get('id')
    print('上传接受的参数', form)
    print('接收信息', request.files)
    file = request.files['file']
    print('file', type(file), file)
    print('文件名', file.filename)  # 打印文件名
    print('name', file.name)
    f = file.read()  # 文件内容
    data = xlrd.open_workbook(file_contents=f)
    table = data.sheets()[0]
    names = data.sheet_names()  # 返回book中所有工作表的名字

    status = data.sheet_loaded(names[0])  # 检查sheet1是否导入完毕
    print('导入状态', status)
    nrows = table.nrows  # 获取该sheet中的有效行数
    ncols = table.ncols  # 获取该sheet中的有效列数
    # print('nrows',nrows)
    # print('ncols',ncols)
    s = table.col_values(2)  # 第1列数据
    print('尺码', s)
    table_name = names[0]
    Batch.update(id=id, upload=1, excel_name=form.get('excel_name'))
    Stock.delete_by_batch_id(id=id)
    res = formatExcel(table)
    # 根据文件名添加批次
    for r in res:
        r['batch'] = form.get('id')

    r = Stock.add_by_list(res)
    # print('导入结果', r)
    return make_response(jsonify(Res.success(r)))
예제 #2
0
def delete():
    form = request.form.to_dict()
    id = form.get('id')
    r = Stock.delete_by_batch_id(id=id)
    r = Batch.delete_by_ids(id)
    r = Batch.all()
    print('删除', r)
    return make_response(jsonify(r))