openpyxl

How to concatenate three excels files xlsx using python?

喜欢而已 提交于 2019-11-27 04:08:09
Hello I would like to concatenate three excels files xlsx using python. I have tried using openpyxl, but I don't know which function could help me to append three worksheet into one. Do you have any ideas how to do that ? Thanks a lot Here's a pandas -based approach. (It's using openpyxl behind the scenes.) import pandas as pd # filenames excel_names = ["xlsx1.xlsx", "xlsx2.xlsx", "xlsx3.xlsx"] # read them in excels = [pd.ExcelFile(name) for name in excel_names] # turn them into dataframes frames = [x.parse(x.sheet_names[0], header=None,index_col=None) for x in excels] # delete the first row

openpyxl python - writing csv to excel gives 'number formatted as text'

自闭症网瘾萝莉.ら 提交于 2019-11-27 02:57:00
问题 I have written a code to import a .csv file (containing numbers) into an excel file through openpyxl. It works, however, all the cells have written the numbers to the excel file as text. I then have to manually correct the error in excel: "Numbers formatted as text (displaying little green triangles in the corner of the cell). Is there a way to prevent this from happening? It occurs with any csv file, even if I make it with just numbers. Thanks #!python2 # Add csv file to an xlsx import os,

how to write to a new cell in python using openpyxl

我的未来我决定 提交于 2019-11-27 02:50:44
问题 I wrote code which opens an excel file and iterates through each row and passes the value to another function. import openpyxl wb = load_workbook(filename='C:\Users\xxxxx') for ws in wb.worksheets: for row in ws.rows: print row x1=ucr(row[0].value) row[1].value=x1 # i am having error at this point I am getting the following error when I tried to run the file. TypeError: IndexError: tuple index out of range Can I write the returned value x1 to the row[1] column. Is it possible to write to

Python: Writing to Excel 2007+ files (.xlsx files)

大憨熊 提交于 2019-11-27 02:13:18
问题 Is there a Python module that writes Excel 2007+ files? I'm interested in writing a file longer than 65535 lines and only Excel 2007+ supports it. 回答1: There are two libraries you can take a look at. Python-xlsx and PyXLSX EDIT: As the comments mention, for writing you check out openpyxl 回答2: Take a look at Eric' Gazoni's openpyxl project. The code can be found on bitbucket. 回答3: You should take a look at xlsxcessive. It's for writing xlsx files, and is, perhaps, a bit more pythonic. 回答4: The

Copy pandas dataframe to excel using openpyxl

流过昼夜 提交于 2019-11-27 01:57:21
问题 I have some complicated formating saved in a template file into which I need to save data from a pandas dataframe. Problem is when I use pd.to_excel to save to this worksheet, pandas overwrites the formatting. Is there a way to somehow 'paste values' form the df into the worksheet? I am using pandas 0.17 import openpyxl import pandas as pd wb= openpyxl.load_workbook('H:/template.xlsx') sheet = wb.get_sheet_by_name('spam') sheet.title = 'df data' wb.save('H:/df_out.xlsx') xlr = pd.ExcelWriter(

OpenPyXL + How can I search for content in a cell in Excel, and if the content matches the search criteria update the content?

假如想象 提交于 2019-11-26 23:33:55
问题 I'm working on a Python (using 2.7) project to search through excel files for a UNC path for a server that is changing, and then update the cell with the new UNC path. I'm new to python and I'm able to find the cell and print it with: def main(): wb = load_workbook(filename = 'Book1_test.xlsx', use_iterators = True) ws = wb.get_sheet_by_name(name = 'Sheet1') for row in ws.iter_rows(): for cell in row: print cell.value But, I don't know how to update the cell with the new string, and the

cannot import workbook in openpyxl

时光总嘲笑我的痴心妄想 提交于 2019-11-26 21:56:57
问题 I have installed openpyxl in ubuntu. now I am running the openpyxl with xlsx files. While importing the module, it gives me the following error. from openpyxl import Workbook ImportError: cannot import name Workbook Can anyone knows what I have to do to solve the problem? 回答1: I think you want: from openpyxl import workbook # not Workbook Note the capitalization of the name here. 回答2: I answer your second problem, because I found the solution (as though the cause of the first one is the same)

How to save a new sheet in an existing excel file, using Pandas?

我们两清 提交于 2019-11-26 21:44:56
I want to use excel files to store data elaborated with python. My problem is that I can't add sheets to an existing excel file. Here I suggest a sample code to work with in order to reach this issue import pandas as pd import numpy as np path = r"C:\Users\fedel\Desktop\excelData\PhD_data.xlsx" x1 = np.random.randn(100, 2) df1 = pd.DataFrame(x1) x2 = np.random.randn(100, 2) df2 = pd.DataFrame(x2) writer = pd.ExcelWriter(path, engine = 'xlsxwriter') df1.to_excel(writer, sheet_name = 'x1') df2.to_excel(writer, sheet_name = 'x2') writer.save() writer.close() This code saves two DataFrames to two

How to write a list to xlsx using openpyxl

最后都变了- 提交于 2019-11-26 21:25:02
问题 I have a list of some values in Python and want to write them into an Excel-Spreadsheet using openpyxl. So far I tried, where lstStat is a list of integers that needs to be written to the Excel file: for statN in lstStat: for line in ws.range('A3:A14'): for cell in line: cell.value(statN) I'm getting a TypeError: 'NoneType' object is not callable for the last line in the code snipet. Can you help me out how to write my data to the Excel file? Cheers Thomas 回答1: To assign a value to a cell,

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

倾然丶 夕夏残阳落幕 提交于 2019-11-26 21:15:22
问题 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