如何将字节码写入word文件 [英] How to write byte code into word file
本文介绍了如何将字节码写入word文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,它将字节代码转换为原始字符串,并且它在普通的HTML页面中完美地工作,
string sql1 =SELECT Package FROM Package WHERE ID ='' 1 '';
SqlConnection con1 = new SqlConnection(cls.GetConnectionString());
SqlCommand cmd1 = new SqlCommand(sql1,con);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataTable dt1 = new DataTable();
da1.Fill(dt1);
dt1.Columns.Add(Description);
foreach(dt1.Rows中的DataRow dr1)
{
if(dr1!= null)
{
byte [] byt1 =(byte [])dr1 [ 0];
string str1;
System.Text.ASCIIEncoding enc1 = new System.Text.ASCIIEncoding();
str1 = enc1.GetString(byt1);
dr1 [1] = str1;
description = str1;
}
}
但我想以下列方式将此字符串写入word文件
public void CreateWordFile(DataTable dt)
{
Response.Clear();
Response.Buffer = true;
Response.AddHeader(content-disposition,attachment; filename = Publish.doc);
Response.Charset =;
Response.ContentType =application / vnd.ms-word;
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
GridView gvTemp = new GridView();
gvTemp.AllowPaging = false;
gvTemp.DataSource = dt;
gvTemp.DataBind();
gvTemp.RenderControl(hw);
Response.Output.Write(sw.ToString());
Response.Flush();
Response.End();
}
现在这里输出
< p 样式 = margin:0px; text-align: center; > 标题< / p > < p style = margin:0px; text-align:center; > 颜色 < span style = color:#ff0000; > 红色< / span > < / p > < br / > < p style = margin:0px; text-align:center; > 标题< / p >
< 表 width = 100% cellspacing = 1 border = 0 id = table1 > < tbody > < tr > < td > < p align = center > TITLE < / p > < / td > < td width = < span class =code-keyword> 9 > & nbsp; < span class =code-keyword>< / td > < / tr > < tr > < td width = 11 > & nbsp; < / td > < td > & nbsp; < / td > < td width = 9 > & nbsp; < / td > < / tr > < tr > < span class =code-keyword>< td width = 11 > & nbsp; < / td > < td > < p align = 对齐 > < b > 说明< / b > < br / > 详细信息&。< / p > < / td > ; < td width = 9 > & nbsp; < / td > < / tr > < tr > < td width = 11 > & nbsp; < / td > < td > & nbsp; < / td > < td width = 9 > & nbsp; < / td > < / tr > < tr > < < span class =code-leadattribute> td width = 11 > & nbsp; < / td > < / tr > ; < / tbody > < / table >
> < span < span class =code-attribute> style = font-weight:bold; > 颜色< / span > < / p > < span 样式 = font-weight:bold; > & nbsp;& nbsp;& nbsp;& nbsp;& NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP; &安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP; &安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;&安培; NBSP;页脚< / span >
所以请指导我如何在一个单词上面发表这个file?
解决方案
我希望您尝试从dataTable的内容创建一个word文件。
我建议你有一个看一下这篇文章
创建单词-document-using-c [ ^ ]
WordFromDotNet [ ^ ]
通过传递包含图像的数据集创建Word文档 [ ^ ]
Here is my code which converts Byte code to original string and it works in normal HTML page perfectly,
string sql1 = "SELECT Package FROM Package WHERE ID=''1''"; SqlConnection con1 = new SqlConnection(cls.GetConnectionString()); SqlCommand cmd1 = new SqlCommand(sql1, con); SqlDataAdapter da1 = new SqlDataAdapter(cmd1); DataTable dt1 = new DataTable(); da1.Fill(dt1); dt1.Columns.Add("Description"); foreach (DataRow dr1 in dt1.Rows) { if (dr1 != null) { byte[] byt1 = (byte[])dr1[0]; string str1; System.Text.ASCIIEncoding enc1 = new System.Text.ASCIIEncoding(); str1 = enc1.GetString(byt1); dr1[1] = str1; description = str1; } }
But i want to write this string into word file in the following way
public void CreateWordFile(DataTable dt) { Response.Clear(); Response.Buffer = true; Response.AddHeader("content-disposition", "attachment;filename=Publish.doc"); Response.Charset = ""; Response.ContentType = "application/vnd.ms-word "; StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); GridView gvTemp = new GridView(); gvTemp.AllowPaging = false; gvTemp.DataSource = dt; gvTemp.DataBind(); gvTemp.RenderControl(hw); Response.Output.Write(sw.ToString()); Response.Flush(); Response.End(); }
Now here is output
<p style="margin: 0px; text-align: center;">Header</p> <p style="margin: 0px; text-align: center;">Color <span style="color: #ff0000;">Red</span></p><br /> <p style="margin: 0px; text-align: center;">Heading</p>
<table width="100%" cellspacing="1" border="0" id="table1"> <tbody> <tr> <td> <p align="center">TITLE</p></td> <td width="9"> </td></tr> <tr> <td width="11"> </td> <td> </td> <td width="9"> </td></tr> <tr> <td width="11"> </td> <td> <p align="justify"><b>Description</b><br /> Details &.</p></td> <td width="9"> </td></tr> <tr> <td width="11"> </td> <td> </td> <td width="9"> </td></tr> <tr> <td width="11"> </td> </tr></tbody></table>
><span style="font-weight: bold;">Color</span></p><span style="font-weight: bold;"> Footer</span>
So please guide me how to publish this above in a word file?
解决方案
I hope you are trying to create a word file from the content of a dataTable.
I suggest you to have a look at some of this articles
creating-word-document-using-c[^]
WordFromDotNet[^]
Creating a Word Document by Passing the Dataset including Image(s)[^]
这篇关于如何将字节码写入word文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文