當前位置:首頁(yè) > 軟件 > 正文內容

怎么用python修改excel表格內容 python怎么保存excel文件

巴中印刷網(wǎng)2年前 (2022-10-19)軟件23
印刷廠(chǎng)直印●彩頁(yè)1000張只需要69元●名片5元每盒-更多報價(jià)?聯(lián)系電話(huà):138-1621-1622(微信同號)

在工作中經(jīng)常需要修改excel文件并保存(例如添加行、添加列),如果只使用xlwt和xlrd并不能達成目的,需要用到xlutils。下面以我實(shí)際寫(xiě)的代碼為例

備注:代碼格式本來(lái)好好的,不知道為什么發(fā)表后就亂了,沒(méi)有縮進(jìn)

1.python是2.7

2.調試環(huán)境是:eclipse+pydev

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

*.實(shí)際代碼如下:

#encoding:utf-*

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"))

收藏0

發(fā)表評論

訪(fǎng)客

看不清,換一張

◎歡迎參與討論,請在這里發(fā)表您的看法和觀(guān)點(diǎn)。
中文字幕在线永久91_国产一级AV不卡毛片_亚洲日本中文字幕在线四区_日韩黄片在线大全