国产探花免费观看_亚洲丰满少妇自慰呻吟_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ā)表
主站蜘蛛池模板: 通榆县| 沁源县| 长沙县| 营山县| 钦州市| 万全县| 修水县| 隆子县| 海安县| 丰顺县| 济源市| 明光市| 武义县| 宜宾县| 吴堡县| 巴中市| 乌拉特前旗| 澄江县| 寿宁县| 元朗区| 贺兰县| 鄂伦春自治旗| 莱芜市| 荃湾区| 成安县| 青岛市| 霍城县| 阿坝| 涟水县| 外汇| 仁布县| 贵南县| 科尔| 玉溪市| 旅游| 衡东县| 土默特右旗| 施秉县| 昌都县| 同德县| 周口市|