zoukankan      html  css  js  c++  java
  • python中excel表格的读写

     1 #!usr/bin/env python
     2 #-*- coding:utf-8 -*-
     3 import xlrd
     4 import xlwt
     5 from xlutils.copy import copy
     6 import os
     7 
     8 data = xlrd.open_workbook('M3000.xls') #打开一个excel表格
     9 table = data.sheets()[0] #通过该方法读取的sheet是只读的,不能进行写操作
    10 rows = table.nrows 
    11 ncols = table.ncols
    12 
    13 datanew = copy(data)  #复制一份新的excel表格
    14 sheetnew = datanew.get_sheet(0)  #用此方法读取的sheet可以进行写操作
    15 
    16 def rXcel(rows):
    17     for r in range(rows-1):
    18         str = table.cell(r+1,1).value
    19         num= len(str)
    20         sheetnew.write(r+1,7,num)
    21     os.remove('M3000.xls') #将旧的excel表格删除了
    22     datanew.save('M3000.xls') #在原来的位置,用原来的表格名,重新保存一个表格
    23     
    24 if __name__=='__main__':
    25     rXcel(rows)
  • 相关阅读:
    cmake
    docker
    rust
    linux
    FPGA
    visual studio
    win+R
    word文档的导出(用freemarker模板导出)(桃)
    iconfont的引入方法
    jquery 日期插件
  • 原文地址:https://www.cnblogs.com/caixiaohong/p/4387464.html
Copyright © 2011-2022 走看看