how can I open an existing Excel workbook with ASP Internet Client ?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 2 of 2

Thread: how can I open an existing Excel workbook with ASP Internet Client ?

  1. #1
    Alox Guest

    how can I open an existing Excel workbook with ASP Internet Client ?


    Please help me!!!

    I need to open an Excel workbook (using ASP) from an Internet client.
    I mean, I have an ASP where any users can (will can) open an Excel workbook
    that can be in a Client PC or a floopy Disk, and they must see that workbook
    in the ASP.

    I tried with CreateObject("Excel.workbook") but, doesn't work.

    I'll keep praying to Saint ASP tonight.


    Alox.

  2. #2
    Glenn Guest

    Re: how can I open an existing Excel workbook with ASP Internet Client ?


    "Alox" <fabianrock@netexplora.com> wrote:
    >
    >Please help me!!!
    >
    > I need to open an Excel workbook (using ASP) from an Internet client.
    > I mean, I have an ASP where any users can (will can) open an Excel workbook
    >that can be in a Client PC or a floopy Disk, and they must see that workbook
    >in the ASP.
    >
    > I tried with CreateObject("Excel.workbook") but, doesn't work.
    >
    > I'll keep praying to Saint ASP tonight.
    >
    >
    > Alox.



    Alox, I have copied in here some snippets of code from a page of mine. All
    this code runs on the client using IE. Hopefully, Saint ASP is giving you
    what you need!

    Here it is:

    '***********************************************************************
    'This simply opens the workbook for the user.
    '***********************************************************************
    Sub CrankUpExcel()

    Dim objExcel
    Dim objWorkBook

    Set objExcel = CreateObject("Excel.Application")
    objExcel.visible = True
    Set objWorkBook = objExcel.Workbooks.open(gsDocFileName)

    Set objWorkBook = Nothing
    Set objExcel = Nothing

    End Sub

    '***********************************************************************
    'This opens a workbook and creates/updates worksheets in it.
    'The user doesn't see this because objExcel.visible = False,
    'but you could make it visible.
    '***********************************************************************
    Sub UpdateExcelWorksheet()
    Dim objExcel
    Dim objWorkBook
    Dim objMainSheet
    Dim objOtherSheet
    Dim objLastSheet
    Dim objCell
    Dim sMainSheetName
    Dim sOtherSheetName
    Dim nNumSheets
    Dim bExists
    Dim nX

    sMainSheetName = "Imported Order"
    sOtherSheetName = "Other"

    Set objExcel = CreateObject("Excel.Application")
    objExcel.visible = False
    Set objWorkBook = objExcel.Workbooks.open(gsExcelFileName)

    'Check if mainsheet already exists in chosen workbook.
    bExists = False
    nNumSheets = objExcel.ActiveWorkBook.Worksheets.count
    For nX = 1 To nNumSheets
    If objExcel.ActiveWorkBook.Worksheets.item(nX).name = sMainSheetName Then
    bExists = True
    Exit For
    End If
    Next
    Set objLastSheet = objExcel.ActiveWorkBook.Worksheets(nNumSheets)
    'If mainsheet doesn't exist, create it.
    If not bExists Then
    Set objMainSheet = objExcel.ActiveWorkBook.Worksheets.add (, objLastSheet)
    objMainSheet.name = sMainSheetName
    objMainSheet.columns(1).columnWidth = 20
    objMainSheet.columns(2).columnWidth = 40
    objMainSheet.columns(3).columnWidth = 20
    objMainSheet.columns(4).columnWidth = 20
    objMainSheet.columns(5).columnWidth = 20
    Else
    'First, clear out all cells
    Set objMainSheet = objExcel.ActiveWorkBook.Worksheets.item(sMainSheetName)
    objMainSheet.UnProtect "<%=sExcelSheetPassword%>"
    objMainSheet.range("A1:E100").clearContents
    End If

    'Check if Othersheet already exists in chosen workbook.
    bExists = False
    nNumSheets = objExcel.ActiveWorkBook.Worksheets.count
    For nX = 1 To nNumSheets
    If objExcel.ActiveWorkBook.Worksheets.item(nX).name = sOtherSheetName Then
    bExists = True
    Exit For
    End If
    Next
    Set objLastSheet = objExcel.ActiveWorkBook.Worksheets(nNumSheets)
    'If Othersheet doesn't exist, create it.
    If not bExists Then
    Set objOtherSheet = objExcel.ActiveWorkBook.Worksheets.add (, objLastSheet)
    objOtherSheet.name = sOtherSheetName
    objOtherSheet.columns(1).columnWidth = 10
    objOtherSheet.columns(2).columnWidth = 15
    objOtherSheet.columns(3).columnWidth = 16
    objOtherSheet.columns(4).columnWidth = 15
    objOtherSheet.columns(5).columnWidth = 11
    objOtherSheet.columns(6).columnWidth = 15
    objOtherSheet.columns(7).columnWidth = 15
    objOtherSheet.columns(8).columnWidth = 10
    objOtherSheet.columns(9).columnWidth = 30
    objOtherSheet.Range("A1:I1").Font.Size = 10
    objOtherSheet.Range("A1:I1").Font.Bold = True
    Else
    'First, clear out all cells
    Set objOtherSheet = objExcel.ActiveWorkBook.Worksheets.item(sOtherSheetName)
    objOtherSheet.UnProtect "<%=sExcelSheetPassword%>"
    objOtherSheet.range("A1:I20").clearContents
    End If

    Set objCell = objMainSheet.cells(1,1)
    objCell.value = "ID#"
    Set objCell = objMainSheet.cells(1,2)
    objCell.value = window.frmOrder.txtIDNum.value

    Set objCell = objMainSheet.cells(2,1)
    objCell.value = "OrderType"
    Set objCell = objMainSheet.cells(2,2)
    etc. etc.....

    'Sort the range A2:P20 on column starting in A2
    objContactsSheet.Range("A2:P20").Sort objContactsSheet.Range("A2")

    '**************************
    '** Format Other **
    '**************************

    nX = 1
    Set objCell = objOtherSheet.cells(nX,1)
    objCell.value = "Service"
    Set objCell = objOtherSheet.cells(nX,2)
    objCell.value = "Event"
    Set objCell = objOtherSheet.cells(nX,3)
    objCell.value = "Date Requested"
    etc. etc.....

    objMainSheet.Protect "<%=sExcelSheetPassword%>" 'Protect and set password
    objOtherSheet.Protect "<%=sExcelSheetPassword%>" 'Protect and set password

    On Error Resume Next
    objWorkBook.Save
    objWorkBook.Close
    objExcel.quit
    Set objCell = Nothing
    Set objMaintSheet = Nothing
    Set objOtherSheet = Nothing
    Set objLastSheet = Nothing
    Set objWorkbook = Nothing
    Set objExcel = Nothing
    On Error GoTo 0

    End Sub


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center