openpyxl

Python - Create multiple folders from an excel column list

烂漫一生 提交于 2019-12-08 07:52:54
问题 I am basically trying to get Python to create a bunch of folders in a directory with each folders name based on a list in an Excel file. The list is in column D, that has a heading "Folder Name". I have been able to do this with an individual cell, but struggling to figure out how to do it for multiple. The code I have so far is below. Your help is really appreciated - I am very new to this!` import os import openpyxl def folder_creation(EXCEL_FILE_DIRECTORY, FOLDER_CREATION_LOCATION, EXCEL

How to apply conditional formatting in openpyxl?

人盡茶涼 提交于 2019-12-08 07:35:37
问题 I am using openpyxl to manipulate a Microsoft Excel Worksheet. What I want to do is to add a Conditional Formatting Rule that fills the rows with a given colour if the row number is even, leaves the row blank if not. In Excel this can be done by selecting all the worksheet, creating a new formatting rule with the text =MOD(ROW();2)=0 or =EVEN(ROW()) = ROW() . I tried to implement this behaviour with the following lines of code (considering for example the first 10 rows): redFill = PatternFill

Print Excel workbook using python

此生再无相见时 提交于 2019-12-08 07:04:35
问题 Suppose I have an excel file excel_file.xlsx and i want to send it to my printer using Python so I use: import os os.startfile('path/to/file','print') My problem is that this only prints the first sheet of the excel workbook but i want all the sheets printed. Is there any way to print the entire workbook? Also, I used Openpyxl to create the file, but it doesn't seem to have any option to select the number of sheets for printing. Any help would be greatly appreciated. 回答1: from xlrd import

Reading cell value with applied number format?

守給你的承諾、 提交于 2019-12-08 06:37:59
问题 Using openpyxl I've been able to get all the code in place to read .xlsx tables to generate .xml needed for a specific technical document tool. I'm trying to make the code general to work for just about any table someone on my team may generate and one issue that has bitten me is that some columns in the XML have formatting applied to save some typing. For example, I have a table with a column for the line ID and the text, in Excel, reads as Test-001, Test-002, Test-003, etc. To save typing,

openpyxl+load_workbook+AttributeError: 'NoneType' object has no attribute 'date1904'

自古美人都是妖i 提交于 2019-12-08 04:32:45
问题 When I use openpyxl to load the Excel file( .xlsx), this error displays (the last the link is the sample Excel file): from openpyxl import * wb = load_workbook("D:/develop/workspace/exman/test sample/510001653.xlsx") Traceback (most recent call last): File "", line 1, in File "C:\Python34\lib\site-packages\openpyxl-2.5.0-py3.4.egg\openpyxl\reader\ xcel.py", line 161, in load_workbook parser.parse() File "C:\Python34\lib\site-packages\openpyxl-2.5.0-py3.4.egg\openpyxl\packagi g\workbook.py",

openpyxl - adding new rows in excel file with merged cell existing

梦想与她 提交于 2019-12-08 03:15:11
问题 Before After So, I was trying to add 6 rows into the excelsheet. And I used openpyxl.worksheet.worksheet.Worksheet.insert_rows(ws,idx=0,amount=6) to help me accomplish the task. This line works perfect with normal excel file. But, when it comes to the excel file contained merged cells. The program will not working properly just like the image I attached. Could someone give me some ideas about how to solve the issue. I ran out all the ideas and need some inspirations. Thank you very much for

Changing formats of contents in columns in an existing Excel workbook

隐身守侯 提交于 2019-12-07 20:45:09
问题 I want to change the format of the contents in an Excel workbook. Environment: Win 7; Python 2.76 I want to change the columns A, B and C to the desired format. What I have is: from openpyxl import Workbook from openpyxl import load_workbook wb = load_workbook('c:\\oldfile.xls') ws = wb.active d = ws.cell(column = 0) # or 1, 2, 3 d.style = Style(font=Font(bold=False), borders=Borders(left=Border(border_style='none'), right=Border(border_style='none'), top=Border(border_style='none'), bottom

Checking for empty cells with OpenPyXl

三世轮回 提交于 2019-12-07 19:17:19
问题 I've poured over numerous versions of this same question, but simply cannot find a working solution for looping through a group of cells and checking for empty ones. Here's my code: wb = openpyxl.Workbook(write_only=False) sheet = wb.get_sheet_by_name('Sheet') for i in range(1, 20): if sheet.cell(row=i, column=1).value == None or 'None': print('Space' + str(i)) sheet.cell(row=i, column=1) = i else: pass wb.save('filename.xlsx') But for some reason it writes to the empty cells AND overwrites

Adding a pandas.DataFrame to Existing Excel File

﹥>﹥吖頭↗ 提交于 2019-12-07 18:06:50
问题 I have a web scraper which creates an excel file for this month's scrapes. I want to add today's scrape and every scrape for that month into that file as a new sheet every time it is run. My issue, however, has been that it only overwrites the existing sheet with a new sheet instead of adding it as a separate new sheet. I've tried to do it with xlrd, xlwt, pandas, and openpyxl. Still brand new to Python so simplicity is appreciated! Below is just the code dealing with writing the excel file.

Openpyxl deleting cells

狂风中的少年 提交于 2019-12-07 16:44:25
i want to pick the last 20 items of a list copy them a new spreadsheet, and once copied i want to delete them from the first spreadsheet. i have the first part going (copy the last 20) but im not sure how to delete that cell so it doesnt appear as none after i save it. filtered = [-20:] how do i delete those 20 cells from the spreadsheet? def cell_values(somesheet): # extract the last 20 items from the worksheet filtered = [x for x in somesheet.rows if x is not None] last20 = filtered[-20:] extracted_values = [] for row in last20: for cell in row: # print cell.value extracted_values.append