openpyxl

MemoryError while converting txt to xlsx

血红的双手。 提交于 2019-12-11 03:41:59
问题 Related questions: 1. Error in converting txt to xlsx using python Converting txt to xlsx while setting the cell property for number cells as number My code is 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,

python 3: py2app “Modules not found (unconditional imports)”

China☆狼群 提交于 2019-12-11 03:33:00
问题 I am building a standalone python3 app for a friend that has no knowledge about code whatsoever. For this app I use multiple modules including tkinter and openpyxl . I use py2app to make my app. Even though the GUI part of the program works, the methods using the openpyxl module do not. As my terminal indicates: Modules not found (unconditional imports): * StringIO.StringIO (pkg_resources._vendor.six) * _gdbm (dbm.gnu) * cjkwrap (texttable) * com (com.sun.jna) * com.jna (com.sun) * com.sun

How to copy a range from one sheet to another as values using openpyxl in python

心已入冬 提交于 2019-12-11 03:27:29
问题 I have to copy a range from A1:Z100 from sheet onw of workbook 1 to sheet 1 of workbook 2? My code : wb = openpyxl.load_workbook('file1.xlsx') wb1 = openpyxl.load_workbook('file2.xlsx') sheet = wb["R"] sheet1 = wb1["Rt"] sheet1.cell(row=1,column=1).value = sheet.cell(row=1,column=1).value This is not working properly. How to copy this range to that sheet? 回答1: You can try with something like: for i in range(1, 100): for j in range(1, 26): sheet1.cell(row=i,column=j).value = sheet.cell(row=i

AttributeError with openpyxl

北慕城南 提交于 2019-12-11 01:49:24
问题 I'm trying to read an Excel workbook into a three-dimensional array ([worksheet][column][cell]) but I'm getting an error with openpyxl (v2.5.0a2) that looks like it contradicts the online documentation. The documentation for the worksheet module clearly states that there's a 'columns' attribute (and I've seen examples using it), but I get an "AttributeError: 'ReadOnlyWorksheet' object has no attribute 'columns'" error. Code below, any clues? # Load spreadsheet in read only mode wb = load

Set Password for excel file using Python [duplicate]

删除回忆录丶 提交于 2019-12-11 01:32:19
问题 This question already has answers here : Password Protecting Excel file using Python (3 answers) Closed last year . I am trying to set password for excel file generated using openpyxl. I went through openpyxl . Openpyxl has a workbook protection functionality, but it does not support whole workbook lock using password as it does in MS Excel. I also looked into xlsxwriter , xlrd , xlwt . Is there any way in python which i can set password for an excel file ? Thanks in advance. 回答1: Can you try

Can I disable openpyxl from automatically parsing strings to datetime?

a 夏天 提交于 2019-12-10 23:29:43
问题 I'm having simple excel files with various timstamp formats written as strings. There is a build in feature in openpyxl to automatically convert what seems like a date to a datetime object. My question is simple, how can I take the raw string as it was inserted to the excel file by the user, without intervention of openpyxl . I want to do my own format testings using a function that tries various calls to datetime.strptime myself. Loading the excel is done by me like this: import openpyxl ex

优秀Python处理excel文件库openpyxl

早过忘川 提交于 2019-12-10 19:42:57
目录 简单介绍 新建一个excel文件 激活表 简单介绍 openpyxl官方文档 官方教程 我总觉得,在学习一个编程语言概念的时候,与其看中国的程序员翻译过来的学习资料和博客,真的不如自己去看纯英文版的官方文档。所以官方文档是一定要看的,别人写的东西是经过作者自己的过滤的,可能会缺失很多知识点。而自己去发现去删减,选择性地学习,才能收获到自己最需要的东西。 新建一个excel文件 from openpyxl import Workbook wb = Workbook ( ) 激活表 ws = wb . active ( ) 来源: CSDN 作者: 戎码关山 链接: https://blog.csdn.net/dghcs18/article/details/103445621

Can't load workbook with openpyxl: during handling of the above exception, another exception occurred

醉酒当歌 提交于 2019-12-10 19:39:09
问题 I want to edit a xlsx file with openpyxl 2.5.0. This is my code and it works with an empty file: from openpyxl import load_workbook wb = load_workbook(filename="Untitled.xlsx") ws = wb.active ws["B5"] = "test" wb.save("Export.xlsx") However if I try to load this file, I get the following obscure error. Traceback (most recent call last): File "C:\Matteo\PyCharm\CMakeR\venv\lib\site-packages\openpyxl\descriptors\base.py", line 57, in _convert value = expected_type(value) ValueError: invalid

openpyxl: writing large excel files with python

谁说胖子不能爱 提交于 2019-12-10 18:59:19
问题 I have a big problem here with python, openpyxl and Excel files. My objective is to write some calculated data to a preconfigured template in Excel. I load this template and write the data on it. There are two problems: I'm talking about writing Excel books with more than 2 millions of cells, divided into several sheets. I do this successfully, but the waiting time is unthinkable. I don't know other way to solve this problem. Maybe openpyxl is not the solution. I have tried to write in xlsb,

Python: Creating row breaks in a list for openpyxl to recognise in .xlsx

本小妞迷上赌 提交于 2019-12-10 18:39:13
问题 I am scraping information from a URL I can successfully get the information into a .xlsx It isn't in the format I want it to be in. element_rows = [] for table_row in Elements.findAll('tr'): columns = table_row.findAll('td') output_row = [] for column in columns: sub_rows = column.findAll('p') output_row.append('\r\n'.join(row.text for row in sub_rows)) element_rows.append(output_row) I feel it's something simple, but can't place it. As it iterates through, for every 'p' I want it to create a