#coding:utf-8
'''
Created on 2019年8月
从一个excel文件中读取相关的内容保存到新的excel文件中,去掉已重复的名称
testWrite.xlsx和testRead.xlsx都在当前目录下
@author: test
'''
import xlsxwriter
import os
import xlrd
def readWriteExcel():
workbook = xlsxwriter.Workbook(os.path.abspath(".") + '/testWrite.xlsx') # 在当前目录下创建一个Excel文件
worksheet = workbook.add_worksheet() # 创建一个sheet
title = [U'id', U'名称', U'备注'] # 表格title
worksheet.write_row('A1', title) # title 写入Excel
i=1
names = []
ExcelFile=xlrd.open_workbook(r'testRead.xlsx') #文件名以及路径,如果路径或者文件名有中文给前面加一个r表示原生字符
#获取sheet内容【1.根据sheet索引2.根据sheet名称】
sheet=ExcelFile.sheet_by_index(0)
#sheet=ExcelFile.sheet_by_name('Sheet1')
#打印sheet的名称(sheet.name),行数(sheet.nrows),列数(sheet.ncols )
for j in range(0,sheet.nrows):#行
id = she
python从一个excel文件中读取相关的内容到新的excel文件中
最新推荐文章于 2022-06-14 16:33:04 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)