G
G
Gleb Lukashonok2019-09-23 01:12:03
Python
Gleb Lukashonok, 2019-09-23 01:12:03

Win32com.client xlsx to pdf - how to save formulas?

Good afternoon! I am working with an Excel spreadsheet and I want to upload it in two versions: xlsx and pdf. The problem is that in xlsx the formula works correctly, but in pdf it says in place of the formula:

::::NAME???

Here is the code:
import win32com.client
Excel = win32com.client.Dispatch("Excel.Application")
Excel.Visible = 0
wb1 = Excel.Workbooks.Open(u'D:\\Python\\Bot\\Форма.xlsx')
sheet1 = wb1.ActiveSheet          #выбрал активный лист
val1 = sheet1.Cells(1,2).value    #забрал данные
wb1.Save()            #сохранил книгу
wb1.Close()      #закрыл книгу
wb2 = Excel.Workbooks.Open(u'D:\\Python\\Bot\\Счет-фактура.xlsx')
sheet2 = wb2.ActiveSheet
sheet2.Cells(9,3).value = val1            #отдал данные
wb2.Save()         #сохранил xlsx
wb2.ExportAsFixedFormat(0,'D:\\Python\\Bot\\Счет-фактура.pdf') #'D:\\Python\\Bot\\Счет-фактура.pdf'
#сохранил pdf
wb2.Close()     #закрыл книгу
Excel.Quit()      #закрыл процесс

I repeat once again, in xlsx everything is good, but in pdf it is saved crookedly, BUT !!! If I open that ready-made .xlsx file and click save as and select pdf, then everything will be as it should be there too. Maybe you need to add parameters to ExportAsFixedFormat? Searched - did not find, came here. Help me please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Dugin, 2019-09-23
@adugin

Try to copy the contents of the cells and paste them into them, but only as values, without formulas.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question