openpyxl

Openpyxl - object has no attribute 'load_workbook'

有些话、适合烂在心里 提交于 2020-05-29 01:09:37
问题 I'm trying to load an existing workbook using openpyxl. But when I'm trying to run this code - I'm getting following error: AttributeError: 'module' object has no attribute 'load_workbook' import openpyxl works fine, what I'm doing wrong? 回答1: The examples are for a later version of openpyxl . In 1.1.4 the main __init__.py did not provide a shortcut to load_workbook in the form of from openpyxl.reader.excel import load_workbook so you will have to do that instead of: from openpyxl import load

Populate an excel file from csv input file line by line

落爺英雄遲暮 提交于 2020-05-28 05:45:08
问题 I have a csv file like this with multiple lines: column1,column2,column3,column4,colunm5,column6 valueA,valueB,valueC,valueD,valueE,valueD valueA,valueB,valueC,valueD,valueE,valueD ... In the other hand I have an excel file where I want to fill it with some of the csv line by line values on certain specific cells, for example: column1 and valueA into the excel file in the cell D7. column2 and valueB into the excel file in the cell E8. column3 and valueC into the excel file in the cell F8.

Openpyxl: set background color to a row and column Attribute Error

纵饮孤独 提交于 2020-05-27 06:34:45
问题 having looked at a few examples over here I tried to set background color to an entire row and column. I have done `import openpyxl from openpyxl.styles import PatternFill wb = openpyxl.load_workbook(self.inputfile) ws = wb.active ws['A1'].fill = PatternFill(bgColor="FFC7CE", fill_type = "solid")` I get an Attribute error if I do ws[1].fill =PatternFill(bgColor="FFC7CE", fill_type = "solid") The above code fills a single cell(A1). But how do I go forward if I want to fill an entire row(1),

Update an Excel sheet in real time using Python

梦想的初衷 提交于 2020-05-25 07:14:43
问题 Is there a way to update a spreadsheet in real time while it is open in Excel? I have a workbook called Example.xlsx which is open in Excel and I have the following python code which tries to update cell B1 with the string 'ID': import openpyxl wb = openpyxl.load_workbook('Example.xlsx') sheet = wb['Sheet'] sheet['B1'] = 'ID' wb.save('Example.xlsx') On running the script I get this error: PermissionError: [Errno 13] Permission denied: 'Example.xlsx' I know its because the file is currently

python: why does replace not work?

倾然丶 夕夏残阳落幕 提交于 2020-05-24 04:47:10
问题 I wrote a quick script to remove the 'http://' substring from a list of website addresses saved on an excel column. The function replace though, doesn't work and I don't understand why. from openpyxl import load_workbook def rem(string): print string.startswith("http://") #it yields "True" string.replace("http://","") print string, type(string) #checking if it works (it doesn't though, the output is the same as the input) wb = load_workbook("prova.xlsx") ws = wb["Sheet"] for n in xrange(2,698

Read Excel checkbox from Python

别来无恙 提交于 2020-05-17 06:43:50
问题 I want to read data from an Excel sheet from a Python script and fill an XML file using the data read. Unfortunately the Excel sheet/form contains checkboxes and drop down lists. I was unable to get the value of the drop down list from its cell with the code below. import openpyxl excel_document = openpyxl.load_workbook('name.xlsx', keep_vba=True) name_sheet1 = excel_document.get_sheet_names()[0] sheet1 = excel_document.get_sheet_by_name(name_sheet1) cell = sheet1['D38'] print(cell.value)

Using openpyxl module to write to spreadsheet creates a damaged spreadsheet, how to fix with zipfile module?

*爱你&永不变心* 提交于 2020-05-14 18:23:05
问题 I have a program which writes to a spreadsheet using openpyxl . Upon execution of the program, the cells are filled as expected but the spreadsheet becomes damaged. Excel repairs the spreadsheet and I can then view it again. import openpyxl from openpyxl import load_workbook amounts, row = [1, 2, 3, 4, 5], 2 book = load_workbook("output.xlsx") sheet = book.active for i, value in enumerate(amounts): sheet.cell(column=i+1, row=row, value=value) print ("Sheet updating complete.") book.save(

Pandas read_excel returns PendingDeprecationWarning

橙三吉。 提交于 2020-05-14 12:09:28
问题 I have been importing Excel files as Pandas data frames using the read_excel function with no apparent issues so far. However, I just realized that after some recent updates I'm getting the below warning: /usr/local/lib/python3.7/site-packages/xlrd/xlsx.py:266: PendingDeprecationWarning: This method will be removed in future versions. Use 'tree.iter()' or 'list(tree.iter())' instead. for elem in self.tree.iter() if Element_has_iter else self.tree.getiterator(): /usr/local/lib/python3.7/site

Pandas read_excel returns PendingDeprecationWarning

醉酒当歌 提交于 2020-05-14 12:08:25
问题 I have been importing Excel files as Pandas data frames using the read_excel function with no apparent issues so far. However, I just realized that after some recent updates I'm getting the below warning: /usr/local/lib/python3.7/site-packages/xlrd/xlsx.py:266: PendingDeprecationWarning: This method will be removed in future versions. Use 'tree.iter()' or 'list(tree.iter())' instead. for elem in self.tree.iter() if Element_has_iter else self.tree.getiterator(): /usr/local/lib/python3.7/site

Memory error using openpyxl and large data excels

邮差的信 提交于 2020-05-09 02:02:07
问题 I have written a script which has to read lot of excel files from a folder (around 10,000). This script loads the excel file (some of them has more than 2,000 rows) and reads one column to count the number of rows (checking stuff). If the number of rows is not equal to a given number, it writes the warning in a log. The problem comes when the script reads more than 1,000 excel files. It's then when it throws memory error, and I don't know where could be the problem. Previously, the script