正团级是什么行政级别:.net 在打印中怎么以表格的形式打印出来,谁知道请帮帮忙!谢谢了!

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/29 04:02:35

那就以Excel格式输出好了哇,要在项目上面,添加引用;然后在窗体上加个按钮.click,将文件以Excel格式导出后再打印就行了哇
Private Sub MenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem18.Click
'一个Excel 工作表数个对象所构成的阶层架构
'从Application 到Workbook 再到 Worksheet
Dim excelApp As New Excel.Application
Dim excelBook As Excel.Workbook = excelApp.Workbooks.Add
Dim excelWorksheet As Excel.Worksheet = _
CType(excelBook.Worksheets(1), Excel.Worksheet)

Try '取得当前激活的窗体
Dim activeform As Form = Me.ActiveMdiChild
Dim activeformname As String = activeform.Name
'判断有没有打开的窗体
If activeform Is Nothing Then
MsgBox("没有要导出的文件!请先打开你要导出的窗体!")
Else
'使Excel 显示出来
excelApp.Visible = True
If activeformname.Equals("Customer") Then
Dim f As frmCustomer = CType(activeform, frmCustomer)
Dim ds As DataSet
ds = f.DataSet11
With excelWorksheet
'设定栏标题与所需的格式
.Columns().ColumnWidth = 21.71
.Range("A1").Value = "客户ID"
.Range("A1").Font.Bold = True
.Range("B1").Value = "客户名"
.Range("B1").Font.Bold = True
.Range("C1").Value = "客户姓"
.Range("C1").Font.Bold = True
.Range("D1").Value = "地址"
.Range("D1").Font.Bold = True
.Range("E1").Value = "电话"
.Range("E1").Font.Bold = True
.Range("F1").Value = "邮件"
.Range("F1").Font.Bold = True
Dim i As Integer = 2
'循环处理 DataSet 的 Rows 集合并将每一列
'的数据写至 Excel 中 单元
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows
.Range("A" & i.ToString).Value = dr("CustID")
.Range("B" & i.ToString).Value = dr("FName")
.Range("C" & i.ToString).Value = dr("LName")
.Range("D" & i.ToString).Value = dr("Address")
.Range("E" & i.ToString).Value = dr("Phone")
.Range("F" & i.ToString).Value = dr("email")
i += 1
Next
End With
End If
If activeformname.Equals("frmProduct") Then
Dim f As frmProduct = CType(activeform, frmProduct)
Dim ds As DataSet
ds = f.DataSet41
With excelWorksheet
'设定栏标题与所需的格式
.Columns().ColumnWidth = 21.71
.Range("A1").Value = "产品ID"
.Range("A1").Font.Bold = True
.Range("B1").Value = "产品名称"
.Range("B1").Font.Bold = True
.Range("C1").Value = "产品价格"
.Range("C1").Font.Bold = True
Dim i As Integer = 2
'循环处理 DataSet 的 Rows 集合并将每一列
'的数据写至 Excel 中 单元
Dim dr As DataRow
For Each dr In ds.Tables(0).Rows
.Range("A" & i.ToString).Value = dr("ProdID")
.Range("B" & i.ToString).Value = dr("ProdName")
.Range("C" & i.ToString).Value = dr("Base_Cost")
i += 1
Next
End With
End If
End If
Catch ex As Exception
MsgBox(ex.Message & Chr(10) & ex.StackTrace, MsgBoxStyle.OKOnly, "导出文件出错问题")
End Try
End Sub