苹果版excel怎么保存:怎么用python修改excel表格内容 python怎么保存excel文件

太平洋在线下载 132 1

在工作中经常需要修改excel文件并保存(例如添加行、添加列),如果只使用xlwt和xlrd并不能达成目的,需要用到xlutils苹果版excel怎么保存。下面以我实际写的代码为例

备注:代码格式本来好好的苹果版excel怎么保存,不知道为什么发表后就乱了,没有缩进

1.python是2.7

2.调试环境是:eclipse+pydev

3.用到的python插件:xlrd、xlutils

4.实际代码如下:

#encoding:utf-8

import xlrd

import shutil

from xlutils.copy import copy

from xlutils.margins import null_cell_types

def ana_file(aExcelFile):

#global gOutput_log_str

#download all zip files

r_xls=xlrd.open_workbook(aExcelFile)

table = r_xls.sheet_by_index(0)

nrows=table.nrows

ncols = table.ncols

#write the column key

w_xls = copy(r_xls)

sheet_write = w_xls.get_sheet(0)

sheet_write.write(0, gBug_id_col, "Bug ID")

sheet_write.write(0, gBug_newflag_col, "New Bug")

sheet_write.write(0, gBug_comment_col, "Comments")

sheet_write.write(0, gBug_findclose_col, "Bug Close")

w_xls.save(aExcelFile)

shutil.move(aExcelFile, os.path.join(os.path.split(aExcelFile)[0],os.path.splitext(os.path.split(aExcelFile)[1])[0]+".xls"))

标签: 怎么 python excel 表格 保存

抱歉,评论功能暂时关闭!