My Excel file does not have a header, I am trying to update some cells in the spreadsheet then write it to another file. A Sample file:
A B C D E
1 Title of file in text form
2 This file contains calculations that are used...
3 in verifying values...
4
5 Vre Vim Complex Vl
6 0 0.0000
Rows 1-3 contains text which are in the A column only (B-E are empty). A6 and B6 are data I'm entering from my code. C6 and D6 are formulas and will get updated when A6 and B6 data exist. Using openpyxl, I'm able to do everything I want but I get the warning:
C:\Python27\lib\site-packages\openpyxl\worksheet\header_footer.py:49:
UserWarning: Cannot parse header or footer so it will be ignored
warn("""Cannot parse header or footer so it will be ignored""")
My code to open the 1st excel file looks like:
wb = load_workbook(filename = tempfilename)
ws = wb.active
# Update cells with data
ws['A9'] = Calc_Vre
ws['B9'] = Calc_Vim
Writing the data to the 2nd excel file:
wb.save(myfile)
I tried using pandas, but I'm not updating the correct cells and the first line of the input excel is not written to the output excel.
import pandas as pd
idf = pd.read_excel(tempfilename, headers=False)
idf.at[5,0] = Calc_Vre
# write to 2nd excel file
odf = pd.ExcelWriter(myfile, engine='xlsxwriter')
idf.to_excel(odf,index = False);
odf.save()
The output looks like:
A B C D E
1 This file contains calculations that are used...
2 in verifying values...
3
4 Vre Vim Complex Vl
5 0 0.0000 5.2934
6
I wanted the 5.2934 to be in cell A5, not E5 and the first line was not written to the output file. when I used
idf = pd.read_excel(tempfilename, headers=True)
I get:
A B C D E
1 Title of fiUnnamed:1 Unnamed:2 Unnamed:3 Unnamed:4
2 This file contains calculations that are used...
So, I either need to use openpyxl and somehow, suppress or not get the warning, or use pandas but get the correct cells and the first line back.
Any suggestions?