problem reading one excel file and writing a new excel file
Created originally on Bitbucket by bzoltick (Brad Zoltick)
Hi,
I am having problems reading the values from one excel file and writing the values to another excel file. Here I am just writing out the same values but the intent to process the values before writing them to a new excel file. Can you tell me what I am doing wrong? I can read the values but when I try to write them out, the file is empty. {{{ #!python
#!/usr/bin/env python
from openpyxl.reader.excel import load_workbook from openpyxl.workbook import Workbook
xls_old = 'old.xlsx' xls_new = 'new.xlsx'
wb2 = Workbook() ws2 = wb2.create_sheet()
wb1 = load_workbook(xls_old) name = wb1.get_sheet_names()[0] ws2.title = name
ws1 = wb1.get_sheet_by_name(name)
for i, row in enumerate(ws1.rows): for j, cell in enumerate(row): sty = ws1.get_style(cell.address) ws2.cell(cell.address).value = cell.value # how to set the style for ws2.cell ? wb2.save(xls_new) }}}