将数据从存储过程复制到MS-Word

时间:2015-05-19 07:28:59

标签: c# sql asp.net

我有一个存储过程。我想以表格格式将数据从存储过程复制到MS-Word。我在下面链接中提到它。 http://www.webcodeexpert.com/2013/06/how-to-bind-and-export-gridview-data-to.html 但我想在不使用GridView绑定的情况下复制数据。 有可能吗?

                    strlocBankFilename = "Payment.docx";
                    Response.ClearContent();
                    Response.ClearHeaders();
                    Response.Buffer = true;
                    Response.Charset = "";
                    Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";



        StreamWriter outputFile1 = new StreamWriter(strlocBankFilename, true);
                    HtmlTextWriter htw = new HtmlTextWriter(outputFile1);
                    DataGrid dg = new DataGrid();
                    dg.DataSource = ds.Tables[0];
                    dg.DataBind();
                    dg.RenderControl(htw);

                    DataGrid dg1 = new DataGrid();
                    DataTable dt1 = ds.Tables[1];
                    dt1.Columns[0].ColumnName = dt1.Rows[0][0].ToString();
                    dt1.Rows.RemoveAt(0);
                    dg1.DataSource = dt1;
                    dg1.DataBind();
                    dg1.RenderControl(htw);
                    string strlocReplace = "";
                    // strlocReplace = outputFile.ToString();
                    htw.Close();
                    using (StreamReader sr = new StreamReader(strlocBankFilename))
                    {
                        String line = sr.ReadToEnd();
                        strlocReplace += line;
                    }

0 个答案:

没有答案