<%@ Page Language="VB" EnableViewState="false" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Excel Report with Picture using ASP.NET and VB.NET - Returns XLS Workbook with picture Using SpreadsheetGear 2010</title>
<meta content="Excel Report with Picture with ASP.NET, Visual Basic .NET and SpreadsheetGear 2010, a royalty free Microsoft Excel compatible spreadsheet component for the Microsoft .NET Framework featuring the fastest and most complete calculation engine available. Create, read, modify, calculate and write Microsoft Excel workbooks from your Microsoft .NET, ASP.NET, C#, VB.NET and Microsoft Office solutions. Integrates with Microsoft Visual Studio .NET, including IntelliSense and Dynamic Help." name="description" />
<script language="VB" runat="server">
Sub Page_Load(sender As Object, e As EventArgs)
' Create a new empty workbook and get the first sheet.
Dim workbook As SpreadsheetGear.IWorkbook = SpreadsheetGear.Factory.GetWorkbook()
Dim worksheet As SpreadsheetGear.IWorksheet = workbook.Worksheets("Sheet1")
' Get the image file name.
Dim imageFile As String = Server.MapPath("files/ssgear.gif")
' Get the width and height of the picture in pixels and convert to
' points for use in the call to AddPicture. This step is only
' necessary if the actual picture size is to be used and that size
' is unknown. Another option is to calculate the width and height
' in row and column coordinates in the same manner as left and top below.
Dim width As Double
Dim height As Double
Dim image As System.Drawing.Image = System.Drawing.Image.FromFile(imageFile)
Try
width = image.Width * 72.0 / image.HorizontalResolution
height = image.Height * 72.0 / image.VerticalResolution
Finally
image.Dispose()
End Try
' Calculate the left and top placement of the picture by converting
' row and column coordinates to points. Use fractional values to
' get coordinates anywhere in between row and column boundaries.
Dim windowInfo As SpreadsheetGear.IWorksheetWindowInfo = worksheet.WindowInfo
Dim left As Double = windowInfo.ColumnToPoints(1.5)
Dim top As Double = windowInfo.RowToPoints(1.5)
' Add the picture from file.
worksheet.Shapes.AddPicture(imageFile, left, top, width, height)
' Stream the Excel spreadsheet to the client in a format
' compatible with Excel 97/2000/XP/2003/2007/2010.
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
</script>
</head>
<body>
</body>
</html>