Abdur
Abdur

Reputation: 15

Python Openpyxl Writing in a cell

I cannot seem to write any value in an excel sheet. I open two files at the same time. I want to copy a value from file 1 to file 2. it gives the error

File

"C:\Python34\lib\site-packages\openpyxl\writer\dump_worksheet.py", line 214, in removed_method
    raise NotImplementedError 

Only the line with the writing part gives an error. The function code is as follows

def data_input(size):

    from openpyxl import load_workbook

    wb1 = load_workbook('150318 load matching_Storage_v4.xlsm',data_only=True)
    wb1s1 = wb1.get_sheet_by_name('Home load options')

    from openpyxl import Workbook
    wb2 = Workbook('Data',write_only=True)
    wb2s1 = wb2.create_sheet(0)
    wb2s1.title = "Consumption"

    wb2s1.cell(row = 1, column = 1).value = 4 - this line gives the error

    #what i have to write but block yet to test if i can write at all
    '''i = 0
    r = 0
    while i < 8760:
        d = wb2s1.cell(row = r, column = 1)
        d.value = i
        i = i + 0.25
        r += 1'''


    for i in range(4,35040):
        cell_value1 = wb1s1.cell(row = i, column = (12+size)).value
        print(cell_value1)
     #   cell_value1 = wb2s1.cell(row = i-3, column = 1) 
    wb2.save('Data.xlsx')

I tried all the different ways in the documentation but nothing works so far.

please help.

Thank you

Upvotes: 0

Views: 2465

Answers (1)

Charlie Clark
Charlie Clark

Reputation: 19537

You are creating a write-only workbook. At the name suggests, this is designed for streaming data to a workbook so some operations, such as looking up cells do not work. To add data you should use the append() method. If you do need to add formatting or comments to individual cells you can include a WriteOnlyCell in the iterable that you pass into append().

Upvotes: 1

Related Questions