python3 写入excel_python 3 往Excel 中的写入内容但不覆盖原内容

EXCEL 写入数据保持原样式

import xlwt

import xlrd

import xlutils

import xlutils.copy

class ExcelHandle():

def __init__(self, filename):

self.filename = filename

self.test_data = xlrd.open_workbook(self.filename,formatting_info=True) # 保留原格式

self.sheet = self.test_data.sheet_by_index(0)

def writeExcel(self,row,col,value):

self.row = row

self.col = col

self.args = value

style = xlwt.XFStyle()

oldsheet = xlrd.open_workbook(self.filename,formatting_info=True)

newsheet = xlutils.copy.copy(oldsheet)

newwrite = newsheet.get_sheet(0)

newwrite.write(self.row, self.col, str(value), style)

newsheet.save(self.filename)

def readExcel(self, row,col):

comlist = str(self.sheet.cell_value(row, col))

return comlist

if __name__ == '__main__':

t = ExcelHandle('bookname.xlsx')

for i in range(2,15):

for j in range(1, 10):

X = t.readExcel(i,1)

print(X)

print("______________")

t.writeExcel(i,j,"sssss")

#coding=utf-8

import xlwt

import xlrd

import xlutils.copy

#################################################################################

# Create a new sheet1

#workbook = xlwt.Workbook()

#sheet1 = workbook.add_sheet('sheet1',cell_overwrite_ok=True)

# Write something into the sheet1

#sheet1.write(0,0,'connected IP')

#sheet1.write(0,1,'Addr IPV4 IP(s)')

# save excel file

#workbook.save('C:\\Users\\32065\\Desktop\\Net\\simulation\\excel\\test.xls')

#print 'create excel file successfully!'

################################################################################

rb = xlrd.open_workbook('C:\\Users\\32065\\Desktop\\Net\\simulation\\excel\\test.xls')

wb = xlutils.copy.copy(rb)

#获取sheet对象,通过sheet_by_index()获取的sheet对象没有write()方法

ws = wb.get_sheet(0)

#写入数据

ws.write(0, 1, 'changed!')

ws.write(1, 0, '10-changed!')

ws.write(2, 0, '20-changed!')

#添加sheet页

# wb.add_sheet('sheetnnn2',cell_overwrite_ok=True)

#利用保存时同名覆盖达到修改excel文件的目的,注意未被修改的内容保持不变

wb.save('C:\\Users\\32065\\Desktop\\Net\\simulation\\excel\\test.xls')

##############################################################################

# read the excel file

data = xlrd.open_workbook('C:\\Users\\32065\\Desktop\\Net\\simulation\\excel\\test.xls')

table = data.sheets()[0] # open the first sheet

nrows = table.nrows # not-null rows

print nrows

for i in range(nrows): # print by rows

if i == 0: # 跳过第一行

continue

print table.row_values(i)[0:2]

Python批量修改Excel中的文件内容

import osimport xlrdfrom xlutils.copy import copydef base_dir(filename=None):    return os.path.join ...

【Python】如何处理Excel中的数据

我们平时在做自动化测试的时候,可能会涉及到从表格中去读取或者存储数据,我们除了可以使用openpyxl来操作excel,当然也可以利用pandas来完成,这篇随笔只是我在学习过程中的简单记录,其他的功 ...

Python基础-修改excel中内容

from xlutils.copy import copy import xlrd import os #1.打一要修改的excel #2.再打开另一个excel #3.把第一个excel里面修改东西 ...

python - requests从excel中获取测试用例数据

HttpRequests.py #-*- coding:utf-8 -*- import requests class HttpRequests(): def http_requests(self,u ...

python实现操作excel,数据写入excel的一行或者一列

# _*_ coding:utf-8 _*_ import random import xlwt,string class ImportData(object): def create_num(sel ...

使用excel中的数据快速生成sql语句

在小公司的话,总是会有要开发去导入历史数据(数据从旧系统迁移到新系统上)的时候.这个时候,现场实施或客户会给你一份EXCEL文档,里面包含了一些别的系统上的历史数据,然后就让你导入到现在的系统上面去. ...

Python中,添加写入数据到已经存在的Excel的xls文件,即打开excel文件,写入新数据

背景 Python中,想要打开已经存在的excel的xls文件,然后在最后新的一行的数据. 折腾过程 1.找到了参考资料: writing to existing workbook using xlw ...

用python在excel中读取与生成随机数写入excel中

今天是我第一次发博客,就关于python在excel中的应用作为我的第一篇吧. 具体要求是:在一份已知的excel表格中读取学生的学号与姓名,再将这些数据放到新的excel表中的第一列与第二列,最后再 ...

Python+request 将获取的url和接口响应时间(timeout)写入到Excel中《八》

使用场景: 在工作中,常见某个功能的查询,当查询关联表特别多时,开发写的SQL语句等等问题导致响应时间较慢,那么作为测试需要将每个接口的响应时间进行测试,对同个接口多次执行,并将测试结果写入到exce ...

随机推荐

C# 中Switch case 返回不止用break

Switch(temp) { case "A": //跳出循环 break; case "B": //返回值 return var; case "C& ...

【POJ3254】Corn Fields 状压DP第一次

!!!!!!! 第一次学状压DP,其实就是运用位运算来实现一些比较,挺神奇的.. 为什么要发“!!!”因为!x&y和!(x&y)..感受一下.. #include

c#通用递归生成无限层级树

NewsType结构: Id ParentId Name children(List) public void LoopToAppendChildren(List&lt ...

centos6.5_x86_64安装Adobe Flash Player

对x86_64的CentOS6.5系统,安装FireFox的Adobe Flash Player插件 安装插件,终端下输入命令:#wget http://linuxdownload.adobe.com ...

c#中单元测试

从走进.net后发现每天有写不完的代码,有做不完的测试...人感觉都已经机械,我们需要认清自己调整好心态,问下自己是否真的喜欢编程.我的答案当然也就是我爱编码,编码给我带来了许多欢乐,每天都给我体验小 ...

201521123054 《Java程序设计》 第十周学习总结

1. 本周学习总结 2. 书面作业 题目4-2 1.1 截图你的提交结果(出现学号) 1.2 4-2中finally中捕获异常需要注意什么? 无论是否抛出异常,也无论从什么地方返回,finally语句 ...

google gflag使用方法举例

前言: 1. gflag是一种命令行编码参数解析工具,开源地址: https://github.com/gflags/gflags , 在caffe框架也使用了gflag来编码解析命令行. 那么什么是 ...

vue组件通信的几种方式

最近用vue开发项目,记录一下vue组件间通信几种方式 第一种,父子组件通信 一.父组件向子组件传值 1.创建子组件,在src/components/文件夹下新建一个Child.vue 2.Child ...

Python之Numpy数组拼接,组合,连接

转自:https://www.douban.com/note/518335786/?type=like ============改变数组的维度==================已知reshape函数 ...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值