1
using System;
2
using System.Collections;
3
using System.ComponentModel;
4
using System.Web;
5
using Word;
6
7
namespace Rules
8
{
9
///
10
/// 将word文档上传至服务器然后再转存为html格式文件
11
/// 再解析html文件修改其页面样式和css
12
/// BlackSoul 2005.11.08
13
///
14
public class WordToHTML
15
{
16
public WordToHTML(){}
17
18
上传文件并转换为html wordToHtml(wordFilePath)
82
83
public string uploadWord(System.Web.UI.HtmlControls.HtmlInputFile uploadFiles)
84
{
85
if(uploadFiles.PostedFile != null)
86
{
87
string fileName = uploadFiles.PostedFile.FileName ;
88
int extendNameIndex= fileName.LastIndexOf(".");
89
string extendName = fileName.Substring(extendNameIndex);
90
string newName = "";
91
try
92
{
93
//验证是否为word格式
94
if(extendName == ".doc")
95
{
96
97
DateTime now = DateTime.Now;
98
newName = now.DayOfYear.ToString()+uploadFiles.PostedFile.ContentLength.ToString();
99
//上传路径 指当前上传页面的同一级的目录下面的wordTmp路径
100
uploadFiles.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("wordTmp/" + newName + extendName));
101
}
102
else
103
{
104
return "1";
105
}
106
}
107
catch
108
{
109
return "0";
110
}
111
//return "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath + "/wordTmp/" + newName + extendName;
112
return System.Web.HttpContext.Current.Server.MapPath("wordTmp/" + newName + extendName);
113
}
114
115
else
116
{
117
return "0";
118
}
119
}
120
121
}
122
}
http://www.cnblogs.com/BlackSoul/archive/2006/09/30/wordToHTML.html
using System;2
using System.Collections;3
using System.ComponentModel;4
using System.Web;5
using Word;6

7
namespace Rules8
{9
/// 10
/// 将word文档上传至服务器然后再转存为html格式文件11
/// 再解析html文件修改其页面样式和css12
/// BlackSoul 2005.11.0813
/// 14
public class WordToHTML15
{16
public WordToHTML(){}17

18
上传文件并转换为html wordToHtml(wordFilePath)82

83
public string uploadWord(System.Web.UI.HtmlControls.HtmlInputFile uploadFiles)84
{85
if(uploadFiles.PostedFile != null)86
{87
string fileName = uploadFiles.PostedFile.FileName ;88
int extendNameIndex= fileName.LastIndexOf(".");89
string extendName = fileName.Substring(extendNameIndex);90
string newName = "";91
try92
{93
//验证是否为word格式94
if(extendName == ".doc")95
{96

97
DateTime now = DateTime.Now;98
newName = now.DayOfYear.ToString()+uploadFiles.PostedFile.ContentLength.ToString();99
//上传路径 指当前上传页面的同一级的目录下面的wordTmp路径100
uploadFiles.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("wordTmp/" + newName + extendName));101
}102
else103
{104
return "1";105
}106
}107
catch108
{109
return "0";110
}111
//return "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath + "/wordTmp/" + newName + extendName;112
return System.Web.HttpContext.Current.Server.MapPath("wordTmp/" + newName + extendName);113
}114

115
else116
{117
return "0";118
}119
}120

121
}122
}http://www.cnblogs.com/BlackSoul/archive/2006/09/30/wordToHTML.html


浙公网安备 33010602011771号