-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxlsXlsxCopyPaste.py
42 lines (31 loc) · 1.13 KB
/
xlsXlsxCopyPaste.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# Convert xls files to xlsx Using Python Pandas Module
# and then Copy and Paste the source Excel file to destination Excel file using Python openpyxl module
# Converting xls files to xlsx
import pandas as pd
import os
df = pd.read_excel('file1.xls')
df.to_excel('file1.xlsx')
# importing openpyxl module
import openpyxl as xl
# opening the source excel file
filename = "C:/Users/gary/file1.xlsx"
wb1 = xl.load_workbook(filename)
ws1 = wb1.worksheets[0]
# opening the destination excel file
filename1 = "C:/Users/gary/file2.xlsx"
wb2 = xl.load_workbook(filename1)
ws2 = wb2.active
# calculate total number of rows and columns in source excel file
mr = ws1.max_row
mc = ws1.max_column
print(mr)
print(mc)
# copying the cell values from source excel file to destination excel file
for i in range(1, mr + 1):
for j in range(1, mc + 1):
# reading cell value from source excel file
c = ws1.cell(row = i, column = j)
# writing the read value to destination excel file
ws2.cell(row = i, column = j).value = c.value
# saving the destination excel file
wb2.save(str(filename1))