
From an ASP page, is there a way write to an EXCEL file without having EXCEL installed on the IIS machine ?
Quote:
> In my ASP page, I have a button that what it does is writing information
> to an EXCEL file.
> ...
> My client does not have EXCEL loaded on their server and will not load it.
> Is there any other way to write to an EXCEL file without using without
> having to install EXCEL on the IIS server ?
Any Windows OS of a practical vintage will already have the components
required to create a *basic* Excel workbook with one or more worksheets
filled with data. This is documented in many places, including a number of
MS KB articles.
A limitation is that you have no control over things like cell fonts, column
widths, etc. Even this may be overcome to an extent by copying a
pre-formatted "template" workbook and populating it with data. However the
example below (a WSH script for easy testing) creates a workbook from
scratch in the current directory:
Option Explicit
Private Const adCmdTable = 2
Private Const adLockOptimistic = 3
Private Const adOpenStatic = 3
Private Const adVarWChar = 202
Private catWB, tblWS, rsWS, intRow
Private Sub AddColumn(ByVal Table, ByVal ColName)
Dim Column
Set Column = CreateObject("ADOX.Column")
Column.Name = ColName
Column.Type = adVarWChar 'Can also use numeric types.
Table.Columns.Append Column
End Sub
Set catWB = CreateObject("ADOX.Catalog")
catWB.ActiveConnection = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source='created.xls';" _
& "Extended Properties='Excel 8.0;HDR=Yes'"
Set tblWS = CreateObject("ADOX.Table")
tblWS.Name = "Sample"
AddColumn tblWS, "First"
AddColumn tblWS, "Second"
AddColumn tblWS, "Third"
catWB.Tables.Append tblWS
Set tblWS = Nothing
Set rsWS = CreateObject("ADODB.Recordset")
With rsWS
Set .ActiveConnection = catWB.ActiveConnection
Set catWB = Nothing
.Open "Sample", , adOpenStatic, adLockOptimistic, adCmdTable
For intRow = 2 To 100
.AddNew
.Fields("First").Value = CStr(intRow * 10)
.Fields("Second").Value = CStr(intRow * 100)
.Fields("Third").Value = CStr(intRow + 10000)
.Update
Next
.Close
End With
Set rsWS = Nothing
MsgBox "Complete!", vbOkOnly, "Create Workbook"