打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
python xlwt,xlutils 在excel里面如何插入一行数据
import xlwt;
import xlrd;
from xlutils.copy import copy;
  
#styleBoldRed   = xlwt.easyxf('font: color-index red, bold on');
#headerStyle = styleBoldRed;
#wb = xlwt.Workbook();
#ws = wb.add_sheet('sheetName');
#ws.write(0, 0, 'Col1',        headerStyle);
#ws.write(0, 1, 'Col2', headerStyle);
#ws.write(0, 2, 'Col3',    headerStyle);
#wb.save('fileName.xls');
#open existed xls file
oldWb = xlrd.open_workbook('fileName.xls', formatting_info=True);
oldWbS = oldWb.sheet_by_index(0)
newWb = copy(oldWb);
newWs = newWb.get_sheet(0);
inserRowNo = 1
newWs.write(inserRowNo, 0'value1');
newWs.write(inserRowNo, 1'value2');
newWs.write(inserRowNo, 2'value3');
for rowIndex in range(inserRowNo, oldWbS.nrows):
    for colIndex in range(oldWbS.ncols):
        newWs.write(rowIndex + 1, colIndex, oldWbS.cell(rowIndex, colIndex).value);
newWb.save('fileName.xls');
print 'save with same name ok';
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
【整理】Python中,添加写入数据到已经存在的Excel的xls文件,即打开excel文...
使用python操作Excel——xlrd、xlwt、xlutils库
4段简短代码教你用Python读写Excel
python处理excel总结
用强大的Python处理海量的Excel,工作从未如此简单
史上最全Python 操作 Excel库总结!
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服