您需要添加PrintPage
事件:
myDocument.DocumentName = "Test2015";
myDocument.PrintPage += myDocument_PrintPage;
,你需要编写它!在其非常简单的形式,这将dump出来的数据:
void myDocument_PrintPage(object sender, PrintPageEventArgs e)
{
foreach(DataGridViewRow row in dataGridView1.Rows)
foreach(DataGridViewCell cell in row.Cells)
{
if (Cell.Value != null)
e.Graphics.DrawString(cell.Value.ToString(), Font, Brushes.Black,
new Point(cell.ColumnIndex * 123, cell.RowIndex * 12));
}
}
但是,当然,你将要增添了不少获得不错的格式化等。
也是值得考虑的是设置Unit
的东西与设备无关的像mm
:
e.Graphics.PageUnit = GraphicsUnit.Millimeter;
而且,如果需要的话,你应该跟踪的垂直位置的,所以你可以添加页码和认识,当页面已满!
更新:由于您的DGV
可能包含空单元格我添加了一个支票null
。
来源
2015-02-08 08:09:21
TaW
您的问题解决了吗? – TaW 2015-02-12 15:28:24