PDA

View Full Version : سوال: مشکل در خروجی گرفتن از گریدویو



پارسامهر
جمعه 23 بهمن 1394, 17:15 عصر
سلام دوستان ...

من یه قطعه کد دارم که گریدویو رو میبره به ورد اما مشکلش اینه که وقتی به ورد فرستاده میشه تو صفحه ورد ستون ها برعکس میشن!! یعنی چپ چین میشن که با ابزار های خود ورد هم درست نمیشه ممنون میشم راهنمایی کنید..
(البته قطعه کد مشابهی برای اکسل هم وجود داره که همین مشکلو داره اما با ابزارهای اکسل این مشکل حل میشه)
کد مربوط به دکمه چاپ ورد


protected void btnWord_Click(object sender, EventArgs e)
{
HtmlForm form = new HtmlForm();
Response.Clear();
Response.Buffer = true;
Response.Charset = "";
Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", "Student.doc"));
Response.ContentType = "application/ms-msword";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView2.AllowPaging = false;




var list = context.Test.AsQueryable();
if (!string.IsNullOrWhiteSpace(pcal1.Text))
{
DateTime D = Convert.ToDateTime(pcal1.Text);
list = list.Where(x => x.TestDate >= D);
}
if (!string.IsNullOrWhiteSpace(pcal2.Text))
{
DateTime E = Convert.ToDateTime(pcal2.Text);
list = list.Where(x => x.TestDate <= E);
}
if (!string.IsNullOrWhiteSpace(txtName.Text))
{
list = list.Where(x => x.TestName == txtName.Text);
}
if (!string.IsNullOrWhiteSpace(txtFamily.Text))
{
list = list.Where(x => x.TestFamily == txtFamily.Text);
}
if (!string.IsNullOrWhiteSpace(txtPassword.Text))
{
list = list.Where(x => x.TestPassword == txtPassword.Text);
}
GridView2.DataSource = list.ToList();
GridView2.DataBind();




form.Attributes["runat"] = "server";
form.Controls.Add(GridView2);
this.Controls.Add(form);
form.RenderControl(hw);
string style = @"<style> .textmode { mso-number-format:'\#,\#\#0\.00';}
.textmode1(mso-number-format:'\@';}
.SSNmode{mso-number-format:'000-00-000';} </style>";


//@"<style> .textmode {mso-number-format:\@;} .direction{rtl} </style>";


Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");


Response.Write(style);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}

پارسامهر
یک شنبه 25 بهمن 1394, 06:22 صبح
آپـــــــــــــــــــــــ ـــــــــــــــــــــــــ ــــــــــــ ...