creating a table in excel using python - python

I am using xlwt to write to cells in excel from python. I am wondering if there is some way to select the written cells and insert a table. I have references to the cell range. Please help out.

I m not aware of xlwt. But you can try it using xlsxwriter.
https://xlsxwriter.readthedocs.org/working_with_tables.html

Related

Python openpyxl Table Styling convert table to range

I generate this spreadsheet via python and pandas. After generating the .xlsx file,
i would go into Excel and format it using the table Format as table button on the main ribbon.
I decided that i didn't want to manually format the spreadsheet so I started using Openpyxl to attempt to mimic my formats.
my main hiccup is that after i use the format as table button
I would then click on Convert to Range.
The problem is, i cant seem to be able to do this using openpyx.
Does anyone know how to do this? I don't want to create my own personalized style if one already exists.
this is the code i have been using
tab = Table(displayName="Final', ref='A1:O34', tableType=None)
style = TableStyleInfo(name="TableStyleLight2", showFirstColumn=False,
showLastColumn=False, showRowStripes=True, showColumnStripes=False)
tab.tablestyleInfo = style
ws.add_table(tab)
wb.save()
Very basic and to the point, more or less copied from teh openpyxl documents.
How do i convert this table to a range of values from openpyxl
thanks
Damn Groundhog
Have you looked at xlsxwriter? It has an option to turn the autofilter on/off when creating a table.

Python add pandas.core.series.Series to excel

I'm working with an excel from which I want to extract certain information and display it in another excel. Using pandas and openpyxl I was able to get the rows I needed to copy (whos type is "pandas.core.series.Series") but I don't know how to copy just those rows to an excel.
Any ideas?
To export a pandas.Series to Excel.
df.to_excel("output.xlsx", sheet_name="Sheet_Name_1")
Documentation.

Writing from Excel sheet to a table

I am looking to write certain columns of data from an excel sheet to a HTML table. Not looking to write specific/fixed cells into the table always, need to do this based on conditions. For example, if I have a table with columns Name/Age/Occupation, I would like to make an HTML table using just columns Name and Occupation. Also, within Name, I would only like to write the names starting with 'N' onto the table and corresponding Occupation. The Excel sheet dynamically changes with new data everytime. Essentially, I would not want to write specific cells or range of cells into the table but only the data based on conditions I set. Any suggestions using python/html/jquery or other methods are welcome.
First you should edit the Excel file, export it as a .csv file and then work on the file using a program language of your preference. It would be much much more complicated if you try to work on the .xls or .xlsx files. I recommend using python with its library panda that works on csv files.
For parsing excel files, I've had good success using openpyxl
A Python library to read/write Excel 2010 xlsx/xlsm files

Using Python (and DataNitro) to copy cells from a particular sheet in one Excel workbook, to a particular sheet in another Excel workbook

I do a lot of data analysis in Excel and have been exploring Python and DataNitro to streamline my workflow. I specifically am trying to copy certain cells from one sheet in one Excel workbook, and paste them into certain cells in a certain sheet in another Excel workbook.
I have been storing ("copying") using CellRange (DataNitro), but am not sure how to copy the stored contents into a particular sheet, in another Excel workbook. Any clue how I may go about this? Also, is it possible to make the range defined for a CellRange conditional on certain cell properties?
I would really appreciate any help! Thank you, all.
Here's an example of copying:
data = CellRange("A1:A10").value
active_wkbk("Book2.xlsx")
CellRange("A1:A10").value = data
You can make the range conditional using regular Python logic (if statements, etc.).

Use Pyxl to read Excel spreadsheet data up to a certain row

I created an Excel spreadsheet using Pandas and xlsxwriter, which has all the data in the right rows and columns. However, the formatting in xlsxwriter is pretty basic, so I want to solve this problem by writing my Pandas spreadsheet on top of a template spreadsheet with Pyxl.
First, however, I need to get Pyxl to only import data up to the first blank row, and to get rid of the column headings. This way I could write my Excel data from the xlsxwriter output to the template.
I have no clue how to go about this and can't find it here or in the docs. Any ideas?
How about if I want to read data from the first column after the first blank column? (I can think of a workaround for this, but it would help if I knew how)
To be honest I'd be tempted to suggest you use openpyxl all the way if there is something that xlsxwriter doesn't do, though I think that it's formatting options are pretty extensive. The most recent version of openpyxl is as fast as xlsxwriter if lxml is installed.
However, it's worth noting that Pandas has tended to ship with an older version of openpyxl because we changed the style API.
Otherwise you can use max_row to get the highest row but this won't check for an empty row.

Categories

Resources