鱼C论坛

 找回密码
 立即注册
查看: 1263|回复: 3

[已解决]求助关于将数值写入excel问题

[复制链接]
发表于 2019-5-1 09:08:46 | 显示全部楼层 |阅读模式
10鱼币
例如:numbers= [20,300,20190501,1523456790]
想将该列表中的每一个值写入excel中,并这样呈现,可见截图,想利用openpyxl库实现,请问有什么方法没?感谢
最佳答案
2019-5-1 09:08:47
  1. # coding: utf-8
  2. import xlwt


  3. xlsfile=xlwt.Workbook(encoding = 'utf-8')
  4. worksheet=xlsfile.add_sheet('My Worksheet')
  5. numbers= [20,300,20190501,1523456790]
  6. col=0
  7. for x in  numbers:
  8.     worksheet.write(col,0, label = x)
  9.     col+=1
  10. xlsfile.save("ttt.xls")
复制代码

0501.JPG
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-1 09:08:47 | 显示全部楼层    本楼为最佳答案   
  1. # coding: utf-8
  2. import xlwt


  3. xlsfile=xlwt.Workbook(encoding = 'utf-8')
  4. worksheet=xlsfile.add_sheet('My Worksheet')
  5. numbers= [20,300,20190501,1523456790]
  6. col=0
  7. for x in  numbers:
  8.     worksheet.write(col,0, label = x)
  9.     col+=1
  10. xlsfile.save("ttt.xls")
复制代码

小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-3 05:24:25 | 显示全部楼层
学习一下, 正好在搞这个~
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

发表于 2019-5-3 13:44:41 | 显示全部楼层
  1. import bs4,requests
  2. import openpyxl
  3. url="https://www.bilibili.com/ranking"
  4. res=requests.get(url)
  5. res.encoding='utf-8'
  6. soup=bs4.BeautifulSoup(res.text,"html.parser")

  7. #print(soup.text)
  8. targets=soup.find_all(class_="rank-item")
  9. wb=openpyxl.Workbook()
  10. ws=wb.worksheets[0]
  11. #print(targets)
  12. lin =["排序","作品名称","播放量","up主"]
  13. ws.append(lin)
  14. for each in targets:
  15.     num=each.find(class_="num").text
  16.     print(num)
  17.     print("稿件名称:")
  18.     name=each.findAll("a")[1].text
  19.     print(name)
  20.     times=each.findAll('span')[0].text
  21.     print(times)
  22.     print("up主:")
  23.     up=each.findAll('span')[2].text
  24.     print(up)
  25.     line=[num,name,times,up]
  26.     ws.append(line)
  27.     wb.save('234.xls')
复制代码
小甲鱼最新课程 -> https://ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2025-11-3 08:02

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表