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);
It looks like you posted an image, but it is not showing. Can you post the stack trace of the exception?
Hello Currie,
This issue is resolved in the latest service release for Infragistics 2013 Volume 2 as of the date of this post. It is also resolved in Infragistics 2014 Volume 1.
Thank you for your response.
I also reproduced the issue when I made the modification you described. I have submitted this issue to our developers and I've created CAS-131957-S4Z5N0 to track the issue.
I have run into this same problem. I downloaded the sample you provided, changed the Format to WorkbookFormat.Excel97to2003, and I get the Null Reference Exception. I tried it with both 13.1 and 13.2. Any suggested workarounds?
Currie
Hello,
I created the attached sample using 12.1, and I do not get any errors. You might want to check that the image actually exists in the folder you're trying to load it from.
Please let me know if my sample helps to resolve this issue.
It's possible a regression has been introduced. I have forwarded this post to the Developer Support Manager and a DS engineer will be contacting you about this issue.