欢迎使用CSDN-markdown编辑器

来源:互联网 发布:淘宝邮箱登录格式 编辑:程序博客网 时间:2024/06/05 17:09

angular标签的数据与控制器中的数据使用ng-module进行绑定,达到相互同步数据改变的功效;以下部分放到上面html代码所在的控制器内。

$scope.dateRange = {
values: {},
opts: {}
};

scope.searchCond=withdrawId:,username:,status:,;scope.is_click_button = true;
scope.export = function () {log.debug(‘Export Excel’);

$http({  url: api + "/admin/exportExcelraw?rawId=" + $scope.searchCond.rawId +  "&username=" + $scope.searchCond.username + "&status=" + $scope.searchCond.status +  "&startDate=" + $scope.dateRange.values.startDate +  "&endDate=" + $scope.dateRange.values.endDate,  method: 'get',  responseType: 'arraybuffer'

}).success(function (data, status, headers) {
var type = ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’;
saveAs(new Blob([data], {type: type}), “导出数据.xls”); // 中文乱码
}).error(function (data, status) {
alert(data);
});
};

导出excel

@bp.route(‘/exportExcelWithdraw’, methods=[‘GET’, ‘OPTIONS’])
@allow_cross_domain
@require_admin([‘admin_bill.withdraw_ghb’])
def ghb_withdraw_excel():
args = request.args
withdrawId = args.get(‘withdrawId’)
username = args.get(‘username’)
status = args.get(‘status’)
cond = [rawCash.user_id == GHBUserTransactionExt.user_id]

if withdrawId:    cond.append(rawCash.id == withdrawId)if username:    cond.append(rawCash.user_id == username)if status:    cond.append(rawCash.status == status)start_date = args.get('startDate')end_date = args.get('endDate')if start_date != 'undefined' and end_date != 'undefined':    cond.append(rawCash.time >= dateutil.parser.parse(start_date))    cond.append(rawCash.time < dateutil.parser.parse(end_date))query = db.session.query(rawCash, TransactionExt).filter(*cond).order_by(  rawCash.time.desc())data = [[u'编号', u'提现时间', u'用户名', u'真实姓名', u'金额', u'手续费', u'状态']]if query:    for item in query:        if item.drawCash.status == 'wait_verify':            item.drawCash.status = '等待审核'        elif item.rawCash.status == 'fail':            item.rawCash.status = '未通过'        elif item.rawCash.status == 'success':            item.rawCash.status = '通过'        data.append(            [item.rawCash.id, str(item.rawCash.time), item.rawCash.user_id,             item.TransactionExt.ghb_account_name, item.rawCash.money, item.rawCash.fee,             item.rawCash.status])# 生成excel文件workbook = xlwt.Workbook(encoding='utf-8')sheet = workbook.add_sheet(u'导出数据')row = 0for row_item in data:    col = 0    for col_item in row_item:        sheet.write(row, col, col_item)        col += 1    row += 1output = StringIO.StringIO()workbook.save(output)output.seek(0)return send_file(mimetype='application/vnd.ms-excel',                 as_attachment=True, attachment_filename='导出数据.xls', filename_or_fp=output)
原创粉丝点击