python excel Flashcards

1
Q

Method to open the excel spreadsheet

A

openpyxl.load_workbook()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Name of module you need to import to work with excel spreadsheets

A

openpyxl

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What parameters does the load_workbook method need?

A

the file path

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to select first available worksheet

A

wb_obj = openpyxl.load_workbook(path)

sheet_obj = wb_obj.active

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is the integer of the first row & column?

A

1, 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

How to create a cell object

A

Using the sheet object’s cell method:

cell_obj = sheet_obj.cell(row = 1, column = 1)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Display the value inside each cell object

A

print(cell_obj.value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Get value of total rows & columns

A

row = sheet_obj.max_row

column = sheet_obj.max_column

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Print all values from first column

A

for i in range(1, row+1):
cell_obj = sheet_obj.cell(row = i, column = 1)
print(cell_obj.value)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

print all values from first row

A

Same as printing columns but you have range(1, column+1) and (row = 1, column = i)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Create a new empty xl file

A

from openpyxl import Workbook
workbook = Workbook()
workbook.save(filename=”file-name.xlsx”)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

assign value to cell object

A

c1 = sheet.cell(row = 1, column = 1)
c1.value = “Hello”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

access a cell object by its actual excel name

A

c3 = sheet[‘A2’]

A2 means column = 1 & row = 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

append data to sheet

A

data = ((1, 2, 3),(4, 5, 6))

for row in data:
sheet.append(row)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

make cell A7 set to a formula that sums the values in A1, A2, A3, A4, A5

A

sheet[‘A7’] = ‘= SUM(A1:A5)’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly