0

I have a problem when I'm trying to save and than read excel file in python. So this is my function:

import openpyxl
import xlrd
from xlutils.copy import copy
import pandas as pd

def write_excel():
  wb = openpyxl.load_workbook('8de69ccb60047ce5.xlsx')
  sheet = wb.active

  sheet['D18'] = 3

  wb.save('8de69ccb60047ce5.xls')

  df1 = pd.read_excel('8de69ccb60047ce5.xls', sheet_name='Лист1', header=None, skiprows=1, usecols="H,I")
  print(df1)

  workbook = xlrd.open_workbook('8de69ccb60047ce5.xls')
  worksheet = workbook.sheet_by_index(0)
  print(worksheet.cell(17, 8).value)
  print(worksheet.cell(18, 8).value)

I'm changing cell D18, saving file and than trying to read other cells that has formulas but I get nothing (also cell without formulas read correctly). But if I open file manually and save it in Excel that lines of code read those cells correctly.

The problem is this line wb.save('8de69ccb60047ce5.xls'). It saves changes in file but it doesn't saves file correctly (I don't know how to discribe it). How can I read cell with formula after changing the file in python?

1 Answer 1

1

Save a file as sample_book.xlsx with save function.

wb.save(filename = 'sample_book.xlsx')

For more info check out this link: https://www.soudegesu.com/en/post/python/create-excel-with-openpyxl/#save-file

Sign up to request clarification or add additional context in comments.

1 Comment

Doesn't help. Still can't get value from cell with formula.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.