相关库

读:xlrd

写:xlwt

案例

要求:

将图1中的数据导以图2的形式写入另一个文件中

第一列索引关系:{1:K1-B1,2:K1-B2}

。。。(18列)

思路:

按行读取数据,根据索引关系按列写入数据

代码:

 1 import xlrd
2 import xlwt
3 #柱号映射关系
4 index = ['K1-B1','K1-B2']
5 load_cnt = 6
6 #读excel文件
7 wb = xlrd.open_workbook(r'C:\Users\Administrator\Desktop\demo\111.xls')
8 sheet1 = wb.sheet_by_index(0)
9 index_col = sheet1.col_values(0)[1:]
10 joint_cnt = len(index_col)
11 #写excel文件
12 f = xlwt.Workbook()
13 sheet2 = f.add_sheet(u'sheet1',cell_overwrite_ok=True)
14 for i in range(joint_cnt):
15 for j in range(joint_cnt):
16 if index_col[j] == index[i]: break
17 target_row = sheet1.row_values(j+1)[1:]
18 num_cnt = len(target_row)
19 for k in range(load_cnt):
20 sheet2.write(3*i,k,target_row[3*k])
21 sheet2.write(3*i+1,k,target_row[3*k+1])
22 sheet2.write(3*i+2,k,target_row[3*k+2])
23 f.save(r'C:\Users\Administrator\Desktop\demo\222.xls')

参考

xlrd帮助

https://blog.csdn.net/Sukie_csdn/article/details/78672626

openpyxl帮助

https://segmentfault.com/a/1190000016256490

常用操作实现

https://blog.csdn.net/paul0127/article/details/82529153

最新文章

  1. Android四大组件-Activity
  2. update
  3. tensorflow1
  4. PHP __DIR__, __FILE__, __FUNCTION__, __CLASS__, __METHOD__, __LINE__, __NAMESPACE__
  5. 16.(转) Android之Support v4、v7、v13的区别和应用场景
  6. java 打包过程及如何使用第三方jar包
  7. 设置页面不缓存 no-cache
  8. [Android]使用platform密钥来给apk文件签名的命令
  9. #1042 - Can't get hostname for your address
  10. 14.18.1 The InnoDB Recovery Process InnoDB 恢复进程:
  11. 学习Easyui
  12. 使用Java实现二叉树的添加,删除,获取以及遍历
  13. windows server 2016 x64用MecaCli工具检查raid5磁盘状态
  14. 天气预测(CNN)
  15. How to change Eclipse loading image
  16. android checkBox选中与取消
  17. SoapUI SoapUI测试WebService协议接口简介
  18. 【转】苹果App Store审核指南中文翻译(更新)
  19. c++并发编程之互斥锁(mutex)的使用方法
  20. HA 高可用mysql集群

热门文章

  1. Qt信号槽源码剖析(一)
  2. Python的flask接收前台的ajax的post数据和get数据
  3. 【2.0 递归 Recursion 01】
  4. PAT B1038 统计同成绩学生
  5. Fastbin attack 总结
  6. redhat 7.6 安装Python3后配置 yum pip3 升级openssl
  7. Spring Cloud Alibaba(5)---Nacos(配置中心)
  8. windows黑窗口命令笔记
  9. 简谈Mysql悲观锁和乐观锁
  10. 提示No input file specified的解决方法