calling a function that's in the class

Results 1 to 2 of 2

Thread: calling a function that's in the class

  1. #1
    Join Date
    Dec 1969

    Default calling a function that's in the class

    I am trying to redirect user to a newly created spreadsheet with office web components. I get "header error" and was trying to link directly to spreadsheet instead of redirecting but don&#039;t know how to call the variable from function which is in the class.<BR>here&#039;s the code that&#039;s in the class.<BR> Option Explicit<BR> <BR><BR> Class ExcelGen<BR><BR> Private objSpreadsheet<BR> Private iColOffset<BR> Private iRowOffset<BR> Private strTmpDir<BR> <BR><BR> <BR> Sub Class_Initialize()<BR> Set objSpreadsheet = Server.CreateObject("OWC.Spreadsheet")<BR><BR> iRowOffset = 2<BR> iColOffset = 2<BR> <BR> strTmpDir = "C:Inetpubwwwroot
    eports\"<BR><BR> End Sub<BR><BR> Sub Class_Terminate()<BR> Set objSpreadsheet = Nothing &#039;Clean up<BR> End Sub<BR><BR> Public Property Let ColumnOffset(iColOff)<BR> If iColOff &#062; 0 then<BR> iColOffset = iColOff<BR> Else<BR> iColOffset = 2<BR> End If<BR> End Property<BR><BR> Public Property Let RowOffset(iRowOff)<BR> If iRowOff &#062; 0 then<BR> iRowOffset = iRowOff<BR> Else<BR> iRowOffset = 2<BR> End If<BR> End Property<BR><BR><BR> Sub GenerateWorksheetFromRecordset(RS, bolAutofitColumns)<BR> &#039;Populates the Excel worksheet based on a Recordset&#039;s contents<BR> &#039;Start by displaying the titles<BR> If RS.EOF then Exit Sub<BR><BR> Dim objField, iCol, iRow, iMaxColVal<BR> iCol = iColOffset<BR> iRow = iRowOffset<BR><BR> For Each objField in RS.Fields<BR> objSpreadsheet.Cells(iRow, iCol).Value = objField.Name<BR> objSpreadsheet.Cells(iRow, iCol).Font.Bold = True<BR> objSpreadsheet.Cells(iRow, iCol).Font.Underline = True<BR><BR> iCol = iCol + 1<BR> Next &#039;objField<BR><BR> &#039;Save the total number of columns we have for later use<BR> iMaxColVal = iCol - 1<BR><BR> &#039;Display all of the data<BR> Do While Not RS.EOF<BR> iRow = iRow + 1<BR> iCol = iColOffset<BR><BR> For Each objField in RS.Fields<BR> If IsNull(objField.Value) then<BR> objSpreadsheet.Cells(iRow, iCol).Value = ""<BR> Else<BR> objSpreadsheet.Cells(iRow, iCol).Value = objField.Value<BR> End If<BR><BR> iCol = iCol + 1<BR> Next &#039;objField<BR><BR> RS.MoveNext <BR> Loop<BR><BR> If bolAutofitColumns then &#039;autofit columns<BR> &#039;Loop from our offset to the max column position<BR> For iCol = iColOffset to iMaxColVal<BR> objSpreadsheet.Columns(iCol).AutoFitColumns<BR> Next<BR> End If<BR> End Sub<BR><BR><BR> Function SaveWorksheet(strFileName)<BR> &#039;Save the worksheet to a specified filename<BR> On Error Resume Next<BR> Call objSpreadsheet.ActiveSheet.Export(strFileName, 0)<BR><BR> SaveWorksheet = (Err.Number = 0)<BR> End Function<BR><BR><BR> Sub StreamWorksheet()<BR> &#039;Save the worksheet in a temporary file<BR> Dim strFileName, objFSO<BR><BR> Set objFSO = Server.CreateObject("Scripting.FileSystemObject")< BR> strFileName = strTmpDir & objFSO.GetBaseName(objFSO.GetTempName) & ".xls"<BR> Set objFSO = Nothing<BR><BR><BR> if SaveWorksheet(strFileName) then<BR> Response.Redirect strFileName<BR>&#039;**********************this is where i get error**********************<BR> end if<BR> End Sub<BR><BR><BR> Private Sub CleanUpSpreadsheets()<BR> Dim objFS<BR> Dim objFolder<BR> Dim objFile<BR><BR> set objFS = Server.CreateObject("Scripting.FileSystemObject")< BR> set objFolder = objFS.GetFolder(strTmpDir)<BR> <BR> &#039;Loop through each file in the strTmpDir folder<BR> for each objFile in objFolder.Files<BR> &#039;Delete Spreadsheets older than 10 minutes<BR> If DateDiff("n", objFile.DateLastModified, now) &#062; 10 then<BR> objFS.DeleteFile strTmpDir & objFile.Name, True<BR> end if<BR> next<BR><BR> set objFolder = nothing<BR> set objFS = nothing<BR> End Sub<BR> <BR><BR>End Class

  2. #2
    arby Guest

    Default RE: calling a function that's in the class

    Try creating two paths for the class.<BR> 1) The first one is the same as the one you are currently have created and are using. Use this one for creating the .xls<BR>file.<BR> 2) The second one create as - http://servername/virtualDirectory/filename.xls<BR><BR>This worked for me.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts