Пример #1
0
 private void BindExportData()
 {
     ArNews objData = new ArNews();
     objData.LoadAll();
     uiGridViewExport.DataSource = objData.DefaultView;
     uiGridViewExport.DataBind();
 }
Пример #2
0
        protected void uiLinkButtonExport_Click(object sender, EventArgs e)
        {
            string filter = "";
            //DataTable dt = new DataTable ();
            ArNews news = new ArNews();
            foreach (GridViewRow row in uiGridViewExport.Rows)
            {

                System.Web.UI.WebControls.CheckBox cb = (System.Web.UI.WebControls.CheckBox)row.FindControl("uiCheckBoxExport");
                if (cb.Checked)
                {
                    if(!string.IsNullOrEmpty(filter))
                        filter += ",";
                    HiddenField hf = (HiddenField)row.FindControl("uiHiddenFieldID");
                    filter += hf.Value;
                }
            }
            news.LoadAll();
            news.Filter = "NewsID in (" + filter + ")";

            if (news.RowCount > 0)
            {
                StringBuilder sbDocBody = new StringBuilder();

                /*object oMissing = System.Reflection.Missing.Value;

                Application oWordApp = new Application();
                Document document = oWordApp.Documents.Add(ref oMissing, ref oMissing, ref oMissing, ref oMissing);
                document.Activate();*/

                int i = 0;
                sbDocBody.Append("<html><body>");
                foreach (DataRowView item in news.DefaultView)
                {

                   /* oWordApp.Selection.TypeText(item["ArTitle"].ToString());
                    oWordApp.Selection.TypeParagraph();
                    oWordApp.Selection.TypeParagraph();

                    oWordApp.Selection.InlineShapes.AddPicture("http://www.globallogistics.mtg-eg.com/" + item["MainPicturePath"].ToString());
                    oWordApp.Selection.TypeParagraph();

                    oWordApp.Selection.TypeText(StripTagsCharArray(Server.HtmlDecode(item["ArBody"].ToString())));
                    oWordApp.Selection.InsertNewPage();*/
                    sbDocBody.Append(item["ArTitle"].ToString());
                    sbDocBody.Append("<br />");
                    sbDocBody.Append("<img src=\'http://www.globallogistics.mtg-eg.com/" + item["MainPicturePath"].ToString() + "\'");
                    sbDocBody.Append("<br />");
                    sbDocBody.Append(Server.HtmlDecode(item["ArBody"].ToString()));
                    sbDocBody.Append("<br />");
                    sbDocBody.Append("<br />");
                    sbDocBody.Append("<hr />");
                    i++;

                }
                sbDocBody.Append("</body></html>");
                /*document.SaveAs(Server.MapPath("~/fileuploads/News.docx"), oMissing, oMissing, oMissing, oMissing, oMissing, oMissing,
                        oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
                document.Close();*/
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.Buffer = true;
                HttpContext.Current.Response.Charset = "utf-8";

                HttpContext.Current.Response.ContentType = "application/msword";
                HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=\"news.doc\"");
                /*HttpContext.Current.Response.TransmitFile("/fileuploads/News.docx");

                HttpContext.Current.Response.Flush();*/
                HttpContext.Current.Response.Write(sbDocBody.ToString());
                HttpContext.Current.Response.End();
               // oWordApp.Application.Quit(ref oMissing, ref oMissing, ref oMissing);
            }
            else
            {

            }
        }