0

I am trying to get my output from my code to go into an excel spread sheet and I keep getting this specific error:

"Exception: Attempt to overwrite cell: sheetname=u'Sheet 1' rowx=1 colx=0"

How I have my code set up is how I need it in order to find the items and print the desired result since I am using it to scrape .PDFs and it will produce the exact output needed if I wanted to put it all into a text file. But I am hoping to output to excel so I can specify where the data should go. It seems that because the output of code cycles through the results it also tries to put everything in row 0, column 0 continuously and I keep getting an error about overriding data.

    from xlwt import Workbook, Formula, easyxf
    wb = Workbook()
    sheet1 = wb.add_sheet('Sheet 1')
    lines = open("register.txt", "r").readlines()

    search_counters = {
        "Per End": 0,
    }
    lines=[line for line in lines if line]  # removes empty lines, if there are any
    for i, line in enumerate(lines):
        for search_key in search_counters.keys():
            if search_key in line:
                # print the previous line if the current line contains "Per End"
                search_counters[search_key] += 1  
                if search_key == "Per End":
                    print lines[i-1]
                    EE_Name = lines[i-1]
    wb.save('payroll2.xls')
Jason Jabbour
  • 47
  • 2
  • 9
  • Sorry to be vague. I do not want the output overwritten. I need it to list as the data outputs into new rows for column one. – Jason Jabbour Jun 13 '17 at 14:55

1 Answers1

0

XLWT does not implicitly allow cell overwrite. See the answer to a similar question here: Python XLWT attempt to overwrite cell workaround

Basically to get around the overwrite exception you need your sheet creation line to look like this:

sheet1 = wb.add_sheet('Sheet 1', cell_overwrite_ok=True)

But doing so will result in your Sheet 1 always being overwritten. Is that what you want?

BoboDarph
  • 2,751
  • 1
  • 10
  • 15
  • I do not want it to overwrite. I would like them to just list the data in the next row until there is no more data to go through. – Jason Jabbour Jun 13 '17 at 14:54