怎么实现打印报表功能?

解决方案 »

  1.   

    我做过这样的代码你看看!:
    void CECSView::OnPrint(CDC* pDC, CPrintInfo* pInfo) 
    {
    // TODO: Add your specialized code here and/or call the base class
    pDC->SetMapMode(MM_HIMETRIC);
    LOGFONT lf;
    lf.lfHeight=1000;
    lf.lfWidth=0;
    lf.lfEscapement=0;      
    lf.lfOrientation=0;
        lf.lfWeight=FW_NORMAL;//FW_BOLD;//FW_NORMAL;
    lf.lfItalic=FALSE;
    lf.lfUnderline=FALSE;
    lf.lfStrikeOut=FALSE;
    lf.lfCharSet=GB2312_CHARSET;
    lf.lfOutPrecision=OUT_STROKE_PRECIS;
    lf.lfClipPrecision=CLIP_STROKE_PRECIS;
    lf.lfQuality=PROOF_QUALITY;
    lf.lfPitchAndFamily=VARIABLE_PITCH|FF_MODERN;
    strcpy(lf.lfFaceName,"仿宋_GB2312");
    CFont Font;
    CFont * pOldFont;
    Font.CreateFontIndirect(&lf);
    pOldFont=pDC->SelectObject(&Font);

    /////////////////////////////////
    CString str="    蛋品指标检测结果报告";
    CString strTem;
        CString strCaption;
    pDC->TextOut(3000,-2000,str);
    pDC->MoveTo(3000,-3100);
    pDC->LineTo(17000,-3100);
        lf.lfHeight=700;
    lf.lfWidth=0;
    lf.lfEscapement=0;      
    lf.lfOrientation=0;
        lf.lfWeight=FW_NORMAL;//FW_BOLD;//FW_NORMAL;
    lf.lfItalic=FALSE;
    lf.lfUnderline=FALSE;
    lf.lfStrikeOut=FALSE;
    lf.lfCharSet=GB2312_CHARSET;
    lf.lfOutPrecision=OUT_STROKE_PRECIS;
    lf.lfClipPrecision=CLIP_STROKE_PRECIS;
    lf.lfQuality=PROOF_QUALITY;
    lf.lfPitchAndFamily=VARIABLE_PITCH|FF_MODERN;
    strcpy(lf.lfFaceName,"仿宋_GB2312");
    CFont Font1;
    Font1.CreateFontIndirect(&lf);
    pOldFont=pDC->SelectObject(&Font1); CTime t;
    t=CTime::GetCurrentTime();
    str=t.Format("%Y-%m-%d %H:%M:%S");
    str="日期:"+str+"  单位:枚";
    pDC->TextOut(3500,-3300,str); for(int i=1;i<19;i++)
    {
    strTem.Format("%d",INDEX[i]);
    strCaption=GetString(i);
    str=strCaption+":"+strTem;
    pDC->TextOut(2800,-4500-(i-1)*800,str);
    }
    pDC->MoveTo(3000,-20000);
    pDC->LineTo(17000,-20000);
        INDEX[19]=0;
    for(i=1;i<19;i++)
    INDEX[19]+=INDEX[i];
    strTem.Format("%d",INDEX[19]);
    str="总产量";
    str+=(":"+strTem);
    pDC->TextOut(10500,-20700,str);
    str="累计总产量";
    ////////////////////
    strTem.Format("%d",INDEX[20]+INDEX[19]);
    str+=":"+strTem;
    pDC->TextOut(10500,-21700,str); pDC->SelectObject(pOldFont);
    CView::OnPrint(pDC, pInfo);} 希望对你有帮助
      

  2.   

    See the sample below, maybe useful :http://www.codeproject.com/useritems/printchart.asp