注册 登录
编程论坛 C# 论坛

c#打印报表可自定义表格样式,可分页打印

lukebc 发布于 2016-09-12 16:01, 2325 次点击
我是这么打印的,但是没有标题,也不能自定义表格样式
 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;

            }

谁能帮帮我
1 回复
#2
yhlvht2016-09-12 20:26
都使用Graphics绘图了,绘数据之前自己绘制标题啊,样式也可以随意绘制啊,只是使用者不能自己定义,你可以预设几种样式让用户选择嘛
1