python - xlsx writing cell_value error, writing to new worksheet -


i'm trying build report generator reads excel sheets , returns rows contain values. built version works require works csv 1st code-mash-together, worked. include conditional formatting (highlight cells values eg. if <65 format red) , required rewrite xlsx sheets rather csv. below attempt @ getting work... can find values , return row, on second run through returns error

attributeerror: 'worksheet' object has no attribute 'cell_value'

which surprising because worked , stepping through code retuns values want.... have tried changing .value, returns:

attributeerror: 'function' object has no attribute 'value'

help, have no idea i'm doing now. if doens't make sense i'm happy post original code csv 'explain'

thanks

import xlsxwriter import xlrd import os import xlwt  # open original excelbook , access first sheet exceldocs in os.listdir('.'):     if not exceldocs.endswith('.xlsx'):         continue    # skip non-xlsx files      workbook = xlrd.open_workbook(exceldocs)     sheet = workbook.sheet_by_index(0)     cellslist = []     = 0 #########works!#####################     row in range(sheet.nrows):         col in range(sheet.ncols):              if sheet.cell_value(row, col) == 'cp' or sheet.cell_value(row, col) == 'lna' or sheet.cell_value(row, col) == 'last name':                 = + 1                 data = [sheet.cell_value(0, col) col in range(sheet.ncols)]                 workbook = xlsxwriter.workbook()                 sheet = workbook.add_worksheet('exceldocs')                  index, value in enumerate(data):                     sheet.write(i, index, value)                 workbook = xlrd.open_workbook(exceldocs) 

i have no experience xlsxwriter, xlrd or xlwt. "1st code-mash-together" figured offer alternative using openpyxl. not have data, testing little difficult, syntax errors fixed. please let me know if not run , fix if required.

i assuming output seperate file(report.xlsx here) , tab each workbook checked(each tab named source book name).

    import openpyxl         openpyxl import *         openpyxl.utils import get_column_letter          interestingvalues = ['cp','lna', 'lastname']         report = workbook()         dest_filename = 'report.xlsx'         # open original excelbook , access first sheet         exceldocs in os.listdir('.'):             if not exceldocs.endswith('.xlsx'):                 continue    # skip non-xlsx files              workbook = load_workbook(exceldocs)             sheet = workbook.active             workingreportsheet = report.create_sheet(str(exceldocs.split('.')[0]))             = 0             row in range(1,sheet.max_row):                 col in range(sheet.max_column):                     columnletter = get_column_letter(col +1)                     if str(sheet['%s%s' % (columnletter,row)].value) in interestingvalues:                         += 1                         data = [sheet['%s%s' % (str(get_column_letter(col)),i)].value col in range(1,sheet.max_column +1)]                         index, value in enumerate(data):                             workingreportsheet['%s%s' % (str(get_column_letter(index+1)),i)].value = value          report.save(filename = dest_filename) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -