Example #1
0
    protected void Button2_Click(object sender, EventArgs e)
    {
        Button2.Enabled = false;
        SQLtoWord SW  = new SQLtoWord();
        string    str = " SELECT student_Name, student_ID,Depart,class,AimComplete,time  FROM aimCom WHERE (student_ID ='" + Session["student_ID"].ToString().Trim() + "')";
        DB        db  = new DB();
        DataSet   ds  = db.Select(str, db.DBconn());

        try
        {
            string tex   = ds.Tables[0].Rows[0][0].ToString();//ceshi
            string path1 = Server.MapPath(@"..\\过程文档\\文档模版\\小结表.doc");
            string path2 = Server.MapPath(@"..\\过程文档\\小结表") + "\\" + Session["student_ID"] + Session["student_Name"] + "小结表.doc";

            string[] obDD = new string[6];
            obDD[0] = "student_Name";
            obDD[1] = "student_ID";
            obDD[2] = "Depart";
            obDD[3] = "class";
            obDD[4] = "AimComplete";
            obDD[5] = "time";
            if (SW.ExportToWord(ds, path1, path2, obDD))
            {
                // Response.Write("<script>alert('文档写入成功!')<script>");
                //yi流的方式传送给客户端
                String             filepath = path2;
                System.IO.FileInfo file     = new System.IO.FileInfo(filepath);
                Response.Clear();
                Response.Charset         = "GB2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                // 添加头信息,为"文件下载/另存为"对话框指定默认文件名
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
                // 添加头信息,指定文件大小,让浏览器能够显示下载进度
                Response.AddHeader("Content-Length", file.Length.ToString());

                // 指定返回的是一个不能被客户端读取的流,必须被下载
                Response.ContentType = "application/ms-excel";

                // 把文件流发送到客户端
                Response.WriteFile(file.FullName);
                // 停止页面的执行
                Response.End();
            }
            else
            {
                Response.Write("<script>alert('向word文件中写入数据出错.')</script>");
                return;
            }
        }
        catch
        {
            Response.Write("<script>alert('数据库出错,该同学可能还未填写小结表.')</script>");
            return;
        }
        finally
        {
            ds.Clear();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SQLtoWord SW = new SQLtoWord();

        string str = "select student_ID,name,specialty from student where student_ID='20051308025'";
        DB db = new DB();
        DataSet ds = db.Select(str, db.DBconn());
        try
        {
            string tex = ds.Tables[0].Rows[0][1].ToString();
            string path1 = Server.MapPath(@"1.doc");
            string path2 = Server.MapPath("file") + "\\" + "接收毕业生情况表" + ".doc";
            string[] obDD = new string[3];
            obDD[0] = "t1";
            obDD[1] = "t2";
            obDD[2] = "t3";
            if (SW.ExportToWord(ds, path1, path2, obDD))
            {
               // Response.Write("<script>alert('文档写入成功!')<script>");
                //yi流的方式传送给客户端
                String filepath =path2;
                System.IO.FileInfo file = new System.IO.FileInfo(filepath);
                Response.Clear();
                Response.Charset = "GB2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
                // 添加头信息,指定文件大小,让浏览器能够显示下载进度 
                Response.AddHeader("Content-Length", file.Length.ToString());

                // 指定返回的是一个不能被客户端读取的流,必须被下载 
                Response.ContentType = "application/ms-excel";

                // 把文件流发送到客户端 
                Response.WriteFile(file.FullName);
                // 停止页面的执行 
                Response.End();

            }
            else
            {
                Response.Write("<script>alert('向word文件中写入数据出错.')<script>");
            }
        }
        catch
        {
            Response.Write("<script>alert('数据库出错.')<script>");
        }
        finally
        {
            ds.Clear();

        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        SQLtoWord SW = new SQLtoWord();

        string  str = "select student_ID,name,specialty from student where student_ID='20051308025'";
        DB      db  = new DB();
        DataSet ds  = db.Select(str, db.DBconn());

        try
        {
            string   tex   = ds.Tables[0].Rows[0][1].ToString();
            string   path1 = Server.MapPath(@"1.doc");
            string   path2 = Server.MapPath("file") + "\\" + "接收毕业生情况表" + ".doc";
            string[] obDD  = new string[3];
            obDD[0] = "t1";
            obDD[1] = "t2";
            obDD[2] = "t3";
            if (SW.ExportToWord(ds, path1, path2, obDD))
            {
                // Response.Write("<script>alert('文档写入成功!')<script>");
                //yi流的方式传送给客户端
                String             filepath = path2;
                System.IO.FileInfo file     = new System.IO.FileInfo(filepath);
                Response.Clear();
                Response.Charset         = "GB2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                // 添加头信息,为"文件下载/另存为"对话框指定默认文件名
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
                // 添加头信息,指定文件大小,让浏览器能够显示下载进度
                Response.AddHeader("Content-Length", file.Length.ToString());

                // 指定返回的是一个不能被客户端读取的流,必须被下载
                Response.ContentType = "application/ms-excel";

                // 把文件流发送到客户端
                Response.WriteFile(file.FullName);
                // 停止页面的执行
                Response.End();
            }
            else
            {
                Response.Write("<script>alert('向word文件中写入数据出错.')<script>");
            }
        }
        catch
        {
            Response.Write("<script>alert('数据库出错.')<script>");
        }
        finally
        {
            ds.Clear();
        }
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Button2.Enabled = false;
        SQLtoWord SW = new SQLtoWord();

        //string str = "select student_ID,name,Depart,specify,teacher_Name,title,AimandSense,state,content,schedule,ref from STReport where student_ID='" +Session["student_ID"].ToString().Trim()+ "'";
        string str = " SELECT student_ID, name, Depart, specify, teacher_Name, title, AimandSense, state,  content, schedule, ref FROM STReport WHERE (student_ID ='" + Session["student_ID"].ToString().Trim() + "')";
        DB db = new DB();
        DataSet ds = db.Select(str, db.DBconn());
        try
        {
            string tex = ds.Tables[0].Rows[0][0].ToString();//ceshi 
            string path1 = Server.MapPath(@"..\\过程文档\\文档模版\\开题报告.doc");
            string path2 = Server.MapPath(@"..\\过程文档\\开题报告") + "\\" + Session["student_ID"] + Session["student_Name"] + "开题报告.doc";

            string[] obDD = new string[11];
            obDD[0] = "student_ID";
            obDD[1] = "name";
            obDD[2] = "Depart";
            obDD[3] = "specify";
            obDD[4] = "teacher_Name";
            obDD[5] = "title";
            obDD[6] = "AimandSense";
            obDD[7] = "state";
            obDD[8] = "content";
            obDD[9] = "schedule";
            obDD[10] = "ref";

            if (SW.ExportToWord(ds, path1, path2, obDD))
            {

                // Response.Write("<script>alert('文档写入成功!')<script>");
                //yi流的方式传送给客户端
                String filepath = path2;
                System.IO.FileInfo file = new System.IO.FileInfo(filepath);
                Response.Clear();
                Response.Charset = "GB2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                // 添加头信息,为"文件下载/另存为"对话框指定默认文件名 
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
                // 添加头信息,指定文件大小,让浏览器能够显示下载进度 
                Response.AddHeader("Content-Length", file.Length.ToString());

                // 指定返回的是一个不能被客户端读取的流,必须被下载 
                Response.ContentType = "application/ms-excel";

                // 把文件流发送到客户端 
                Response.WriteFile(file.FullName);
                // 停止页面的执行 
                Response.End();

            }
            else
            {
                Response.Write("<script>alert('向word文件中写入数据出错.')</script>");
                return;
            }

        }
        catch
        {
            Response.Write("<script>alert('数据库出错,该同学可能还未填写开题报告.')</script>");
            return;
        }
        finally
        {
            ds.Clear();
            Button2.Enabled = true;
        }
       
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        Button2.Enabled = false;
        SQLtoWord SW = new SQLtoWord();

        //string str = "select student_ID,name,Depart,specify,teacher_Name,title,AimandSense,state,content,schedule,ref from STReport where student_ID='" +Session["student_ID"].ToString().Trim()+ "'";
        string  str = " SELECT guimark, time  FROM guiMark WHERE (student_ID ='" + Session["student_ID"].ToString().Trim() + "')";
        DB      db  = new DB();
        DataSet ds  = db.Select(str, db.DBconn());

        try
        {
            string tex   = ds.Tables[0].Rows[0][0].ToString();//ceshi
            string path1 = Server.MapPath(@"..\\过程文档\\文档模版\\指导记录.doc");
            string path2 = Server.MapPath(@"..\\过程文档\\指导记录") + "\\" + Session["student_ID"] + this.Label2.Text + "指导记录.doc";

            string[] obDD = new string[16];
            obDD[0]  = "guide1";
            obDD[1]  = "date1";
            obDD[2]  = "guide2";
            obDD[3]  = "date2";
            obDD[4]  = "guide3";
            obDD[5]  = "date3";
            obDD[6]  = "guide4";
            obDD[7]  = "date4";
            obDD[8]  = "guide5";
            obDD[9]  = "date5";
            obDD[10] = "guide6";
            obDD[11] = "date6";
            obDD[12] = "guide7";
            obDD[13] = "date7";
            obDD[14] = "guide8";
            obDD[15] = "date8";
            if (SW.ExportToWord(ds, path1, path2, obDD))
            {
                // Response.Write("<script>alert('文档写入成功!')<script>");
                //yi流的方式传送给客户端
                String             filepath = path2;
                System.IO.FileInfo file     = new System.IO.FileInfo(filepath);
                Response.Clear();
                Response.Charset         = "GB2312";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                // 添加头信息,为"文件下载/另存为"对话框指定默认文件名
                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(file.Name));
                // 添加头信息,指定文件大小,让浏览器能够显示下载进度
                Response.AddHeader("Content-Length", file.Length.ToString());

                // 指定返回的是一个不能被客户端读取的流,必须被下载
                Response.ContentType = "application/ms-excel";

                // 把文件流发送到客户端
                Response.WriteFile(file.FullName);
                // 停止页面的执行
                Response.End();
            }
            else
            {
                Response.Write("<script>alert('向word文件中写入数据出错.')</script>");
            }
        }
        catch
        {
            Response.Write("<script>alert('数据库出错,该同学可能还未填写指导记录.')</script>");
        }
        finally
        {
            ds.Clear();
            Button2.Enabled = true;
        }
    }