Skip to main content Skip to footer

Import Images from Excel into Spread

Spread has several CellTypes that allow you to enter variety of data into the Spread cells including text, numbers, checkboxes, comboboxes and even images. Please refer to the following link that describes the same: http://helpcentral.componentone.com/NetHelp/SpreadNet6/WF/webframe.html#spwin-setcelltypes.html ImageCellType is used to load an image into the Spread cell. The following link describes the usage of ImageCellType: http://helpcentral.componentone.com/NetHelp/SpreadNet6/WF/spwin-setimagecell.html Sometimes, the user would want to export the Spread sheet with images to Excel. This can be done using the SaveExcel() method. Later, when the same excel file is imported back to Spread, all the images in the Spread cell are imported as shapes. When the images are imported as shapes, they are not exactly placed in the cells. They rather float on the drawing layer over the Spread sheet. You would need to reset these images in the Spread cell so as to have the effect similar to that of ImageCelltype. This blog discusses how the images imported as shapes can be reset in the cells. The shapes are held in the ContainedObjects collection of the Drawing Container. You would need to loop through the collection to get each shape. Each shape in the collection is basically a PSObject; the BackgroundImage property of this object gets you the image that the shape currently represents. You can fetch this image and load it back in the cell. Once all the shapes are rendered back as images, you must clear the shapes collection of the sheet to avoid any ambiguity.


private void Button3_Click(object sender, EventArgs e)  
{  
  int i = 0;  
  foreach (FarPoint.Win.Spread.DrawingSpace.PSObject ps in FpSpread1.Sheets[0].DrawingContainer.ContainedObjects)  
  {  
    if (ps.BackgroundImage.Image != null)  
     {  
       FarPoint.Win.Spread.CellType.ImageCellType imgct = new FarPoint.Win.Spread.CellType.ImageCellType();  
       imgct.Style = FarPoint.Win.RenderStyle.Stretch;  
       FpSpread1.ActiveSheet.Cells[ i , 0].CellType = imgct;  
       FpSpread1.ActiveSheet.Cells[ i , 0].Value = ps.BackgroundImage.Image;  
       i = i + 1;  
     }  
   }  
   FpSpread1.ActiveSheet.ClearShapes();  
}  

Refer to the attached samples for detailed implementation. Download C# Sample Download VB Sample

MESCIUS inc.

comments powered by Disqus