# -*-coding:UTF-8-*-
import xlsxwriter
class HtmlOutputer(object):
def __init__(self): # 建立列表存放数据
self.datas = []
def collect_data(self,data): # 收集数据
if data is None:
return
self.datas.append(data)
def save_excel(self):
book = xlsxwriter.Workbook(r'C:\Users\Administrator\Desktop\abc.xlsx') #默认储存在桌面
tmp = book.add_worksheet() #建立sheet
row_num = 11 #行号
for data in self.datas:
for i in range(1, 11):
tag_pos1 = 'A%s' % i
tmp.write(tag_pos1,data['url'])
tag_pos2 = 'B%s' % i
tmp.write(tag_pos2,data['title'])
tag_pos3 = 'C%s' % i
tmp.write(tag_pos3,data['summary'])
book.close()
代码如上,我的类里明明已经定义了这个方法,求大佬指教,我用的是pycharm,第三方模块已经全部导入了
相关分类