Vsflexgrid数据已经弄好了,怎么用Vsprint打印,哪位大哥帮忙?

解决方案 »

  1.   

    装一个vsview8.0,安装完毕后看一下他的例子.很详细的,只有几句代码
      

  2.   

    With  vsView1  
                   '设置表头,创建打印文档  
                   .Header  =  "  ¦"  &  strTitle  &  vbCrLf  &  "  ¦Page  %d  "  '显示Page  n功能  
                     
                   .StartDoc  
                   .Zoom  =  100'显示比例  
                   .RenderControl  =  vsFlexGrid1.Hwnd'把网格内容传递给vsView显示  
                   .EndDoc  
           End  With  
     
    ---------------------------------------------------------------  
     
    With  VSPrinter1  
                   '设置表头,创建打印文档  
                   .Header  =  "  ¦"  &  strTitle  &  vbCrLf  &  "  ¦Page  %d  "  '显示Page  n功能  
                     
                   .StartDoc  
                   .Zoom  =  100'显示比例  
                   .RenderControl  =  vsFlexGrid1.Hwnd'把网格内容传递给vsView显示  
                   .EndDoc  
           End  With
      

  3.   

    With frm_Print.vp
           .StartDoc
           .StartTable
           .HdrFontName = "宋体"
           .HdrFontSize = 20
           .HdrFontBold = True
          
           .Header = "|出库汇总表"
           
           .TableCell(tcCols) = Me.Grid1.Cols
           .TableCell(tcRows) = Me.Grid1.Rows
           .TableCell(tcAlign, , 1, , 3) = taCenterMiddle
        
            
           
            
            '设置预览的时候单元格的大小
           For i = 0 To Grid1.Cols - 1
                .TableCell(tcColWidth, , i + 1, , i + 2) = Grid1.ColWidth(i)
           Next i
                .TableCell(tcRowHeight, 0, , 1) = "0.2in"
        
            .TableCell(RowSpan, 2, 0, 3, 0) = 1
           '设置预览的时候单元格中显示的内容
           
           For i = 0 To Me.Grid1.Rows - 1
               For j = 0 To Me.Grid1.Cols - 1
                   .TableCell(tcText, i + 1, j + 1) = Me.Grid1.TextMatrix(i, j)
               Next j
           Next i
        '''                 打印预览的时候把应该合并的合并到一起
            For i = 1 To Grid1.Rows - 1
                If Grid1.TextMatrix(i, 1) = Grid1.TextMatrix(i - 1, 1) Then
                        spanrows = spanrows + 1
                    Else
                        If spanrows <> 1 Then
                          .TableCell(tcRowSpan, i - spanrows + 1, 2) = spanrows
                        End If
                        spanrows = 1
                        
                End If
            Next i
            
            spanrows = 1
            
            For i = 1 To Grid1.Rows - 1
                If Grid1.TextMatrix(i, 0) = Grid1.TextMatrix(i - 1, 0) Then
                        spanrows = spanrows + 1
                    Else
                        If spanrows <> 1 Then
                          .TableCell(tcRowSpan, i - spanrows + 1, 1) = spanrows
                        End If
                        spanrows = 1
                        
                End If        Next i
           .TableBorder = tbAll
           .TableCell(tcBackColor, 1, , 1) = &HC0C0C0
           .TableCell(tcColAlign, , 3, , 3) = taCenterMiddle
           .TableCell(tcColAlign, , 4, , 5) = taRightMiddle
    '       .TableCell(tcText
           
           .EndTable
           .EndDoc
        End With
        With frm_Print