XLSGrid is a class based on grid.Grid that can be used to faithfully reproduce the appearance of a Microsoft Excel spreadsheet (one worksheet per every instance of XLSGrid).
XLSGrid is a class based on grid.Grid that can be used to faithfully reproduce the appearance of a Microsoft Excel spreadsheet (one worksheet per every instance of XLSGrid).
XLSGrid is a completely owner-drawn control, and it relies on the power of grid.PyGridTableBase and grid.PyGridCellRenderer to draw the cell content. For this reasons (and for some others, see the TODOs section), it will work efficiently only for relatively small Excel files.
Note
XLSGrid requires the xlrd package from:
http://pypi.python.org/pypi/xlrd
Minimum version requirement for xlrd is 0.7.1. If you wish to have support for hyperlinks inside cells and rich text content, you need the SVN version of xlrd.
Note
On Windows, it is strongly recommended to install Mark Hammonds’ pywin32 package:
http://sourceforge.net/projects/pywin32/
This will allow you to perfectly reproduce the appearance of the Excel worksheet in your instance of XLSGrid.
Warning
If Mark Hammonds’ pywin32 package is not available, the formatting capabilities of XLSGrid are severely limited; for instance, you won’t probably get the exact WYSIWYG between the Excel spreadsheet and XLSGrid.
Warning
XLSGrid can only read Excel xls files, not the newer versions xlsx generated by Office 2007/2010. If you have a xlsx file, you will need to save it in 1997-2003 Office compatibility mode.
Currently this class provides a read-only subclass of grid.Grid, with the following formatting features already implemented:
And a lot more. Check the demo for an almost complete review of the functionalities.
Sample usage:
import wx
import xlrd
import os
import xlsgrid as XG
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, parent, -1, "XLSGrid Demo", size=(1000, 800))
filename = os.path.join(os.getcwd(), "Excel", "Example_1.xls")
sheetname = "Example_1"
book = xlrd.open_workbook(filename, formatting_info=1)
sheet = book.sheet_by_name(sheetname)
rows, cols = sheet.nrows, sheet.ncols
comments, texts = XG.ReadExcelCOM(filename, sheetname, rows, cols)
xls_grid = XG.XLSGrid(self)
xls_grid.PopulateGrid(book, sheet, texts, comments)
# our normal wxApp-derived class, as usual
app = wx.App(0)
frame = MyFrame(None)
app.SetTopWindow(frame)
frame.Show()
app.MainLoop()
Note
Please note that you have to pass the keyword formatting_info to the method xlrd.open_workbook to obtain the cell formatting.
No particular window styles are available for this class.
No custom events are available for this class.
XLSGrid is distributed under the wxPython license.
Latest Revision: Andrea Gavana @ 20 Mar 2012, 21.00 GMT
Version 0.4
FontFromFont | Creates a copy of the input font. |
ReadExcelCOM | Reads and Excel spreadsheet (a single worksheet) using Mark Hammonds’ pywin32 |
SplitThousands | Splits a general float on thousands. GIGO on general input. |
Excel | A simple class that holds a COM interface to Excel. |
TransientPopup | This is a sublass of SuperToolTip and it is used to display a |
XLSBackground | This is a class which holds information about the cell background, in terms |
XLSBorder | This is a class which holds information about a single cell border, in terms |
XLSBorderFactory | This is a factory class which holds information about all the borders in a |
XLSCell | This is a class which holds information about a single cell in XLSGrid. |
XLSComment | This is a class which holds information about the content of the “comment |
XLSGrid | XLSGrid is a class based on grid.Grid that can be used to faithfully |
XLSRenderer | This class is responsible for actually drawing the cell in the grid. |
XLSRichText | This is a class which holds information about the cell content, in terms |
XLSTable | The almost abstract base class for grid tables. |
XLSText | This is a class which holds information about the cell content, in terms |
Reads and Excel spreadsheet (a single worksheet) using Mark Hammonds’ pywin32 package. If this package is not available, it returns two empty nested lists.
Parameters: |
|
---|---|
Returns: | two nested lists representing the comments (notes) on every cell and the WYSIWYG representation of the cell content. |
Note
If Mark Hammonds’ pywin32 package is not available, this method returns two empty nested lists.
Splits a general float on thousands. GIGO on general input.
Parameters: |
|
---|---|
Returns: | a string properly formatted with thousands and decimal separators in it. |
Note
This method is used only if Mark Hammonds’ pywin32 package is not available to try and format a number in an intelligent way.
Note
This code has been obtained from the public domain:
http://code.activestate.com/recipes/498181-add-thousands-separator-commas-to-formatted-number/#c14