xlrd

Python中xlrd和xlwt模块使用方法

左心房为你撑大大i 提交于 2019-11-28 10:11:57
xlrd模块实现对excel文件内容读取,xlwt模块实现对excel文件的写入。 安装 pip install xlrd pip install xlwt   xlrd模块使用 excel文档名称为联系人.xls,内容如下: (1) 打开excel文件并获取所有sheet import xlrd # 打开Excel文件读取数据 data = xlrd.open_workbook('联系人.xls') sheet_name = data.sheet_names() # 获取所有sheet名称 print(sheet_name) # ['银行2', '银行3'] (2) 根据下标获取sheet名称 # 根据下标获取sheet名称 sheet2_name = data.sheet_names()[1] print(sheet2_name) # '银行3' (3) 根据sheet索引或者名称获取sheet内容,同时获取sheet名称、行数、列数 # 根据sheet索引或者名称获取sheet内容,同时获取sheet名称、列数、行数 sheet2 = data.sheet_by_index(1) print('sheet2名称:{}\nsheet2列数: {}\nsheet2行数: {}'.format(sheet2.name, sheet2.ncols, sheet2.nrows)) #

Python xlrd和xlwt模块的简单使用

不打扰是莪最后的温柔 提交于 2019-11-28 10:11:26
最近在工作中需要对EXCEL表进行操作,故而对xlrd和xlwt模块进行了一番学习,功能很强大,我就常用的一些基本功能做点总结吧。 模块的安装: xlrd和xlwt模块不是自带模块。需要进行安装,安装方法不多说,有很多种通常用下面的这种方法安装简单方便。 pip install xlrd pip install xlwt 导入模块:import xlrd,xlwt xlrd模块的使用 获取表格名称的方法: (1) 打开excel文件并获取所有sheet(表格) >>> import xlrd >>> workbook = xlrd.open_workbook(r'D:\路径\文件名.xlsx') >>> print workbook.sheet_names() [u'Sheet1', u'Sheet2', u'Sheet3'] (2) 根据下标获取sheet名称 >>> sheet2_name=workbook.sheet_names()[1] >>> print sheet2_name Sheet2 (3) 根据sheet索引或者名称获取sheet内容 #根据名字获取sheet内容 >>> sheet_name = work_book.sheet_by_name('Sheet1') #如果知道表格名可以这样写,注意这里需要区分大小写。 <xlrd.sheet.Sheet

How do I find the formatting for a subset of text in an Excel document cell

徘徊边缘 提交于 2019-11-28 09:18:23
Using Python, I need to find all substrings in a given Excel sheet cell that are either bold or italic. My problem is similar to this: Using XLRD module and Python to determine cell font style (italics or not) ..but the solution is not applicable for me as I cannot assume that the same formatting holds for all content in the cell. The value in a single cell can look like this: 1. Some bold text Some normal text. Some italic text . Is there a way to find the formatting of a range of characters in a cell using xlrd (or any other Python Excel module)? Thanks to @Vyassa for all of the right

python xlutils : formatting_info=True not yet implemented

。_饼干妹妹 提交于 2019-11-28 09:07:41
I've got simple code to copy files with xlutils, xlrd, xlwt (downloaded new libraries from python-excel.org) with not loosing formatting. I've got an error as below: from xlwt.Workbook import * from xlwt.Style import * from xlrd import open_workbook from xlutils.copy import copy import xlrd style = XFStyle() rb = open_workbook('file_master.xlsx', formatting_info=True) wb = copy(rb.get_sheet(0)) new_book = Workbook() w_sheet = wb.get_sheet(0) w_sheet.write(6,6) wb.save('new_file_master.xls') Error: raise NotImplementedError("formatting_info=True not yet implemented") NotImplementedError:

Using Python, write an Excel file with columns copied from another Excel file [closed]

我与影子孤独终老i 提交于 2019-11-28 05:22:29
I have an Excel file containing a varying number of columns, I would like to loop through certain columns (from their header row value) of that file using Python, then write (copy) those columns to another Excel file. Any examples on how I can do this please? alecxe Here are some options to choose from: xlwt (writing xls files) xlrd (reading xls/xlsx files) openpyxl (reading/writing xlsx files) xlsxwriter (writing xlsx files) If you need to copy only data (without formatting information), you can just use any combination of these tools for reading/writing. If you have an xls file, you should

python: creating excel workbook and dumping csv files as worksheets

别来无恙 提交于 2019-11-28 04:34:25
I have few csv files which I would like to dump as new worksheets in a excel workbook(xls/xlsx). How do I achieve this? Googled and found 'pyXLwriter' but it seems the project was stopped. While Im trying out 'pyXLwriter' would like to know are there any alternatives/suggestions/modules? Many Thanks. [Edit] Here is my solution: (anyone has much leaner, much pythonic solution? do comment. thx) import glob import csv import xlwt import os wb = xlwt.Workbook() for filename in glob.glob("c:/xxx/*.csv"): (f_path, f_name) = os.path.split(filename) (f_short_name, f_extension) = os.path.splitext(f

log4cplus:ERROR in python when calling for tkinter file dialog

柔情痞子 提交于 2019-11-28 04:20:08
问题 I've written a little program in python that pulls data out of an .xls spreadsheet using xlrd with tkinter file dialogue boxes for opening/saving the files. Earlier today, the program was running fine, but I recently installed Autocad Electrical 2014 on my laptop for work, and now when I run the python script, I get the following errors when the script pulls up the dialogue boxes: log4cplus:ERROR No appenders could be found for logger (AdSyncNamespace). log4cplus:ERROR Please initialize the

python中使用xlrd、xlwt操作excel

佐手、 提交于 2019-11-28 01:54:07
python 对 excel基本的操作如下: # -*- coding: utf-8 -*- import xlrd import xlwt from datetime import date,datetime def read_excel(): # 打开文件 workbook = xlrd.open_workbook(r'F:\demo.xlsx') # 获取所有sheet print workbook.sheet_names() # [u'sheet1', u'sheet2'] sheet2_name = workbook.sheet_names()[1] # 根据sheet索引或者名称获取sheet内容 sheet2 = workbook.sheet_by_index(1) # sheet索引从0开始 sheet2 = workbook.sheet_by_name('sheet2') # sheet的名称,行数,列数 print sheet2.name,sheet2.nrows,sheet2.ncols # 获取整行和整列的值(数组) rows = sheet2.row_values(3) # 获取第四行内容 cols = sheet2.col_values(2) # 获取第三列内容 print rows print cols # 获取单元格内容 print sheet2

Python中xlrd和xlwt模块使用方法

人走茶凉 提交于 2019-11-28 01:53:49
本文主要介绍可操作excel文件的xlrd、xlwt模块。其中xlrd模块实现对excel文件内容读取,xlwt模块实现对excel文件的写入。 安装xlrd和xlwt模块 xlrd和xlwt模块不是自带的,需要自行安装。模块安装建议使用pip自动安装。安装方法参考< Python自动安装第三方模块 > xlrd模块使用 测试使用excel文档名称为Student.xlsx,内容如下: (1) 打开excel文件并获取所有sheet >>> import xlrd >>> workbook = xlrd.open_workbook(r'D:\Program Files\Notepad++\Student.xlsx') >>> print workbook.sheet_names() [u'Sheet1', u'Sheet2', u'Sheet3'] (2) 根据下标获取sheet名称 >>> sheet2_name=workbook.sheet_names()[1] >>> print sheet2_name Sheet2 (3) 根据sheet索引或者名称获取sheet内容,同时获取sheet名称、行数、列数 >>> sheet2 = workbook.sheet_by_index(1) >>> print sheet2.name,sheet2.nrows,sheet2

Python中xlrd和xlwt模块使用方法

♀尐吖头ヾ 提交于 2019-11-28 01:52:30
本文主要介绍可操作excel文件的xlrd、xlwt模块。其中xlrd模块实现对excel文件内容读取,xlwt模块实现对excel文件的写入。 安装xlrd和xlwt模块 xlrd和xlwt模块不是自带的,需要自行安装。模块安装建议使用pip自动安装。安装方法参考< Python自动安装第三方模块 > xlrd模块使用 测试使用excel文档名称为Student.xlsx,内容如下: (1) 打开excel文件并获取所有sheet >>> import xlrd >>> workbook = xlrd.open_workbook(r'D:\Program Files\Notepad++\Student.xlsx') >>> print workbook.sheet_names() [u'Sheet1', u'Sheet2', u'Sheet3'] (2) 根据下标获取sheet名称 >>> sheet2_name=workbook.sheet_names()[1] >>> print sheet2_name Sheet2 (3) 根据sheet索引或者名称获取sheet内容,同时获取sheet名称、行数、列数 >>> sheet2 = workbook.sheet_by_index(1) >>> print sheet2.name,sheet2.nrows,sheet2