欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

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

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

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

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

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

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

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

最新評(píng)論