I'm trying to find the dimensions of a worksheet. This is the code:
'Instantiate and open a Workbook object that represents an Excel file
Dim workbook As Workbook = New Workbook()
workbook.Open(Server.MapPath(fileLocation))
'Get worksheets from the workbook
Dim sheets As Worksheets = workbook.Worksheets
'Get the first worksheet
Dim sheet As Worksheet = sheets.Item(0)
'Get the cells collection of the worksheet
Dim cells As Cells = sheet.Cells
'Get worksheet dimensions
Dim startColumn, startRow, endColumn, endRow As Integer
startColumn = cells.Start.Column
startRow = cells.Start.Row
endColumn = cells.End.Column
endRow = cells.End.Row
However on an example excel file endColumn returns a value of 8 when there are in fact 14 columns. This has worked fine for some other tried excel files, however this one particular file is causing this problem. Is there anything in the page setup that could be causing this value to be returned?
'Instantiate and open a Workbook object that represents an Excel file
Dim workbook As Workbook = New Workbook()
workbook.Open(Server.MapPath(fileLocation))
'Get worksheets from the workbook
Dim sheets As Worksheets = workbook.Worksheets
'Get the first worksheet
Dim sheet As Worksheet = sheets.Item(0)
'Get the cells collection of the worksheet
Dim cells As Cells = sheet.Cells
'Get worksheet dimensions
Dim startColumn, startRow, endColumn, endRow As Integer
startColumn = cells.MinColumn
startRow = cells.MinRow
endColumn = cells.MaxDataColumn // you may use... cells.MaxColumn... if you also want to include the cells having any kind of style... this property won't mind if it does not have data in the cells for retrieving last column's index.
endRow = cells.MaxDataRow // you may use... cells.MaxRow... if you also want to include the cells having any kind of style... this property won't mind if it does not have data in the cells for retrieving last row's index.
Please be sure to let me know if every thing is fine now.