void Page_Load(Object sender, EventArgs e)
{
// Create a new empty workbook and get the first sheet.
SpreadsheetGear.IWorkbook workbook = SpreadsheetGear.Factory.GetWorkbook();
SpreadsheetGear.IWorksheet worksheet = workbook.Worksheets["Sheet1"];
// Get the image file name.
String imageFile = 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.
double width;
double height;
System.Drawing.Image image = System.Drawing.Image.FromFile(imageFile);
using (image)
{
width = image.Width * 72.0 / image.HorizontalResolution;
height = image.Height * 72.0 / image.VerticalResolution;
}
// 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.
SpreadsheetGear.IWorksheetWindowInfo windowInfo = worksheet.WindowInfo;
// Convert from the center of column B to points.
double left = windowInfo.ColumnToPoints(1.5);
// Convert from the center of row 1 to points.
double top = windowInfo.RowToPoints(1.5);
// Add the picture from file.
worksheet.Shapes.AddPicture(imageFile, left, top, width, height);
// Stream the Excel workbook to the client.
Response.Clear();
Response.ContentType = "application/vnd.ms-excel";
workbook.SaveToStream(Response.OutputStream, SpreadsheetGear.FileFormat.Excel8);
Response.End();
}