亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python中使用第三方庫xlutils來追加寫入Excel文件示例

 更新時(shí)間:2015年04月05日 10:04:49   投稿:junjie  
這篇文章主要介紹了Python中使用第三方庫xlutils來追加寫入Excel文件示例,本文直接給出追加寫入示例和追加效果,需要的朋友可以參考下

目前還沒有更好的方法來追寫Excel,lorinnn在網(wǎng)上搜索到以及之后用到的方法就是使用第三方庫xlutils來實(shí)現(xiàn)了這個(gè)功能,主體思想就是先復(fù)制一份Sheet然后再次基礎(chǔ)上追加并保存到一份新的Excel文檔中去。

使用xlutils

代碼實(shí)現(xiàn)如下:

# -*- coding: utf-8 -*- 
''' 
Created on 2012-12-17 
 
@author: walfred 
@module: XLRDPkg.write_append 
@description: 
'''  
import os 
from xlutils.copy import copy 
import xlrd as ExcelRead 
 
def write_append(file_name): 
  values = ["Ann", "woman", 22, "UK"] 
 
  r_xls = ExcelRead.open_workbook(file_name) 
  r_sheet = r_xls.sheet_by_index(0) 
  rows = r_sheet.nrows 
  w_xls = copy(r_xls) 
  sheet_write = w_xls.get_sheet(0) 
 
  for i in range(0, len(values)): 
    sheet_write.write(rows, i, values[i]) 
 
  w_xls.save(file_name + '.out' + os.path.splitext(file_name)[-1]); 
 
if __name__ == "__main__": 
  write_append("./test_append.xls")

追寫前

name sex  age country
jim  man  19 USA
hmm  woman 24 CHN
lilei man  24 CHN

追寫后

name  sex  age country
jim  man  19 USA
hmm  woman 24 CHN
lilei man  24 CHN
Ann  woman 22 UK

相關(guān)文章

最新評論