ClosedXML no attribute Cell or Range

I am trying to export to excel via ClosedXML. It works but I can’t create a table because it does not find Cell or Range attributes. It can only find Cells and Ranges… Why is it like that? I can see that there is Cell and Range attribute under Worksheet class.

.NET Expert @c.poupin you are the only one to solve that again :slight_smile:

It has Range and Cell Attribute on GitHub:

hi @Deniz_Maral, I never used this library ¯\(ツ)

1 Like

Thanks for reply :slight_smile:
then last hope can be @Konrad_K_Sobon. I saw you use also that library in your nodes :slight_smile:

I found the problem…

I have XLWorksheet and IXLWorksheet as subclass. How can I get methods of a subclass in Python?

I think you’d implement it similar to FamilyLoadOptions.

class FamilyOption(IFamilyLoadOptions):
    def OnFamilyFound(self, familyInUse, overwriteParameterValues):
        overwriteParameterValues = True
        return True

    def OnSharedFamilyFound(
            self, sharedFamily, familyInUse, source, overwriteParameterValues):
        source = FamilySource.Family
        overwriteParameterValues = True
        return True

Hello @SeanP,

thank you very much for reply. I can’t get it well, unfortunately.

as Worksheet I have that:

but I need its subclass IXLWorksheet because I can add tables in its subclass (Range.CreateTable() or Cell().CreateTable()).

In C# you can specifiy return type of attributes.

For example: IXLCell c = ws.Cells(string "A1")
How can I return c as IXLCell and not XLCell in Python. I don’t know that…

I found something new:

The IXLWorksheet Class is an interface and XLWorksheet was implemented:

My question: how can I implement a class in IronPython?

try this

import sys
import clr
from Autodesk.DesignScript.Geometry import *
import ClosedXML
from ClosedXML.Excel import *
ClosedXML Doc -> IXLRanges Ranges(string ranges);
/// <summary>Returns a collection of ranges, separated by commas.</summary>
/// <para>e.g. Ranges("A1"), Ranges("A1:C2"), Ranges("A1:B2,D1:D4")</para>
/// <param name="ranges">The ranges to return.</param>
with XLWorkbook(IN[0], XLEventTracking.Disabled) as wb:
	ws = wb.Worksheet(1)
	# dataTable = ws.RangeUsed().AsTable().AsNativeDataTable()
	r = ws.Ranges("A1:C22")
	cellsValue = [c.GetString() for c in r.Cells()]
OUT = cellsValue

Merci Cyril! but it did not apply that table:

BTW: how did you download that dll file? I get it only with archi-lab package and its not the latest version.

It is all about the interfaces… but I don’t know how to manage that in Python.

this line was just a test, I comment it

1 Like

No problem, still thank you very much for your efforts. As @SeanP said, we should implement methods of subclass IXLWorksheet.
If we create a worksheet from:
ws = Excel.XLWorkbook().AddWorksheet()

It gives XLWorksheet as DataType. In C# you can manage to get it as IXLWorksheet so as to use its methods.

Here you can see that @Konrad_K_Sobon could use methods of IXLWorksheet in his node: