openpyxl

Attribute Error: 'Workbook' object has no attribute 'active'

有些话、适合烂在心里 提交于 2019-12-13 21:18:37
问题 I am new to both python programming and the raspberry pi environment and I need to do some project with it. As I was trying to run the sample code for the openpyxl library I found myself stuck in the error provided in the title, Attribute Error: 'Workbook' object has no attribute 'active' I tried to install some more packages to check if there are just missing libraries but none of them work the code I am trying is below: from openpyxl import Workbook wb = Workbook() ws = wb.active ws['A1'] =

Can't get OpenPyXl to delete rows

混江龙づ霸主 提交于 2019-12-13 21:16:08
问题 I'm using Python and OpenPyXL to merge two Excel reports. When a report has a row of all zero values, that row should be deleted. The command to delete rows seems simple enough, but it simply doesn't work. Another post suggests delete rows doesn't play nice with append . I'm not using this function, but maybe there are other finicky bits? I'm processing the Excel files opening and saving groups of actions. Here is a comment-for-code version of the block where I'm deleting these rows. # Get WB

Using Python's Openpyxl for an index match

馋奶兔 提交于 2019-12-13 20:49:29
问题 I am trying to build a tool which will run an index match in a cell on a spreadsheet, and then display the result of the formula in python. My understanding is Openpyxl will not actually run the formulas but I can write to excel and then refresh the file to run it? from openpyxl import load_workbook path= "C:\\Users\\Me\\Documents\\Python\\File.xlsx" myworkbook=load_workbook(path) worksheet=myworkbook.get_sheet_by_name('Sheet1') mycell=worksheet['B2'] mycell.value="index(B4:B72,match(B1,A4

Calculating Excel sheets without opening them (openpyxl or xlwt)

╄→гoц情女王★ 提交于 2019-12-13 11:48:16
问题 I made a script that opens a xls. file, writes a few new value's in it, then save the file. Later the script opens it again, and wants to find the answers in some cells which contain formulas. If I call that cell with openpyxl, I get the formula (ie: =A1*B1). And if I activate data_only, i get nothing. Is there a way to let python calculate the xls file? (or should I try PyXll?) 回答1: There is actually a project that takes Excel formulas and evaluates them using Python: Pycel. Pycel uses Excel

Openpyxl & Python : column of keys, column of values - how to add up the values and assign totals to corresponding keys

♀尐吖头ヾ 提交于 2019-12-13 10:09:38
问题 Apologies for the false start. I have now read the FAQs and hope my question meets the standards:). I have the following in a spreadsheet : Col1 Col2 1234 12.5 1234 8.2 1234 9.8 2334 10.1 2334 7.7 4567 9.8 5678 9.9 5678 8.4 i need to total up the figures in Col2 for each reference number in Col1 using OpenPyxl & Python ie. 1234 30.5 2334 17.8 4567 9.8 5678 18.3 After a few false starts i have this : #import modules import openpyxl from openpyxl.utils import coordinate_from_string, column

write into excel file without overwriting old content with openpyxl

天涯浪子 提交于 2019-12-13 08:36:37
问题 I need to copy data from a text file to an excel file, but without overwriting the old data. my code: import os,sys from openpyxl import Workbook from openpyxl.compat import range wb = Workbook() Excelfilename = 'LogErrors.xlsx' ws1 = wb.active ws1.title = "Historique" excelData = [] try: with open('out.txt') as f: for line in f: excelData.append([word for word in line.split("\t") if word]) for lines in range(1,len(excelData)): for columns in range(1,len(excelData[lines])): ws1.cell(column

Script throws an error when it is made to run using multiprocessing

匆匆过客 提交于 2019-12-13 07:55:29
问题 I've written a script in python in combination with BeautifulSoup to extract the title of books which get populated upon providing some ISBN numbers in amazon search box. I'm providing those ISBN numbers from an excel file named amazon.xlsx . When I try using my following script, It parse the titles accordingly and write back to excel file as intended. The link where I put isbn numbers to populate the results. import requests from bs4 import BeautifulSoup from openpyxl import load_workbook wb

openpyxl output formula results, not formula into cells

左心房为你撑大大i 提交于 2019-12-13 07:48:02
问题 I'm trying to finish a script to convert an Excel file. It iterates through rows in a column, and creates a formula which cleans data in another column. Here is my code so far: import openpyxl wb = openpyxl.load_workbook('test-in.xlsx') ws = wb.worksheets[2] max_row = sheet.max_row for row_num in range(2, max_row): ws['I{}'.format(row_num)] = '=CLEAN(D{})'.format(row_num) wb.save('test-out.xlsx') This works very nicely, however the output file contains cells with the above formula in them. I

How to import entire sheet to list via openpyxl

允我心安 提交于 2019-12-13 03:46:17
问题 I have a problem with importing data from the spreadsheet. I'm trying create list containing all data. But only last row is added to list. from openpyxl import load_workbook path = "excel.xlsx" l_data = load_workbook(path) sheet = l_data.active c_row = sheet.max_row c_column = sheet.max_column out_data=[] dict={} for a in range(1, c_row + 1): for b in range(1, c_column + 1): ob = sheet.cell(row=a, column=b) dict[b] = ob.value out_data.append(dict) I need such output data: [ {1:"row1_call1",2:

Python Openpyxl Insert row at each value change

纵然是瞬间 提交于 2019-12-13 03:27:04
问题 I am attempting to use Python to insert an empty row at each change, for instance: Original Workbook: A A A B B C Outcome: A A A B B C Code I am working on: num=2 while num < 13: if ws['A'+str(num)].value != ws['A'+str(num+1)].value: ws.insert_rows(num+1) elif ws['A'+str(num)].value == ws['A'+str(num+1)].value or ws['A'+str(num)].value == '': pass num+=1 Output I currently get is A A A B B C Thanks in advance! EDIT: SOLVED! In a weird way. num=2 while num < 13: if ws['A'+str(num)].value == ws