先导出为excel,然后再打印呗。 有 vb.net的代码,自己上 http://labs.developerfusion.co.uk/convert/vb-to-csharp.aspx 转一下。Try Dim xlApp As New Excel.Application Dim xlBook As Excel.Workbook xlBook = xlApp.Workbooks.Add(True) Dim rowIndex As Integer = 1 Dim colIndex As Integer = 0 For colIndex = 0 To DataGridView1.Columns.Count - 1 xlApp.Cells(1, colIndex + 1) = DataGridView1.Columns(colIndex).HeaderCell.Value Next For rowIndex = 1 To DataGridView1.Rows.Count - 1 For colIndex = 0 To DataGridView1.Columns.Count - 1 xlApp.Cells(rowIndex + 1, colIndex + 1) = DataGridView1.Rows(rowIndex - 1).Cells(colIndex).Value.ToString Next Next xlApp.Visible = True xlBook = Nothing xlApp = Nothing Me.WindowState = FormWindowState.Minimized Catch ex As Exception MsgBox("导出excle失败!" & ex.ToString().Trim(), MsgBoxStyle.Exclamation, "系统提示: ") End Try
Dim xlApp As New Excel.Application
Dim xlBook As Excel.Workbook
xlBook = xlApp.Workbooks.Add(True)
Dim rowIndex As Integer = 1
Dim colIndex As Integer = 0 For colIndex = 0 To DataGridView1.Columns.Count - 1
xlApp.Cells(1, colIndex + 1) = DataGridView1.Columns(colIndex).HeaderCell.Value
Next For rowIndex = 1 To DataGridView1.Rows.Count - 1
For colIndex = 0 To DataGridView1.Columns.Count - 1
xlApp.Cells(rowIndex + 1, colIndex + 1) = DataGridView1.Rows(rowIndex - 1).Cells(colIndex).Value.ToString
Next
Next
xlApp.Visible = True xlBook = Nothing
xlApp = Nothing
Me.WindowState = FormWindowState.Minimized Catch ex As Exception
MsgBox("导出excle失败!" & ex.ToString().Trim(), MsgBoxStyle.Exclamation, "系统提示: ") End Try