c#打印报表可自定义表格样式,可分页打印
我是这么打印的,但是没有标题,也不能自定义表格样式private void printDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "server=LUKE\\SQLEXPRESS;uid=sa;pwd=sa;database=luke";
conn.Open();
DataTable dt = new DataTable("resouce");
dt.Clear();
string sql = "";
if (textBox1.Text == "" && textBox2.Text == "")
{
sql = "select * from text1";
label1.Text = sql;
}
else
{
sql = "select * from text1 where bh like '%" + textBox1.Text + "%'";
label1.Text = sql;
}
SqlDataAdapter adp = new SqlDataAdapter(sql, conn);
adp.Fill(dt);
dataGridView1.DataSource = dt.DefaultView;
int r = 0;
int c = 20;
for (int i = 0; i < dt.Rows.Count; i++)
{
for (int j = 0; j < dt.Columns.Count; j++)
{
e.Graphics.DrawString(dt.Rows[i][j].ToString(), new Font("宋体", 72, FontStyle.Regular), Brushes.Black, r, c);
r = r + 160;
}
r = 0;
c += 200;
}
谁能帮帮我