Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
95
Export a graphic (bitmap) to excel
posted

How can I export a bitmap graphic to a spreadsheet?

Parents
No Data
Reply
  • 95
    Suggested Answer
    posted

    never mind I found the answer

     

    using System.Windows.Forms;
    using
    Infragistics.Excel;

    // Create a workbook with a worksheet
    Workbook workbook = new
    Workbook();
    Worksheet worksheet1 = workbook.Worksheets.Add(
    "Sheet1"
    );

    // Create an image shape which can be placed on a worksheet
    Image 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 A1
    imageShape1.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 B2
    imageShape1.BottomRightCornerCell = worksheet1.Rows[ 1 ].Cells[ 1 ]
    ;
    imageShape1.BottomRightCornerPosition =
    new
    PointF( 50, 50 );

    // Create another image shape which can be placed on a worksheet
    Image image2 = Image.FromFile( "C:\\image2.bmp"
    );
    WorksheetImage imageShape2 =
    new
    WorksheetImage( image2 );

    // Get the bounds of cell C3
    Rectangle cellC3Bounds = worksheet1.Rows[ 2 ].Cells[ 2 ]
    .GetBoundsInTwips();

    // Place the second image shape in the same bounds as cell C3
    imageShape2.SetBoundsInTwips( worksheet1, cellC3Bounds );

    // Create a group which will hold both images
    WorksheetShapeGroup group = new
    WorksheetShapeGroup();

    // Place both images in the group
    group.Shapes.Add( imageShape1 );
    group.Shapes.Add( imageShape2 );

    // Place the group on the worksheet
    worksheet1.Shapes.Add( group );

Children