Hi,
I am trying to Read the first row of an axcel file and store the fieldnames in an array.
I am doing all this in a class , and I am instantiating this class in main ASP page, where I am calling the public method
Here Is the code:
Code:
<%
Class ExcelReader
'Delcare Excel Application Object,
Private xlApp
Private xlWorkbk
Public intCol
Public fieldName(50)
Public Strrow
Public Sub ColumnInfo(FileName)
On Error Resume Next
'Create Excel Application Object
Dim strFilename
strFileName = "C:\temp\" & cStr(FileName)
Set xlApp = Server.CreateObject("Excel.Application")
Set xlWorkbk = xlApp.Workbooks.Open(strFileName)
'Retrive the fieldnames in First row into Array
Dim intRow
Dim ArrayIndex
intRow = 1
intCol = 1
ArrayIndex = 1
Strrow = "Names of fields"
While (cStr(xlApp.Worksheets("tblScholarYear").Cells.Item(1, intCol).Value) <> "")
' I am getting error at the below line
fieldName(ArrayIndex) = cStr(xlApp.Worksheets("tblScholarYear").Cells.Item(1, intCol).Value)
Strrow = Strrow & " " & cStr(fieldName(ArrayIndex))
'Strrow = strrow & " " & cStr(xlApp.WorkSheets("tblScholars").Cells.Item(1, intCol).Value)
intCol = intCol + 1
ArrayIndex = ArrayIndex + 1
Wend
'Clean up the Excel Application Object
xlWorkbk.Close
Set xlWorkbk = Nothing
xlApp.Quit
Set xlApp = Nothing
End Sub
End Class
%>
I am getting error when I am trying to assign the cell value to the array.
Can any body help me with this, Please.
Thanks.