How can I export a bitmap graphic to a spreadsheet?
never mind I found the answer
using System.Windows.Forms;using Infragistics.Excel;// Create a workbook with a worksheetWorkbook workbook = new Workbook();Worksheet worksheet1 = workbook.Worksheets.Add( "Sheet1" );// Create an image shape which can be placed on a worksheetImage image1 = Image.FromFile( "C:\\image1.bmp" );WorksheetImage imageShape1 = new WorksheetImage( image1 );// The top-left corner of the image shape will be in the middle of cell A1imageShape1.TopLeftCornerCell = worksheet1.Rows[ 0 ].Cells[ 0 ];imageShape1.TopLeftCornerPosition = new PointF( 50, 50 );// The bottom-right corner of the image shape will be in the middle of cell B2imageShape1.BottomRightCornerCell = worksheet1.Rows[ 1 ].Cells[ 1 ];imageShape1.BottomRightCornerPosition = new PointF( 50, 50 );// Create another image shape which can be placed on a worksheetImage image2 = Image.FromFile( "C:\\image2.bmp" );WorksheetImage imageShape2 = new WorksheetImage( image2 );// Get the bounds of cell C3Rectangle cellC3Bounds = worksheet1.Rows[ 2 ].Cells[ 2 ].GetBoundsInTwips();// Place the second image shape in the same bounds as cell C3imageShape2.SetBoundsInTwips( worksheet1, cellC3Bounds );// Create a group which will hold both imagesWorksheetShapeGroup group = new WorksheetShapeGroup();// Place both images in the groupgroup.Shapes.Add( imageShape1 );group.Shapes.Add( imageShape2 );// Place the group on the worksheetworksheet1.Shapes.Add( group );
I implemented like this, but on Save I get an error (object reference not set)
WorksheetImage wsImage = new WorksheetImage(Image.FromFile(Application.StartupPath + "\\Logo.png")); wsImage.PositioningMode = ShapePositioningMode.MoveWithCells; wsImage.TopLeftCornerCell = wsInfo.Rows[0].Cells[1]; wsImage.TopLeftCornerPosition = new PointF(90, 0); wsImage.BottomRightCornerCell = wsInfo.Rows[1].Cells[2]; wsImage.BottomRightCornerPosition = new PointF(0, 0); WorksheetShapeGroup group = new WorksheetShapeGroup(); group.Shapes.Add(wsImage); wsInfo.Shapes.Add(group); wb.Save(fileName);
Hi Ralmon.
I'm facing same problem as well. May i know, what is your Infragistics version you using for this codes?
Thanks for your answer in advance.
Adi.