Use ASP to export the data readout of the Excel file

zhaozj2021-02-11  218

Author: tonny from: Wei net power http://www.weiw.com/ For reprint, please specify the source.

Author's order: This type of knowledge, there are a lot on the Internet, which is just a summary.

First, use OWC what is OWC? OWC is the abbreviation of Office Web Compe, namely Microsoft's Office Web Components, which is provided in the web.

Flexible is also the most basic mechanism. In an intranet environment, if you can assume that there is a specific browser and one

Some functional software (such as IE5 and Office 2000), then capable of providing an interactive graphic using the Office Web component

Environment. In this mode, the client workstation will share a lot of proportion in the entire task. Detailed description can also be found on this site. <% Option Explicitclass ExcelgenPrivate Objspreadsheet

Private iColoffset

Private irowoffsetSub class_initialize () set objspreadsheet = server.createObject ("owc.spreadsheet") rowoffset = 2icoloffset = 2END SUB

SUB Class_Terminate () set objspreadsheet = Nothing 'Clean Upend Sub

Public Property Let Columnoffset (ICOLOFF) ICOLOFF> 0 Thenicoloffset = ICOLOFFELSEICOLOFFSET = 2END IFEND Property

Public Property Let RowOffset (iRowOff) If iRowOff> 0 theniRowOffset = iRowOffElseiRowOffset = 2End IfEnd Property Sub GenerateWorksheet (objRS) 'Populates the Excel worksheet based on a Recordset's contents'Start by displaying the titlesIf objRS.EOF then Exit SubDim objField, iCol, iRowiCol = iColOffsetiRow = iRowOffsetFor Each objField in objRS.FieldsobjSpreadsheet.Cells (iRow, iCol) .Value = objField.NameobjSpreadsheet.Columns (iCol) .AutoFitColumns' an Excel table font objSpreadsheet.Cells (iRow, iCol) .Font.Bold = true objSpreadsheet.Cells (iRow, iCol) .Font.Italic = FalseobjSpreadsheet.Cells (iRow, iCol) .Font.Size = 10objSpreadsheet.Cells (iRow, iCol) .Halignment = 2 'centrally iCol = iCol 1Next' objField'Display all of the data Do While Not objRS.EOFiRow = iRow 1iCol = iColOffsetFor Each objField in objRS.FieldsIf IsNull (objField.Value) thenobjSpreadsheet.Cells (iRow, iCol) .Value = "" ElseobjSpreadsheet.Cells (iRow, iCol). Value = objfield.valueObjspreadsheet.columns (icol) .autofitcolumns objspreadsheet.cells (IRow, iCol) .Font.Bold = False objSpreadsheet.Cells (iRow, iCol) .Font.Italic = FalseobjSpreadsheet.Cells (iRow, iCol) .Font.Size = 10 End IfiCol = iCol 1Next 'objFieldobjRS.MoveNext Loop End Sub Function SaveWorksheet (strFileName) 'Save the worksheet to a specified filenameOn Error Resume NextCall objSpreadsheet.ActiveSheet.Export (strFileName, 0) SaveWorksheet = (Err.Number = 0) End FunctionEnd Class

Dim objrsset objrs = server.createObject ("adoDb.recordset") objrs.open "Select * from xxxx", "provider = SQLOLEDB.1; PERSIST Security

Info = True; User ID = xxxx; Password = xxxx; Initial Catalog = xxxx; Data source = xxxx; "Dim SaveNameSaveName = Request.Cookies (" savename ") (" name ") Dim objExcelDim ExcelPathExcelPath =" Excel / "& SaveName & ".xls" Set objExcel = New ExcelGenobjExcel.RowOffset = 1objExcel.ColumnOffset = 1objExcel.GenerateWorksheet (objRS) If objExcel.SaveWorksheet (Server.MapPath (ExcelPath)) then'Response.Write " Saved as Excel file.

Export to Excel code