国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 辦公 > Word > 正文

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

2019-12-13 15:02:37
字體:
供稿:網(wǎng)友
現(xiàn)在很多項(xiàng)目和技術(shù)支持在線編輯word文檔。有控件的和javascript操作的。這里簡單的推薦一個(gè)在線編輯word文檔的控件。
地址:http://www.dianju.cn/p/weboffice/
在這個(gè)控件中,word文檔的編輯很好用。但是這里面用到兩個(gè)方法。word文檔和數(shù)據(jù)庫保存的二進(jìn)制之間的轉(zhuǎ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ù)庫中的數(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ù)庫)
/// </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;
}
發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 阳城县| 丹江口市| 通辽市| 巴中市| 沙坪坝区| 鹤峰县| 墨江| 五大连池市| 调兵山市| 和平县| 封开县| 阳江市| 涪陵区| 昔阳县| 大邑县| 景德镇市| 福建省| 呼和浩特市| 兴和县| 铜鼓县| 三穗县| 介休市| 沐川县| 和政县| 托克托县| 克东县| 清丰县| 阳东县| 巴中市| 营口市| 崇明县| 太仆寺旗| 西贡区| 察雅县| 通城县| 龙胜| 石家庄市| 民权县| 廉江市| 读书| 盘山县|