Printing a Spread Sheet embedded in a Windows Form 
Author Message
 Printing a Spread Sheet embedded in a Windows Form

Hello MadhanMohan,

I am afraid there is not a very easy way to print a Spread Sheet control.
You may implement this function with the steps below:

1.      Import the BitBlt API function
2.      Capture the image of the DataGrid
3.      Draw the image in the PrintPage event

However, you can only capture the visible are of the Spread Sheet control,
unless you put it a large enough container. If the Spread Sheet is too
large, you also have to separate it in multi pages in the PrintPage event.

This is a sample code:

private static extern bool BitBlt(
        IntPtr hdcDest, // handle to destination DC
        int nXDest, // x-coord of destination upper-left corner
        int nYDest, // y-coord of destination upper-left corner
        int nWidth, // width of destination rectangle
        int nHeight, // height of destination rectangle
        IntPtr hdcSrc, // handle to source DC
        int nXSrc, // x-coordinate of source upper-left corner
        int nYSrc, // y-coordinate of source upper-left corner
        System.Int32 dwRop // raster operation code

private const Int32 SRCCOPY = 0xCC0020;

private Bitmap memImage;

private void PrepareImage()
        Graphics graphic = axSpreadsheet1.CreateGraphics();
        Size s = this.Size;
        memImage = new Bitmap(s.Width, s.Height, graphic);
        Graphics memGraphic = Graphics.FromImage(memImage);
        IntPtr dc1 = graphic.GetHdc();
        IntPtr dc2 = memGraphic.GetHdc();
        BitBlt(dc2, 0, 0, dataGrid1.ClientRectangle.Width,
dataGrid1.ClientRectangle.Height,dc1, 0, 0, SRCCOPY);


private void button1_Click(object sender, System.EventArgs e)


private void printDocument1_PrintPage(object sender,
System.Drawing.Printing.PrintPageEventArgs e)


I hope this helps you.

Best regards,

Lion Shi [MS}
Microsoft Support Engineer

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use.  2001 Microsoft Corporation. All rights
    Content-Class: urn:content-classes:message

    Subject: Printing a Spread Sheet embedded in a Windows Form
    Date: Tue, 17 Sep 2002 04:12:49 -0700
    Lines: 9

    MIME-Version: 1.0
    Content-Type: text/plain;
    Content-Transfer-Encoding: 7bit
    X-Newsreader: Microsoft CDO for Windows 2000
    Thread-Index: AcJeOyhI5JFJM+eQSmecCo+WxtAT/w==
    X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
    Newsgroups: microsoft.public.dotnet.languages.CSharp
    Path: cpmsftngxa07
    Xref: cpmsftngxa07 microsoft.public.dotnet.languages.csharp:5215
    NNTP-Posting-Host: TKMSFTNGXA14
    X-Tomcat-NG: microsoft.public.dotnet.languages.csharp

    hai friends,
       i used the Microsoft Office Spread sheet component in a
    windows form. i loaded some data into the sheet. how can i
    print that spread sheet alone. please help me in this
    thanks in advance

Mon, 07 Mar 2005 11:59:53 GMT  
 [ 1 post ] 

 Relevant Pages 

1. Help with positioning a embedded property sheet in a form view

2. Printing offset in C# with windows forms printing

3. Microsoft Spread Sheet help?

4. Looking for simple spread sheet entry utilities on VC++

5. Excel Automation - Insert Row to Spread Sheet ?

6. Q: How to write into Excel spread sheet?

7. Spread sheet and ListCtrl

8. Embedding windows forms in a web page

9. Embed PowerPoint 2000 viewer into windows form

10. linking an Excel sheet in Windows Forms

11. How do I print a windows form using c#.NET

12. printing windows forms


Powered by phpBB® Forum Software