- word教程零基础教程免费:Word 2007实现自动编排目录
- word变成ppt制作教程:用Word2010来编写博客日志
- word表格教程:word怎么设置页码第几页共几页
- word文档画流程图教程:Word2013如何设置从其他程序粘贴时的格式选项
地址:
在这个控件中,word文档的编辑很好用。但是这里面用到两个方法。word文档和数据库保存的二进制之间的转换问题。
现在将word文档和二进制数据之间相互转换的两个方法总结如下
复制代码代码如下:
/// <summary>
/// 将二进制数据转换为word文档
/// </summary>
/// <param>二进制数据可以直接存放在sql server数据库中的数据</param>
/// <param>文件名,word教程自学,即你要生成的word文档的名称。自己随便定义一个字符串就行</param>
public void ByteConvertWord(byte[] data, string fileName)
{
string savePath = @"/Upload/"; //虚拟路径,word制作表格教程基础入门,WORD上下页,项目中的虚拟路径。一般我们条用这个方法,肯定要把生成的word文档保存在项目的一个文件夹下,以备后续使用
string path = Server.MapPath(savePath); //把相应的虚拟路径转换成物理路径
if (!System.IO.Directory.Exists(path))
{
Directory.CreateDirectory(path);
}
savePath += fileName + DateTime.Now.ToString().Replace("-", "").Replace(" ", "").Replace(":", "") + Guid.NewGuid().ToString() + ".doc";
string filePath = Server.MapPath(savePath);
FileStream fs;
if (System.IO.File.Exists(filePath))
{
fs = new FileStream(filePath, FileMode.Truncate);
}
else
{
fs = new FileStream(filePath, FileMode.CreateNew);
}
BinaryWriter br = new BinaryWriter(fs);
br.Write(data, 0, data.Length);
br.Close();
fs.Close();
}
以下介绍word文档转换为二进制数据的方法。
复制代码代码如下:
/// <summary>
/// word文件转换二进制数据(用于保存数据库)
/// </summary>
/// <param>word文件路径</param>
/// <returns>二进制</returns>
private byte[] wordConvertByte(string wordPath)
{
byte[] bytContent = null;
System.IO.FileStream fs = null;
System.IO.BinaryReader br = null;
try
{
fs = new FileStream(wordPath, System.IO.FileMode.Open);
}
catch
{
}
br = new BinaryReader((Stream)fs);
bytContent = br.ReadBytes((Int32)fs.Length);
return bytContent;
}
上一篇:word教程零基础教程免费:word文档和二进制数据的转换及相关问题探讨 下一篇:word办公软件使用教程:用word发邮件的方法教程
郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。