Posts

Showing posts from July, 2024

Donate

Excel Interop Get Last Row Logic Conversion To ClosedXML

Hello, I was assigned to convert a VB.NET project that will generate an excel file using Excel COM interop into C# with ClosedXML as the tool to produce the report. When the project was finished coding and proceed to testing, the logic to get the last row isn't working and throws "Object Reference Not Set To An Instance" error. The VB.NET logic that I need to convert to ClosedXML is presented below. Private Function GetLastRow () As Int32 xlRange = xlWSheet.Range( "A65536" ).End(Excel.XlDirection.xlUp) GetLastRow = xlRange.Row() xlRange = Nothing End Function After reading the ClosedXML documentation and doing some debugging stuff, I successfully converted the Excel Interop function to ClosedXML counterpart. Below is the function that returns the last row used. All I need to do is to check first if last row used is null, then return row one. Otherwise, return the succeeding rows. private int GetLastRow (IXLWorksheet xlWSheet)

Donate