All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
SQL Server2000安全管理机制详解_[SQL Server教程]
ASP.NET,2.0中CSS不正常问题及解决_[Asp.Net教程]
用CSS解决未知高度的DIV垂直居中的问题_[Html教程]
C#分析数据库结构,使用XSL模板自动生成代码_.net资料_编程技术
用Asp.Net获取目录的方法_[Asp.Net教程]
ASP.NET技巧:dot,net,html分析类库_.net资料_编程技术
使用PHP的Socket写的POP3类_[PHP教程]
获得汉字字符串的首个拼音字母的缩写_.net资料_编程技术
PHP开发技巧:PHP关于图像颜色的操作_php资料_编程技术
利用OpenSmtp.Net发送需要smtp验证的邮件_.net资料_编程技术
Reading number is top 10 pictures
去瑜伽会所面试的经过
抗日又出雷剧情
Is said to be a Chinese female artist fame explicit pictures before2
Photographed the passion of the clients and prostitutes in the sex trade picture2
Poor doll, hand job was caught the currently in effect by his dad
Female model behind the bitterness, often being overcharged5
Absolutely shocked. National geographic 50 animal photographys7
5 meters long centenarians python and melee was successfully capture king snake (figure)
XuRe xuan cool and refreshing photoes2
So beauty, will let you spray blood9
Download software ranking
终极变速大师Speeder3.26
Detective task-the top secret prostitution files
C++编程教程第三版
C#编程思想
传奇私服架设教程
matrix2
C#程序员参考手册
好色的外科大夫
SQL2000 For 4IN1
Boxer's Top ten classic battle3
delv published in(发表于) 2014/1/23 3:10:39 Edit(编辑)
Asp.net2.0实现Word转换Html,同时分享系列笑话_[Asp.Net教程]

Asp.net2.0实现Word转换Html,同时分享系列笑话_[Asp.Net教程]

Asp.net2.0实现Word转换Html,同时分享系列笑话_[Asp.Net教程]

前两天在园子里看到了BlackSoul 写的《asp.net将word转换为html保存 》的文章
http://www.51aspx.com/CT/Y33HPMEJERPC33/,觉得很实用,但是搭建项目时候缺不是那么回事儿,中间有很多问题,比如说word组建的引用、web.config权限的设置,看到了很多人在网上也在问这个问题,我把问题一一解决,测试成功,现在把全部项目源码文件分享给大家下载。


项目截图:



功能概述及注意事项:


该源码主要是通过Asp.net2.0实现Word文档上传并自动转换为Html文件,原理是将word文档上传至服务器然后再转存为html格式文件,再解析html文件修改其页面样式和css。


wordTmp为上传是word暂存文件夹
html为转换后html保存文件夹



注意:


请设置web.config中的帐号和密码,否则会提示检索 COM 类工厂中 CLSID 为 {000209FF-0000-0000-C000-000000000046} 的组件时失败,原因是出现以下错误: 80070005。


该用户类型为拥有user权限的用户即可


示例Word文件是些笑话,希望能博得大家多多笑容!


部分CS源码:


public partial class _Default : System.Web.UI.Page
{


// public WordToHTML() { }


#region 上传文件并转换为html wordToHtml(wordFilePath)


///


/// 上传文件并转存为html


///


/// word文档在客户机的位置
/// 上传的html文件的地址
public string wordToHtml(System.Web.UI.HtmlControls.HtmlInputFile wordFilePath)
{
Microsoft.Office.Interop.Word.ApplicationClass word = new Microsoft.Office.Interop.Word.ApplicationClass();
Type wordType = word.GetType();
Microsoft.Office.Interop.Word.Documents docs = word.Documents;


// 打开文件
Type docsType = docs.GetType();


//应当先把文件上传至服务器然后再解析文件为html
string filePath = uploadWord(wordFilePath);


//判断是否上传文件成功
if (filePath == "0")
return "0";
//判断是否为word文件
if (filePath == "1")
return "1";


object fileName = filePath;


Microsoft.Office.Interop.Word.Document doc = (Microsoft.Office.Interop.Word.Document) docsType.InvokeMember("Open",
System.Reflection.BindingFlags.InvokeMethod, null, docs, new Object[] { fileName, true, true });


// 转换格式,另存为html
Type docType = doc.GetType();


string filename = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() +
System.DateTime.Now.Hour.ToString() + System.DateTime.Now.Minute.ToString() + System.DateTime.Now.Second.ToString();


//被转换的html文档保存的位置
string ConfigPath = HttpContext.Current.Server.MapPath("html/" + filename + ".html");
object saveFileName = ConfigPath;


/*下面是Microsoft Word 9 Object Library的写法,如果是10,可能写成:
* docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
* null, doc, new object[]{saveFileName, Word.WdSaveFormat.wdFormatFilteredHTML});
* 其它格式:
* wdFormatHTML
* wdFormatDocument
* wdFormatDOSText
* wdFormatDOSTextLineBreaks
* wdFormatEncodedText
* wdFormatRTF
* wdFormatTemplate
* wdFormatText
* wdFormatTextLineBreaks
* wdFormatUnicodeText
*/
docType.InvokeMember("SaveAs", System.Reflection.BindingFlags.InvokeMethod,
null, doc, new object[] { saveFileName, Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatFilteredHTML });


// 退出 Word
wordType.InvokeMember("Quit", System.Reflection.BindingFlags.InvokeMethod, null, word, null);
//转到新生成的页面
return ("/" + filename + ".html");
}
#endregion


public string uploadWord(System.Web.UI.HtmlControls.HtmlInputFile uploadFiles)
{
if (uploadFiles.PostedFile != null)
{
string fileName = uploadFiles.PostedFile.FileName;
int extendNameIndex = fileName.LastIndexOf(".");
string extendName = fileName.Substring(extendNameIndex);
string newName = "";
try
{
//验证是否为word格式
if (extendName == ".doc")
{
DateTime now = DateTime.Now;
newName = now.DayOfYear.ToString() + uploadFiles.PostedFile.ContentLength.ToString();
//上传路径 指当前上传页面的同一级的目录下面的wordTmp路径
uploadFiles.PostedFile.SaveAs(System.Web.HttpContext.Current.Server.MapPath("wordTmp/" + newName + extendName));
}
else
{
return "1";
}
}
catch
{
return "0";
}
//return "http://" + HttpContext.Current.Request.Url.Host + HttpContext.Current.Request.ApplicationPath + "/wordTmp/" + newName + extendName;
return System.Web.HttpContext.Current.Server.MapPath("wordTmp/" + newName + extendName);
}


else
{
return "0";
}
}


protected void btnUpload_Click(object sender, EventArgs e)
{
try
{
//上传
uploadWord(File1);
//转换
wordToHtml(File1);
}
catch (Exception ex)
{
throw ex;
}
finally
{
Response.Write("恭喜,转换成功!");
}
}


}


完整项目源码下载
http://www.51aspx.com/CV/WordToHtml/


来源:CNBLOGS







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.