Spread for ASP.Net supports displaying images in it's cell. There are scenarios, where the end-user (not the programmer), would like to load some image, and display the same in a Spread Cell. In this article, I am going to share information on how to allow your end users to set image inside a Spread cell dynamically. Uploading an image to a Spread cell is as simple as loading it for an image control. You may place your image under a folder on a Server and set the URL for image cell on Spread sheet to that folder. Here is a step by step guide to help you achieve this:
DirectoryInfo di = new DirectoryInfo(Server.MapPath("img"));
FileInfo[] rgFiles = di.GetFiles("*.jpg");
foreach (FileInfo fi in rgFiles)
{
fi.Delete();
}
// Check whether file upload control has a file
if (FileUpload1.HasFile)
{
//check whether the selected file is a .jpg image file
if (FileUpload1.PostedFile.ContentType == "image/jpg")
{
//limit the image file size in bytes.
if (FileUpload1.PostedFile.ContentLength < 102400)
{
//upload the file to "img" folder
string filename = Server.MapPath("img") + "\\\" + Path.GetFileName(FileUpload1.FileName);
// save the file to "img" folder
FileUpload1.SaveAs(filename);
// create an ImageCellType object
FarPoint.Web.Spread.ImageCellType img = new FarPoint.Web.Spread.ImageCellType();
// set the ImageUrl property for ImageCellType object to the uploaded file in "img" folder
img.ImageUrl = "img/" + FileUpload1.FileName;
// set the celltype for Spread sheet's cell(0,0) to image cell type
FpSpread1.ActiveSheetView.Cells[0, 0].CellType = img;
}
}
}
You may download the samples in VB.Net and C# to test at your end. Run the attached project after extracting and upload any Jpeg image from your machine to Spread cell. Download Sample VB.Net Download Sample C#