Hello, sorry for the delay but lately I’ve had trouble connecting to the Internet.
The point is that I am generating (using xlwt) an Excel document, from the data loaded in a form and stored in a SQLite database, to then load this document in my application using XLSGrid.
Queries to the database, return, in some fields a None value (for example, a date that is not loaded in the form and get a default None value in the database), and are those fields that cause the error.
I assume that indeed is a bug in xlwt (which I have not checked), which did not consider the nature of the document created, since it is very different to create a spreadsheet using OpenOffice, Excel or similar, to create it in a rather more “Handcrafted” way.
And thank you very much for the suggestions and corrections regarding the conditional, sometimes I have a tangled mind, so sometimes I make some strange errors.
···
On Monday, August 8, 2011 4:36:17 PM UTC-4:30, Infinity77 wrote:
Hi All,
it's been a while since my last "announcement"... Anyway, I am happy to announce the birth of my latest child, XLSGrid.
Source code:
http://xoomer.virgilio.it/infinity77/Zipped/XLSGrid.zip
Screenshots:
(XLSGrid standalone)
http://xoomer.virgilio.it/infinity77/Softwares/XLSGrid_1.png
(XLSGrid against Excel, same file)
http://xoomer.virgilio.it/infinity77/Softwares/XLSGrid_3.png
@Robin and other wxGrid gurus (which group I am not part of, unfortunately), a couple of questions at the end of the message. Any suggestion is more than welcome.
@Warning: XLSGrid requires the xlrd package from:
http://pypi.python.org/pypi/xlrd
@Warning: XLSGrid has been tested on Windows Vista/Windows 7 with wxPython 2.8.11 unicode and Python 2.5, and wxPython 2.9.2.1 unicode and Python 2.7.
So, what is XLSGrid?
XLSGrid is a class based on wx.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
wx.grid.PyGridTableBase and wx.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: 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 wx.grid.Grid
, with
the following formatting features already implemented:
-
Cell background: support for any cell background colour and fill pattern
(hatching) in the Excel default set. There currently is no support for
gradient shading inside a cell as xlrd
doesn’t report this information.
- Cell borders: support for all the border types and colours exposed by
Excel (left, top, bottom, right and diagonal borders, thin, double,
thick, ect… line styles).
- Cell text: support for all kind of fonts (except strike-through, but this
is a bug in wxWidgets), and font colours. As a subset of text/font
capabilities, XLSGrid supports the following features found in Excel:
-
Horizontal alignment: left, right, centered, left-indented;
-
Vertical alignment: left, right, centered;
-
Text direction: left-to-right or right-to-left;
-
Text-wrapping: wrapping long texts inside a grid cell;
-
Shrink-to-fit: text font is reduced until the text can fit in a one-line
inside the grid cell;
-
Text rotation: text can be rotated from +90 to -90 degrees.
- Cell text appearance: if you are using Mark Hammonds’
pywin32
package,
the text displayed in the XLSGrid cells has exactly the same appearance
as in the Excel spreadsheet.
- Cell comments (notes): if you are using Mark Hammonds’
pywin32
package,
cell comments (notes) are extracted and you will see a small red triangle
at the top-right corner of any cell containing a comment. Hovering with
the mouse on that cell will pop-up a “comment-window” displaying the
comment text (the comment window is based on wx.lib.agw.supertooltip).
-
Cell hyperlinks: starting from version 0.7.2 (SVN), xlrd
is capable of
extracting hyperlinks from Excel cells. This will be appropriately displayed
in XLSGrid with a cursor changing and a tooltip on that cell.
- Cell merging: merged cells in the Excel spreadsheet will be correctly
handled by XLSGrid.
are based on the default width of the text in 1/256 of the width of the
zero character, using default Excel font (first FONT record in the Excel
file).
Questions:
- I have this piece of code in the XLSGrid implementation (which is currently commented out):
# Commented-out section
if self.attr is not None:
self.attr.IncRef()
return self.attr
attr = gridlib.GridCellAttr()
attr.SetRenderer(XLSRenderer(self))
attr.SetSize(*self.size)
attr.SetOverflow(True)
self.attr = attr
return self.attr
I though I could store a wx.grid.GridCellAttr inside a class member, but every time I try to un-comment that section I get this from wxPython 2.8.11:
Traceback (most recent call last):
File “E:\MyProjects\temp\XLSGrid.py”, line 1553, in GetAttr
return cell.GetAttr()
File “E:\MyProjects\temp\XLSGrid.py”, line 1356, in GetAttr
self.attr.IncRef()
File “C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\grid.py”, line 529, in IncRef
return _grid.GridCellAttr_IncRef(*args, **kwargs)
TypeError: in method ‘GridCellAttr_IncRef’, expected argument 1 of type ‘wxGridCellAttr *’
Or this one, in wxPython 2.9.2.1:
Traceback (most recent call last):
File “E:\MyProjects\XLSGrid\xlsgrid.py”, line 1553, in GetAttr
return cell.GetAttr()
File “E:\MyProjects\XLSGrid\xlsgrid.py”, line 1356, in GetAttr
self.attr.IncRef()
File “c:\Python27\lib\site-packages\wx-2.9.2-msw\wx_core.py”, line 797, in IncRef
return core.RefCounter_IncRef(*args, **kwargs)
TypeError: in method ‘RefCounter_IncRef’, expected argument 1 of type ‘wxRefCounter *’
Isn’t self.attr an instance of GridCellAttr?!?? I explicitly create it in the code above!!
wx.grid.Grid
seems to completely redraw itself at every resize event, even if the cell content has not changed and it has not been damaged. This happens also in the “MegaGrid” sample in the wxPython demo. Why is that? I thought that the undamaged/unchanged cells should just be skipped from refreshing. I have tried to add wx.CLIP_CHILDREN and wx.NO_FULL_REPAINT_ON_RESIZE on the parent window, to no avail.
Enjoy, wxPython rules
Andrea.
“Imagination Is The Only Weapon In The War Against Reality.”
http://xoomer.alice.it/infinity77/