最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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文檔的名稱(chēng)。自己隨便定義一個(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)論

平山县| 辽宁省| 舟曲县| 云龙县| 丹阳市| 鄂托克旗| 临沂市| 仙游县| 开江县| 五指山市| 陕西省| 康乐县| 桑植县| 定南县| 西城区| 博罗县| 鹤岗市| 东光县| 凯里市| 江安县| 行唐县| 利津县| 淳化县| 陈巴尔虎旗| 石台县| 宕昌县| 连州市| 威海市| 陆川县| 吉木乃县| 铜鼓县| 清镇市| 平遥县| 慈溪市| 泸州市| 萨嘎县| 乾安县| 佳木斯市| 安丘市| 宿州市| 安溪县|