
June 24th, 2003, 09:56 PM
|
|
Registered User
|
|
Join Date: Jun 2003
Posts: 1
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Excel in ASP.NET
I have a bunch of code I got from someone written in a macro within Microsoft excel. the code takes data within cells from different sheets, does some calculations and writes out new data in a new sheet.<br><br>I have to move this to an ASP.NET page. However, Ive spent 10 - 12 hours already and I havent got anywhere.<br><br>These are my IMPORTS:<br>__________________________________<br>Option Explicit On <br>Imports System.Runtime.InteropServices.Marshal<br>Imports System.Math<br>Imports Excel<br>__________________________________<br><br>The bigest deal here apparently will be the input / output. Thats what will have to change the most im assuming.<br><br>I will be using the "Excel 10.0 Object Library". Just I cant get to the point where I actually specify the file name and open it for work. <br><br>I've tried code snippits from all over the web and nothing works. WHen I use this:<br><br>_____________________________________________<br> Dim xlApp As Excel.Application<br> Dim xlAppPID As Long<br> Dim xlWorkbooks As Excel.Workbooks<br> Dim xlWorkbook As Excel.Workbook<br> Dim xlSheet As Excel.Worksheet<br><br><br>and try to use these variables to open my file I get some error<br><br>_______________________________________________<br><br>this code:<br><br> xlApp = CType(CreateObject("Excel.Application"), Excel.Application)<br> xlsBook = CType(xlsApp.Workbooks.Add, Excel.Workbook)<br> xlsSheet = CType(xlsBook.Worksheets(1), Excel.Worksheet)<br><br>makes my page run infinitely<br><br>_______________________________________<br><br>whenever i use the new statment I get the error<br>"new cannot be used on an interface"<br><br>ie<br> Dim XL As New Excel.Application<br> Dim XlSheet As New Excel.Worksheet<br> If XL Is Nothing Then<br> MsgBox("Cant create excel object.")<br> Exit Sub<br> End If<br> Try<br> XlSheet = XL.Workbooks.Open(strXlFile).Worksheets("ToCollect")<br> Catch<br> MsgBox("Couldn't open or find :" & strXlFile & ". Error message = " & Err.Description & _<br> ". Error number = " & Err.Number)<br> XlSheet = Nothing<br> XL = Nothing<br> Return LocalArrayToSend<br> Exit Sub<br> End Try<br> strActivePhonenumber = XlSheet.Cells(4, 3).value<br><br> If XlSheet.Cells(8, 3).value = "v" Then<br> blCollectAnal1 = True<br> Else<br> blCollectAnal1 = False<br> End If<br><br> If XlSheet.Cells(9, 3).value = "v" Then<br> blCollectAnal2 = True<br> Else<br> blCollectAnal2 = False<br> End If<br><br>__________________________________________________ <br><br>If anyone is out there that has worked with excel I would really appreciate some help. Ive got 1 day left to get this done.<br><br>Im not exactly sure where to start but i know i need an instance of an object that points to my file so i can minipulate it with the vba code (that obvioulsy I have to conver [chang syntax here and there I suppose])<br><br>Thanks a lot<br><br>Dave
|