openpyxl

ImportError: cannot import name get_column_letter

落爺英雄遲暮 提交于 2019-12-03 05:44:08
问题 I am able to use openpyxl as an import in my code. But when I try to do the following: from openpyxl.cell import get_column_letter I get the following error: ImportError: cannot import name get_column_letter I am using python 2.7. I have installed it using easy_install . Tried searching for this issue but couldn't find anything related to it. 回答1: The function get_column_letter has been relocated in Openpyxl version 2.4 from openpyxl.cell to openpyxl.utils . The current import is: from

getting sheet names from openpyxl

淺唱寂寞╮ 提交于 2019-12-03 04:09:57
问题 I have a moderately large xlsx file (around 14 MB) and OpenOffice hangs trying to open it. I was trying to use openpyxl to read the content, following this tutorial. The code snippet is as follows: from openpyxl import load_workbook wb = load_workbook(filename = 'large_file.xlsx', use_iterators = True) ws = wb.get_sheet_by_name(name = 'big_data') The problem is, I don't know the sheet name, and Sheet1/Sheet2.. etc. didn't work (returned NoneType object). I could not find a documentation

Error in converting txt to xlsx using python

匿名 (未验证) 提交于 2019-12-03 02:33:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: My code is following. import csv import openpyxl import sys def convert(input_path, output_path): """ Read a csv file (with no quoting), and save its contents in an excel file. """ wb = openpyxl.Workbook() ws = wb.worksheets[0] with open(input_path) as f: reader = csv.reader(f, delimiter='\t', quoting=csv.QUOTE_NONE) for row_index, row in enumerate(reader): for col_index, value in enumerate(row): ws.cell(row=row_index, column=col_index).value = value wb.save(output_path) def main(): try: input_path, output_path = sys.argv[1:] except

openpyxl - adjust column width size

匿名 (未验证) 提交于 2019-12-03 02:16:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have following script which is converting a CSV file to an XLSX file, but my column size is very narrow. Each time I have to drag them with mouse to read data. Does anybody know how to set column width in openpyxl ? Here is the code I am using. #!/usr/bin/python2.6 import csv from openpyxl import Workbook from openpyxl.cell import get_column_letter f = open('users_info_cvs.txt', "rU") csv.register_dialect('colons', delimiter=':') reader = csv.reader(f, dialect='colons') wb = Workbook() dest_filename = r"account_info.xlsx" ws = wb

Insert row into Excel spreadsheet using openpyxl in Python

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm looking for the best approach for inserting a row into a spreadsheet using openpyxl. Effectively, I have a spreadsheet (Excel 2007) which has a header row, followed by (at most) a few thousand rows of data. I'm looking to insert the row as the first row of actual data, so after the header. My understanding is that the append function is suitable for adding content to the end of the file. Reading the documentation for both openpyxl and xlrd (and xlwt), I can't find any clear cut ways of doing this, beyond looping through the content

Django: openpyxl saving workbook as attachment

匿名 (未验证) 提交于 2019-12-03 02:07:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hi I have a quick question. I didn't find answer in internet maybe someone of you can help me. So i want to save workbook as attachment but I don't know how lets see an example : from openpyxl import Workbook from openpyxl.cell import get_column_letter wb = Workbook(encoding='utf-8') dest_filename = 'file.xlsx' ws = wb.worksheets[0] ws.title = "range names" for col_idx in xrange(1, 40): col = get_column_letter(col_idx) for row in xrange(1, 600): ws.cell('%s%s'%(col, row)).value = '%s%s' % (col, row) ws = wb.create_sheet() ws.title = 'Pi' ws

Django: openpyxl saving workbook as attachment

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hi I have a quick question. I didn't find answer in internet maybe someone of you can help me. So i want to save workbook as attachment but I don't know how lets see an example : from openpyxl import Workbook from openpyxl.cell import get_column_letter wb = Workbook(encoding='utf-8') dest_filename = 'file.xlsx' ws = wb.worksheets[0] ws.title = "range names" for col_idx in xrange(1, 40): col = get_column_letter(col_idx) for row in xrange(1, 600): ws.cell('%s%s'%(col, row)).value = '%s%s' % (col, row) ws = wb.create_sheet() ws.title = 'Pi' ws

Insert column using openpyxl

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm working on a script that modifies an existing excel document and I need to have the ability to insert a column between two other columns like the VBA macro command .EntireColumn.Insert . Is there any method with openpyxl to insert a column like this? If not, any advice on writing one? 回答1: Haven't found anything like .EntireColumn.Insert in openpyxl. First thought coming into my mind is to insert column manually by modifying _cells on a worksheet. I don't think it's the best way to insert column but it works: from openpyxl .

csv与openpyxl函数

帅比萌擦擦* 提交于 2019-12-03 01:59:32
csv与openpyxl函数 csv函数 常用的存储数据的方式有两种——存储成csv格式文件、存储成Excel文件(不是复制黏贴的那种) 前面,我有讲到json是特殊的字符串。其实,csv也是一种字符串文件的格式,它组织数据的语法就是在字符串之间加分隔符——行与行之间是加换行符, 同列之间是加逗号分隔。 为什么要加分隔符?因为不加的话,数据都堆在一起,会显得杂乱无章,也不方便我们之后提取和查找。这也是一种让数据变得有规律的组织方式。 它可以用任意的文本编辑器打开(如记事本),也可以用Excel打开,还可以通过Excel把文件另存为csv格式(因为Excel支持csv格式文件)。 另外,用csv格式存储数据,读写比较方便,易于实现,文件也会比Excel文件小。但csv文件缺少Excel文件本身的很多功能,比如不能嵌入图像和图表,不能生成公式。 import csv #引用csv模块。 csv_file = open('demo.csv','w',newline='',encoding='utf-8') #创建csv文件,我们要先调用open()函数,传入参数:文件名“demo.csv”、写入模式“w”、newline=''、encoding='utf-8'。 加newline=' '参数的原因是,可以避免csv文件出现两倍的行距(就是能避免表格的行与行之间出现空白行)

Openpyxl 1.8.5: Reading the result of a formula typed in a cell using openpyxl

匿名 (未验证) 提交于 2019-12-03 01:57:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I am printing some formula in one of the Excel sheets: wsOld . cell ( row = 1 , column = 1 ). value = "=B3=B4" But I cannot use its result in implementing some other logic, as: if (( wsOld . cell ( row = 1 , column = 1 ). value )= 'true' ): # copy the 1st row to another sheet Even when I am trying to print the result in the command line, I end up printing the formula: >>> print ( wsOld . cell ( row = 1 , column = 1 )) >>> = B3 = B4 How can I get the result of the formula in a cell and not the formula itself? 回答1: openpyxl support