-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathformatxl.py
More file actions
37 lines (28 loc) · 897 Bytes
/
formatxl.py
File metadata and controls
37 lines (28 loc) · 897 Bytes
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
import openpyxl
# Give the location of the file
path = "SampleExcel02.xlsx"
# To open the workbook
# workbook object is created
wb_obj = openpyxl.load_workbook(path)
# Get workbook active sheet object
# from the active attribute
sheet_obj = wb_obj.active
# Getting the value of maximum rows
# and column
iMaxRow = sheet_obj.max_row
iMaxColumn = sheet_obj.max_column
print("Total Rows:", row)
print("Total Columns:", column)
# printing the value of first column
# Loop will print all values
# of first column
bFirstRecord = True
for iRow in range(1, iMaxRow + 1):
sColumnA = sheet_obj.cell(iRow = i, column = 1)
sColumnB = sheet_obj.cell(iRow = i, column = 2)
if bFirstRecord:
print(f"{sColumnA.value:15s} {sColumnB.value:10s} ")
print(f"{'-' * 15} {'-' * 10} ")
else:
print(f"{sColumnA.value:15s} {sColumnB.value:10.2f} ")
bFirstRecord = False