亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

word文檔和二進制數(shù)據(jù)的轉(zhuǎn)換及相關(guān)問題探討

  發(fā)布時間:2013-01-31 14:50:31   作者:佚名   我要評論
現(xiàn)在很多項目和技術(shù)支持在線編輯word文檔,接下來介紹將word文檔和二進制數(shù)據(jù)之間相互轉(zhuǎn)換的兩個方法總結(jié)如下,感興趣的朋友可以了解下啊,或許對你有所幫助
現(xiàn)在很多項目和技術(shù)支持在線編輯word文檔。有控件的和javascript操作的。這里簡單的推薦一個在線編輯word文檔的控件。
地址:http://www.dianju.cn/p/weboffice/
在這個控件中,word文檔的編輯很好用。但是這里面用到兩個方法。word文檔和數(shù)據(jù)庫保存的二進制之間的轉(zhuǎn)換問題。

現(xiàn)在將word文檔和二進制數(shù)據(jù)之間相互轉(zhuǎn)換的兩個方法總結(jié)如下

復(fù)制代碼
代碼如下:

/// <summary>
/// 將二進制數(shù)據(jù)轉(zhuǎn)換為word文檔
/// </summary>
/// <param name="data">二進制數(shù)據(jù)可以直接存放在sql server數(shù)據(jù)庫中的數(shù)據(jù)</param>
/// <param name="fileName">文件名,即你要生成的word文檔的名稱。自己隨便定義一個字符串就行</param>
public void ByteConvertWord(byte[] data, string fileName)
{
string savePath = @"/Upload/"; //虛擬路徑,項目中的虛擬路徑。一般我們條用這個方法,肯定要把生成的word文檔保存在項目的一個文件夾下,以備后續(xù)使用
string path = Server.MapPath(savePath); //把相應(yīng)的虛擬路徑轉(zhuǎn)換成物理路徑
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文檔轉(zhuǎn)換為二進制數(shù)據(jù)的方法。

復(fù)制代碼
代碼如下:

/// <summary>
/// word文件轉(zhuǎn)換二進制數(shù)據(jù)(用于保存數(shù)據(jù)庫)
/// </summary>
/// <param name="wordPath">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;
}

相關(guān)文章

最新評論