summaryrefslogtreecommitdiff
path: root/Chapter12PracSpreadsheetToText.py
blob: 3fcc81a55114d4caf538dfe4e7de465e7fb9438e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#! usr/bin/env python3

# Chapter 12 Practice
# Spreadsheet to Text - Takes each column of data and creates a text file
#                       with that data.

import openpyxl

wb = openpyxl.load_workbook('produceSales.xlsx')
sheet = wb.get_active_sheet()

for columnNum in range(1, sheet.get_highest_column()):
    spreadText = open('Column ' + str(columnNum) +'.txt', 'a')
    for rowNum in range(2, sheet.get_highest_row()):
        rowData = sheet.cell(row=rowNum, column=columnNum).value
        spreadText.write(str(rowData) + '\n')
    spreadText.close()