0
خروجی اطلاعات یک صفحه وب در Word
باسلام احترام
من یک صفحه وب ASP.NET دارم که بر روی آن یک دکمه هست و با زدن دکمه محتوای یک DataTable در خروجی و در قالب یک فایل Word انجام میشه.
من از کد زیر استفاده می کنم
Dim table1 As New DataTable
HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache)
HttpContext.Current.Response.Clear()
HttpContext.Current.Response.Buffer = True
HttpContext.Current.Response.Charset = "UTF-8"
HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8
HttpContext.Current.Response.AddHeader("Content-Disposition", "attachment;filename=NameTast.doc")
HttpContext.Current.Response.ContentType = "application/vnd.ms-word"
Dim stringWrite As System.IO.StringWriter = New System.IO.StringWriter
Dim htmlWrite As System.Web.UI.HtmlTextWriter = New HtmlTextWriter(stringWrite)
Dim grdExcel As DataGrid = New DataGrid
grdExcel.AllowPaging = False
grdExcel.DataSource = table1
grdExcel.DataBind()
For Each i As DataGridItem In grdExcel.Items
For Each tc As TableCell In i.Cells
tc.Attributes.Add("class", "text")
Next
Next
grdExcel.RenderControl(htmlWrite)
Dim style As String = "<style> .text { mso-number-format:\@; } </style> "
HttpContext.Current.Response.Write(style)
HttpContext.Current.Response.Write(stringWrite.ToString)
HttpContext.Current.Response.Flush()
HttpContext.Current.Response.End()
مشکل من حالا اینجاست که در خروجی فایل word فقط یک جدول با چند سطر و ستون هست ولی من می خواهم مثلا در بالای جدول یک توضیحی را نیز بنویسم و در زیر جدول نیز متنی را درج کنم. باید چه تغییر ی در این کد انجام بدهم.(آیا می شود این متن مورد نظر را در قالب یک کد HTML بدهم که قالبهایی مثل رنگ و سایز هم بگیره)
با تشکر
2 پاسخ
0
با کمال سپاس از شما دوست عزیز
1
با سلام
قبل از کد زیر
HttpContext.Current.Response.Write(stringWrite.ToString)
کد زیر رو قرار بدین :
HttpContext.Current.Response.Write("Your text goes here")