Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) ' Create a new workbook. Dim workbook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook() Dim worksheet As SpreadsheetGear.IWorksheet = workbook.Worksheets("Sheet1") Dim cells As SpreadsheetGear.IRange = worksheet.Cells ' Set the worksheet name. worksheet.Name = "2005 Sales" ' Load column titles and center. cells("B1").Formula = "North" cells("C1").Formula = "South" cells("D1").Formula = "East" cells("E1").Formula = "West" cells("B1:E1").HorizontalAlignment = SpreadsheetGear.HAlign.Center ' Load row titles using multiple cell text reference and iteration. Dim quarter As Integer = 1 Dim cell As SpreadsheetGear.IRange For Each cell In cells("A2:A5") cell.Formula = "Q" & quarter quarter = quarter + 1 Next cell ' Load random data and format as $ using a multiple cell range. Dim body As SpreadsheetGear.IRange = cells(1, 1, 4, 4) body.Formula = "=RAND() * 10000" body.NumberFormat = "$#,##0_);($#,##0)" ' Stream the Excel spreadsheet to the client in a format ' compatible with Excel 97/2000/XP/2003/2007. Response.Clear() Response.ContentType = "application/vnd.ms-excel" Response.AddHeader("Content-Disposition", "attachment; filename=report.xls") workbook.SaveToStream(Response.OutputStream, SpreadsheetGear.FileFormat.XLS97) Response.End() End Sub 'Page_Load
Post a Comment