This project has moved and is read-only. For the latest updates, please go here.

Can't find Cell method on Worksheet, using IronPython

Sep 30, 2011 at 6:00 PM

I'm probably doing something stupid, but I can't find the 'Cell' method on a Worksheet.

Here's a demonstration, using IronPython. Notice that when I show all the attributes on the worksheet, it has 'Cells' but not 'Cell'.

Has anyone else tried this library in IronPython? Am I doing something wrong?

IronPython 2.6.2 (2.6.10920.0) on .NET 2.0.50727.3623
Type "help", "copyright", "credits" or "license" for more information.
>>> import clr
>>> clr.AddReference("ClosedXML")
>>> import ClosedXML
>>> ClosedXML
<module 'ClosedXML' (CLS module from ClosedXML, Version=, Culture=neutral, PublicKeyToken=fd1eb21b62ae805b)>
>>> wb=ClosedXML.Excel.XLWorkbook()
>>> wb
<ClosedXML.Excel.XLWorkbook object at 0x000000000000002B [ClosedXML.Excel.XLWorkbook]>
>>> ws=wb.Worksheets.Add("Test Sheet")
>>> ws
<ClosedXML.Excel.XLWorksheet object at 0x000000000000002C ['Test Sheet'!A1:XFD1048576]>
>>> ws.Cell(1,1).Value = "Test Value"
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'XLWorksheet' object has no attribute 'Cell'
>>> dir(ws)
['AddToNamed', 'AsRange', 'AutoFilterRange', 'Cells', 'CellsUsed', 'Clear', 'CollapseColumns', 'CollapseRows', 'ColumnCount', 'ColumnWidth', 'Columns', 'Contains', 'CopyTo', 'DataType', 'Delete', 'DeleteComments', 'Equals', 'ExpandColumns', 'ExpandRows', 'FixColumnAddress', 'FixRowAddress', 'FormulaA1', 'FormulaR1C1',
'GetHashCode', 'GetStyle', 'GetType', 'Hide', 'Hyperlinks', 'Intersects', 'IsEmpty', 'IsMerged', 'MemberwiseClone', 'Merge', 'Name', 'NamedRange', 'NamedRanges', 'Outline', 'PageSetup', 'PivotTables', 'Position', 'Protect', 'RangeUsed', 'Ranges', 'ReferenceEquals', 'RightToLeft', 'RowCount', 'RowHeight', 'Rows', 'SetRightToLeft', 'SetShowFormulas', 'SetShowGridLines', 'SetShowOutlineSymbols', 'SetShowRowColHeaders', 'SetShowRuler', 'SetShowWhiteSpace', 'SetShowZeros', 'SetStyle', 'SetTabActive', 'SetTabColor', 'SetTabSelected', 'SetValue', 'ShareString', 'SheetView', 'ShiftColumns', 'ShiftRows', 'ShowFormulas', 'ShowGridLines', 'ShowOutlineSymbols', 'ShowRowColHeaders', 'ShowRuler', 'ShowWhiteSpace', 'ShowZeros', 'Sort', 'SortColumns', 'SortRows', 'Style', 'TabActive', 'TabColor', 'TabSelected', 'Table', 'Tables', 'ToString', 'Unhide', 'Unmerge', 'Unprotect', 'Value', 'Visibility', 'Workbook', '__class__', '__delattr__', '__doc__', '__format__',
'__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']
>>> dir(wb)
['CalculateMode', 'Cell', 'CellSetValueBehavior', 'Cells', 'ColumnWidth', 'CustomProperties', 'CustomProperty', 'DefaultColumnWidth', 'DefaultOutline', 'DefaultPageOptions', 'DefaultRightToLeft', 'DefaultRowHeight', 'DefaultShowFormulas', 'DefaultShowGridLines', 'DefaultShowOutlineSymbols', 'DefaultShowRowColHeaders',
'DefaultShowRuler', 'DefaultShowWhiteSpace', 'DefaultShowZeros', 'DefaultStyle', 'Equals', 'FindCells', 'FindColumns', 'FindRows', 'GetHashCode', 'GetType', 'MemberwiseClone', 'NamedRange', 'NamedRanges', 'Outline', 'PageOptions', 'Properties', 'Range', 'Ranges', 'ReferenceEquals', 'ReferenceStyle', 'RightToLeft', 'RowHeight', 'Save', 'SaveAs', 'ShowFormulas', 'ShowGridLines', 'ShowOutlineSymbols', 'ShowRowColHeaders', 'ShowRuler', 'ShowWhiteSpace', 'ShowZeros', 'Style', 'Theme', 'ToString', 'Worksheet', 'Worksheets', '__class__', '__delattr__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__']

Sep 30, 2011 at 8:27 PM

I have no idea, my first guess was that dir(ws) was getting the methods defined in the XLWorksheet class but not the interface but Cell(String) is defined the same way Cells() so there goes that theory =(


Sep 30, 2011 at 8:41 PM

Thanks for responding, MDeLeon.  This looks like it'll be a nice library to use once I discover the issue here.

On a likely related note, I noticed that the worksheet is also missing Row, but has Rows.