37,741
社区成员
发帖
与我相关
我的任务
分享
#! /usr/bin/env python3
# P12_13_5.py - read data from 'fromtxt.xlsx' and wrtie them into several .txt files.
import openpyxl
from openpyxl.utils import get_column_letter
# read contents from 'fromtxt.xlsx'
wb = openpyxl.load_workbook('fromtxt.xlsx')
sheet = wb.active
column_num = sheet.max_column
for i in range(1, column_num+1):
file = open(str(i)+'.txt', 'w')
for j in range(1, len(sheet[get_column_letter(i)])+1):
print(sheet.cell(row=j,column=i).value)
file.write(sheet.cell(row=j,column=i).value)
file.close()#! /usr/bin/env python3
# P12_13_5.py - read data from 'fromtxt.xlsx' and wrtie them into several .txt files.
import openpyxl
from openpyxl.utils import get_column_letter
# read contents from 'fromtxt.xlsx'
wb = openpyxl.load_workbook('fromtxt.xlsx')
sheet = wb.active
column_num = sheet.max_column
for i in range(1, column_num+1):
file = open(str(i)+'.txt', 'w')
for cell in sheet[get_column_letter(i)]:
if cell.value == None:
break
else:
file.write(cell.value)
file.close()