Exemplo n.º 1
0
def ExportExcel(request):
    fields = request.GET['fields']
    filters = request.GET['filters']
    tableName = request.GET['tableName']
    sortField = request.GET['sortField']

    if not sortField:
        sortField = "SORTCODE"

    dt = DbCommonLibaray.GetDTByPage(tableName, filters, sortField, fields, 1,
                                     99999)

    response = HttpResponse(content_type='application/vnd.ms-excel')
    response['Content-Disposition'] = 'attachment;filename=' + tableName + str(
        datetime.datetime.now()) + '.xls'
    wb = xlwt.Workbook(encoding='utf8')
    sheet = wb.add_sheet(tableName)

    if len(dt) > 0:
        i = 0
        headerDic = []
        for headerKey in dt[0].keys():
            sheet.write(0, i, headerKey)
            headerDic.append(headerKey)
            i = i + 1

        data_row = 1
        for excelValue in dt:
            data_col = 0
            for header in headerDic:
                sheet.write(data_row, data_col, excelValue.get(header))
                data_col = data_col + 1
            data_row = data_row + 1

    output = BytesIO()
    wb.save(output)
    output.seek(0)
    response.write(output.getvalue())
    return response
Exemplo n.º 2
0
    def GetFileDTByPage(self,
                        pageIndex=1,
                        pageSize=20,
                        whereConditional="",
                        order=""):
        """
        分页获取文件
        Args:
            pageIndex (string): 页数
            pageSize (string): 每页数据大小
            whereConditional (string): 查询条件
            order (string): 排序方式
        Returns:
            returnValue (List[Cifile] or None): 文件列表
        """
        SelectField = 'ID'
        + "        ," + 'FOLDERID'
        + "        ," + 'FILENAME'
        + "        ," + 'FILEPATH'
        + "        ," + 'FILESIZE'
        + "        ," + 'READCOUNT'
        + "        ," + 'CATEGORY'
        + "        ," + 'DESCRIPTION'
        + "        ," + 'ENABLED'
        + "        ," + 'SORTCODE'
        + "        ," + 'CREATEUSERID'
        + "        ," + 'CREATEBY'
        + "        ," + 'CREATEON'
        + "        ," + 'MODIFIEDUSERID'
        + "        ," + 'MODIFIEDBY'
        + "        ," + 'MODIFIEDON'
        + "       , (SELECT " + 'FOLDERNAME'
        + " FROM " + 'cifolder'
        + " WHERE " + 'ID' + " = '" + 'FOLDERID' + "') AS FolderFullName "

        returnValue = DbCommonLibaray.GetDTByPage('cifile', whereConditional,
                                                  order, SelectField,
                                                  pageIndex, pageSize)
        return len(returnValue), returnValue