office在asp页面内asp.net 显示外部页面

asp.net项目引入office com组件对word操作,在发布程序时如何处理com组件? - 开源中国社区
当前访客身份:游客 [
当前位置:
请教一下asp.net项目引入office com组件之后一般是如何在服务器上部署的?
共有2个答案
<span class="a_vote_num" id="a_vote_num_
这样问问题,有人回答都算奇迹了~~
起码得把“出了什么问题” 说明一下,最好有图或日志提示。
<span class="a_vote_num" id="a_vote_num_
要对COM插件进行用户授权,很麻烦,一般不推荐使用
更多开发者职位上
有什么技术问题吗?
夙歆风的其它问题
类似的话题ASP页面直接显示打印ACCESS报表
ASP页面直接显示打印ACCESS报表
某客户习惯使用ACCESS来制作报表,觉得用起来方便,平是都是直接在服务器上用,
直接通过ACCESS数据库来打印报表。
他们有个很老的系统,是ASP做的,有一天,他们老板说想直接同过IE能看或能打印
ACCESS的报表。
对于这个要求,我们做了分析,如果在ASP可以生成ACCESS对象的话,是不难做到的。
但从百度搜索的结果,国人一般都是直接通过ADO,DAO来连接ACCESS,只是当作数据库来用。
根本就没有现成的例子可以参照。国外倒是有个例子,但还是2000年的,在pws环境下做的。
一,遇到ASP 0178的错误
直接拿来根本连Server.CreateObject("Access.Application")都不成功,老是报ASP
原因肯定是权限的问题,很多人说
1)要设置:C:\Program Files\Common Files\System这个文件夹的权限,
2)或者要运行dcomcnfg--下面是微软的帮助您需要为 IUSR_
&machine_name& 启动并访问您使用 dcomcnfg
命令,通过执行以下的 OOP COM 对象的帐户权限:
通过单击开始按钮,选择运行,然后在运行对话框中键入"dcomcnfg",启动 dcomcnfg 命令。
在默认安全机制选项卡中单击在"编辑默认值"默认访问权限框中。在 注册表值权限 对话框。
添加该 IUSR_ &machine_name &
到帐户的帐户和该实例在注册表值权限 对话框框,然后单击 确定。
在 默认安全机制 选项卡中单击在编辑默认值在默认启动权限框架。在 注册表值权限 对话框。
添加该 IUSR_ &machine_name &
帐户注册表值权限对话框 box0,然后单击OK.
对于1,肯定是不对,但也可以参考,应该给Access安装目录给IUSR_
&machine_name&设定执行的权限,
对于2,可能和服务器版本有关,开始我在windows server 2008测试,说的默认安全机制选项卡到底是
什么东西,根本没有弄清楚,
倒是下面的帮助直接修改对应的Object 权限才识对的。
调用"server.createObject("mssearch.application")"的时候发生错误,解决如下:
& 开始-&运行-&dcomcnfg
&& 找到"mssearch"(这个名称取决于你调用的Object是什么),然后右键-&Properties-&security把三个权限都& 给everyone即可,其实第一个即可.
windows server 2008里面根本找不到Access对应的项,后来偶然机会改在windows server 2003里面测试,终于
发现了有 microsoft office access对应的项目,根据提示修改后,就可以CreateObject了。
二,打开数据库出错
接来OpenCurrentDatabase打开数据库有出现了问题,一直出错,怀疑还是权限的问题,IUSR_ &machine_name & 帐没有相关的权限,对于操作数据库需要多少权限也懒得去查,有人说如果请求CreateObject的话改用Admin用户的话,可以解决问题,但是会有安全方面的问题。最后还是用了这个方法,只是建了一个普通用户,有打开access权限。
解决上面两个问题,基本就可以正常执行下去了。
下面把代码贴出来
& 'after declaring the variables....
&& &&& strDbName = Request.Form("db")& 'Gets the database name
& &&& Set objAccess = Server.CreateObject("Access.Application")
& &&& objAccess.Visible = False
& &&& objAccess.OpenCurrentDatabase Server.MapPath(strDbName)
&With objAccess.DoCmd
& .OpenReport strRptName, acViewPreview, strFilter, strWhere
& .OutputTo acOutputReport, , "Snapshot Format", _
&&&&&&&&&&&&&&&&&& Server.MapPath(".") & "\snapfiles\" & strSnapFile
& objAccess.Quit acQuitSaveNone
& Set objAccess = Nothing
发表评论:
TA的最新馆藏.NET实现在网页中预览Office文件的3个方法,ASPNET教程,ASPNET案例,ASPNET实例
本站中文域名:、 
        
     
 |  |  |  |  
     |     |     |   
您的位置: &&
&& .NET实现在网页中预览Office文件的3个方法
.NET实现在网页中预览Office文件的3个方法
近日公司要搞一个日常的东东,可以上传、下载各种文件,如果是office文件呢还必须得支持预览功能,其他的都好说但是唯独office预览功能比较麻烦,但是不能不做,废话不多说了一步步来吧&。分析了下网易邮箱的文件预览功能,他用的是微软的组件,最早叫Office online,现在分开了叫Word online、Excel online ....等等,效果十分炫酷功能十分强大,但是查看了下对api的说明发现对服务器的要求比较苛刻而且配置比较复杂不太适合&。然后 又看了下腾讯用的是永中第三方组件,效果嘛自然比不上微软的但是能用,综合网上的一些资料大概也就那么几种方式实现
1.使用Microsoft的Office组件将文件直接转换为html文件(优点:代码实现最简单,工作强度最小&。缺点:效果极差)
2.使用Microsoft的Office组件将文件转换为PDF格式文件,然后再使用pdf2swf转换为swf文件,也就是flash文件在使用FlexPaper展示出来(优点:预览效果能接受,缺点:代码量大)
3. 使用Office online(优点:表现完美,缺点:不适合中小企业应用)
综合考虑决定使用第二种方法,经过次次波折终于可以使用,但是有个问题至今没有得到解决,调用Office组件的时候有时候会出现如下异常:
检索 COM 类工厂中 CLSID 为 {000209FF--C000-} 的组件失败,原因是出现以下错误: 8000401a 因为配置标识不正确,系统无法开始服务器进程&。请检查用户名和密码&。 (异常来自 HRESULT:0x8000401A),查阅无数资料还是不能解决,最让人不可接受的的是office文件必须标标准准毫无容错能力,当转换ppt文件时竟然会弹出转换进度框!!
好吧!那么我们改进它&。
使用ASPOSE+pdf2swf+FlexPaper
关于ASPOSE大家可以到官网了解,这是款商业收费产品但是免费也可以使用
1、引用dll
2、编写转换帮助类
复制代码 代码如下:
using System.Collections.G
using System.L
using System.T
using Aspose.C
using Aspose.W
using Aspose.S
using System.Text.RegularE
using System.IO;
&&& /// &summary&
&&& /// 第三方组件ASPOSE Office/WPS文件转换
&&& /// Writer:Helen Joe
&&& /// Date:
&&& /// &/summary&
&&& public class AsposeUtils
&&&&&&& /// &summary&
&&&&&&& /// PFD转换器位置
&&&&&&& /// &/summary&
&&&&&&& private static string _EXEFILENAME = System.Web.HttpContext.Current != null
&&&&&&&&&&&&&&& &#63; System.Web.HttpContext.Current.Server.MapPath("/pdf2swf/pdf2swf.exe")
&&&&&&&&&&&&&&& : System.bine(AppDomain.CurrentDomain.BaseDirectory + "\\pdf2swf\\pdf2swf.exe");
&&&&&&& #region 1.01 Wrod文档转换为PDF文件 +ConvertDocToPdF(string sourceFileName, string targetFileName)
&&&&&&& /// &summary&
&&&&&&& /// Wrod文档转换为PDF文件
&&&&&&& /// &/summary&
&&&&&&& /// &param name="sourceFileName"&需要转换的Word全路径&/param&
&&&&&&& /// &param name="targetFileName"&目标文件全路径&/param&
&&&&&&& /// &returns&转换是否成功&/returns&
&&&&&&& public static bool ConvertDocToPdF(string sourceFileName, string targetFileName)
&&&&&&&&&&& Souxuexiao.API.Logger.error(string.Format("Wrod文档转换为PDF文件:sourceFileName={0},targetFileName={1}", sourceFileName, targetFileName));
&&&&&&&&&&& try
&&&&&&&&&&& {
&&&&&&&&&&&&&&& using (System.IO.Stream stream = new System.IO.FileStream(sourceFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& Document doc = new Document(sourceFileName);
&&&&&&&&&&&&&&&&&&& doc.Save(targetFileName, Aspose.Words.SaveFormat.Pdf);
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& catch (Exception ex)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& Souxuexiao.API.Logger.error(string.Format("Wrod文档转换为PDF文件执行ConvertDocToPdF发生异常原因是:{0}",ex.Message));
&&&&&&&&&&& }
&&&&&&&&&&& return System.IO.File.Exists(targetFileName);
&&&&&&& #endregion
&&&&&&& #region 1.02 Excel文件转换为HTML文件 +(string sourceFileName, string targetFileName, string guid)
&&&&&&& /// &summary&
&&&&&&& /// Excel文件转换为HTML文件
&&&&&&& /// &/summary&
&&&&&&& /// &param name="sourceFileName"&Excel文件路径&/param&
&&&&&&& /// &param name="targetFileName"&目标路径&/param&
&&&&&&& /// &returns&转换是否成功&/returns&
&&&&&&& public static bool ConvertExcelToHtml(string sourceFileName, string targetFileName)
&&&&&&&&&&& Souxuexiao.(string.Format("准备执行Excel文件转换为HTML文件,sourceFileName={0},targetFileName={1}",sourceFileName,targetFileName));
&&&&&&&&&&& try
&&&&&&&&&&& {
&&&&&&&&&&&&&&& using (System.IO.Stream stream = new System.IO.FileStream(sourceFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& Aspose.Cells.Workbook workbook = new Workbook(stream);
&&&&&&&&&&&&&&&&&&& workbook.Save(targetFileName, Aspose.Cells.SaveFormat.Html);
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& catch (Exception ex)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& Souxuexiao.API.Logger.error(string.Format("Excel文件转换为HTML文件ConvertExcelToHtml异常原因是:{0}", ex.Message));
&&&&&&&&&&& }
&&&&&&&&&&& return System.IO.File.Exists(targetFileName);
&&&&&&& #endregion
&&&&&&& #region 1.03 将PowerPoint文件转换为PDF +ConvertPowerPointToPdf(string sourceFileName, string targetFileName)
&&&&&&& /// &summary&
&&&&&&& /// 将PowerPoint文件转换为PDF
&&&&&&& /// &/summary&
&&&&&&& /// &param name="sourceFileName"&PPT/PPTX文件路径&/param&
&&&&&&& /// &param name="targetFileName"&目标文件路径&/param&
&&&&&&& /// &returns&转换是否成功&/returns&
&&&&&&& public static bool ConvertPowerPointToPdf(string sourceFileName, string targetFileName)
&&&&&&&&&&& Souxuexiao.(string.Format("准备执行PowerPoint转换PDF,sourceFileName={0},targetFileName={1}",sourceFileName,targetFileName));
&&&&&&&&&&& try
&&&&&&&&&&& {
&&&&&&&&&&&&&&& using (System.IO.Stream stream = new System.IO.FileStream(sourceFileName, System.IO.FileMode.Open, System.IO.FileAccess.Read, System.IO.FileShare.ReadWrite))
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& Aspose.Slides.Pptx.PresentationEx pptx = new Aspose.Slides.Pptx.PresentationEx(stream);
&&&&&&&&&&&&&&&&&&& pptx.Save(targetFileName, Aspose.Slides.Export.SaveFormat.Pdf);
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& catch (Exception ex)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& Souxuexiao.API.Logger.error(string.Format("将PowerPoint文件转换为PDFConvertExcelToHtml异常原因是:{0}", ex.Message));
&&&&&&&&&&& }
&&&&&&&&&&& return System.IO.File.Exists(targetFileName);
&&&&&&& #endregion
&&&&&&& #region 2.01 读取pdf文件的总页数 +GetPageCount(string pdf_filename)
&&&&&&& /// &summary&
&&&&&&& /// 读取pdf文件的总页数
&&&&&&& /// &/summary&
&&&&&&& /// &param name="pdf_filename"&pdf文件&/param&
&&&&&&& /// &returns&&/returns&
&&&&&&& public static int GetPageCountByPDF(string pdf_filename)
&&&&&&&&&&& int pageCount = 0;
&&&&&&&&&&& if (System.IO.File.Exists(pdf_filename))
&&&&&&&&&&& {
&&&&&&&&&&&&&&& try
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& byte[] buffer = System.IO.File.ReadAllBytes(pdf_filename);
&&&&&&&&&&&&&&&&&&& if (buffer != null && buffer.Length & 0)
&&&&&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&&&&&& pageCount = -1;
&&&&&&&&&&&&&&&&&&&&&&& string pdfText = Encoding.Default.GetString(buffer);
&&&&&&&&&&&&&&&&&&&&&&& Regex regex = new Regex(@"/Type\s*/Page[^s]");
&&&&&&&&&&&&&&&&&&&&&&& MatchCollection conllection = regex.Matches(pdfText);
&&&&&&&&&&&&&&&&&&&&&&& pageCount = conllection.C
&&&&&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& }
&&&&&&&&&&&&&&& catch (Exception ex)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& Souxuexiao.API.Logger.error(string.Format("读取pdf文件的总页数执行GetPageCountByPowerPoint函数发生异常原因是:{0}", ex.Message));
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& return pageC
&&&&&&& #endregion
&&&&&&& #region 2.02 转换PDF文件为SWF格式 +PDFConvertToSwf(string pdfPath, string swfPath, int page)
&&&&&&& /// &summary&
&&&&&&& /// 转换PDF文件为SWF格式
&&&&&&& /// &/summary&
&&&&&&& /// &param name="pdfPath"&PDF文件路径&/param&
&&&&&&& /// &param name="swfPath"&SWF生成目标文件路径&/param&
&&&&&&& /// &param name="page"&PDF页数&/param&
&&&&&&& /// &returns&生成是否成功&/returns&
&&&&&&& public static bool PDFConvertToSwf(string pdfPath, string swfPath, int page)
&&&&&&&&&&& StringBuilder sb = new StringBuilder();
&&&&&&&&&&& sb.Append(" \"" + pdfPath + "\"");
&&&&&&&&&&& sb.Append(" -o \"" + swfPath + "\"");
&&&&&&&&&&& sb.Append(" -z");
&&&&&&&&&&& //flash version
&&&&&&&&&&& sb.Append(" -s flashversion=9");
&&&&&&&&&&& //禁止PDF里面的链接
&&&&&&&&&&& sb.Append(" -s disablelinks");
&&&&&&&&&&& //PDF页数
&&&&&&&&&&& sb.Append(" -p " + "\"1" + "-" + page + "\"");
&&&&&&&&&&& //SWF中的图片质量
&&&&&&&&&&& sb.Append(" -j 100");
&&&&&&&&&&& string command = sb.ToString();
&&&&&&&&&&& System.Diagnostics.Process p =
&&&&&&&&&&& try
&&&&&&&&&&& {
&&&&&&&&&&&&&&& using (p = new System.Diagnostics.Process())
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& p.StartInfo.FileName = _EXEFILENAME;
&&&&&&&&&&&&&&&&&&& p.StartInfo.Arguments =
&&&&&&&&&&&&&&&&&&& p.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(_EXEFILENAME);
&&&&&&&&&&&&&&&&&&& //不使用操作系统外壳程序 启动 线程
&&&&&&&&&&&&&&&&&&& p.StartInfo.UseShellExecute =
&&&&&&&&&&&&&&&&&&& //p.StartInfo.RedirectStandardInput =
&&&&&&&&&&&&&&&&&&& //p.StartInfo.RedirectStandardOutput =
&&&&&&&&&&&&&&&&&&& //把外部程序错误输出写到StandardError流中(pdf2swf.exe的所有输出信息,都为错误输出流,用 StandardOutput是捕获不到任何消息的...
&&&&&&&&&&&&&&&&&&& p.StartInfo.RedirectStandardError =
&&&&&&&&&&&&&&&&&&& //不创建进程窗口
&&&&&&&&&&&&&&&&&&& p.StartInfo.CreateNoWindow =
&&&&&&&&&&&&&&&&&&& //启动进程
&&&&&&&&&&&&&&&&&&& p.Start();
&&&&&&&&&&&&&&&&&&& //开始异步读取
&&&&&&&&&&&&&&&&&&& p.BeginErrorReadLine();
&&&&&&&&&&&&&&&&&&& //等待完成
&&&&&&&&&&&&&&&&&&& p.WaitForExit();
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& catch (Exception ex)
&&&&&&&&&&& {
&&&&&&&&&&&&&&& Souxuexiao.API.Logger.error(string.Format("转换PDF文件为SWF格式执行PDFConvertToSwf函数发生异常原因是:{0}", ex.Message));
&&&&&&&&&&& }
&&&&&&&&&&& finally
&&&&&&&&&&& {
&&&&&&&&&&&&&&& if (p != null)
&&&&&&&&&&&&&&& {
&&&&&&&&&&&&&&&&&&& //关闭进程
&&&&&&&&&&&&&&&&&&& p.Close();
&&&&&&&&&&&&&&&&&&& //释放资源
&&&&&&&&&&&&&&&&&&& p.Dispose();
&&&&&&&&&&&&&&& }
&&&&&&&&&&& }
&&&&&&&&&&& return File.Exists(swfPath);
&&&&&&& #endregion
Office格式转换
3、将pdf文件转swf的转换器放到站点根目录下新建文件夹pdf2swf(我就是这么配置的,您随意)
4、配置FlexPaper
预览页面引用
&复制代码 代码如下:
&&script src="/FlexPaper/js/swfobject.js" type="text/javascript"&&/script&
&script type="text/javascript" src="/FlexPaper/js/flexpaper_flash.js"&&/script&
控件容器以及设置项
复制代码 代码如下:
&div style="margin:0width:980"&
&&&&&&&&&&& &div id="flashContent" style="display:"&
&&&&&&&&&&&&&&& &p&
&&&&&&&&&&&&&&&&&&& To view this page ensure that Adobe Flash Player version
&&&&&&&&&&&&&&&&&&& 10.0.0 or greater is installed.
&&&&&&&&&&&&&&& &/p&
&&&&&&&&&&&&&&& &script type="text/javascript"&
&&&&&&&&&&&&&&&&&&& var pageHost = ((document.location.protocol == "https:") &#63; "https://" : "http://");
&&&&&&&&&&&&&&&&&&& document.write("&a href=/go/getflashplayer&&img src=" + pageHost + "/images/shared/download_buttons/get_flash_player.gif alt=Get Adobe Flash player /&&/a&");
&&&&&&&&&&&&&&& &/script&
&&&&&&&&&&& &/div&
&&&&&&& &script type="text/javascript"&
&&&&&&&&&&& var _filename = document.getElementById("_filename").
&&&&&&&&&&& var swfVersionStr = "9.0.0";
&&&&&&&&&&& var xiSwfUrlStr = "playerProductInstall.swf";
&&&&&&&&&&& var flashvars = {
&&&&&&&&&&&&&&& SwfFile: escape(_filename),
&&&&&&&&&&&&&&& Scale: 0.6,
&&&&&&&&&&&&&&& ZoomTransition: "easeOut",
&&&&&&&&&&&&&&& ZoomTime: 0.5,
&&&&&&&&&&&&&&& ZoomInterval: 0.1,
&&&&&&&&&&&&&&& FitPageOnLoad: false,
&&&&&&&&&&&&&&& FitWidthOnLoad: true,
&&&&&&&&&&&&&&& PrintEnabled: true,
&&&&&&&&&&&&&&& FullScreenAsMaxWindow: false,
&&&&&&&&&&&&&&& ProgressiveLoading: true,
&&&&&&&&&&&&&&& PrintToolsVisible: true,
&&&&&&&&&&&&&&& ViewModeToolsVisible: true,
&&&&&&&&&&&&&&& ZoomToolsVisible: true,
&&&&&&&&&&&&&&& FullScreenVisible: true,
&&&&&&&&&&&&&&& NavToolsVisible: true,
&&&&&&&&&&&&&&& CursorToolsVisible: true,
&&&&&&&&&&&&&&& SearchToolsVisible: true,
&&&&&&&&&&&&&&& SearchMatchAll:true,
&&&&&&&&&&&&&&& localeChain: "zh_CN"
&&&&&&&&&&& };
&&&&&&&&&&& var params = {
&&&&&&&&&&&&&&& quality: "high",
&&&&&&&&&&&&&&& bgcolor: "#ffffff",
&&&&&&&&&&&&&&& allowscriptaccess: "sameDomain",
&&&&&&&&&&&&&&& allowfullscreen: "true"
&&&&&&&&&&& }
&&&&&&&&&&& var attributes = { id: "FlexPaperViewer", name: "FlexPaperViewer" };
&&&&&&&&&&& swfobject.embedSWF("/FlexPaper/FlexPaperViewer.swf", "flashContent", "980", "620", swfVersionStr, xiSwfUrlStr, flashvars, params, attributes);
&&&&&&&&&&& swfobject.createCSS("#flashContent", "display:text-align:");
&&&&&&& &/script&
&&&&&&& &/div&
document.getElementById("_filename").value是预览文件的路径
OK& 大功告成& ,至于如何上传,怎么保存上传的文件等等那些逻辑我这里就省略了&。&。&。&。,但是有个建议,当用户上传文件之后调用转换api生成预览文件是个耗时的操作,
文件越大耗时越长,也就是说生成预览文件的时候是需要时间的,因此我使用异步方式生成预览文件&。
Google搜索中
搜狗搜索中
在线教程导航
数据库开发
车友晒价详情
暂时没有问,因为当地没有斯柯达4S店,参考网上的报价。
<font color="#FF万
大众江都店
<font color="#FF万
我去了泰州那边要27送脚垫啊什么的小件
<font color="#FF
要求最近两个月出厂的新车
<font color="#FF万
江阴新东亚汽车销售服务有限公司(4S店)。我是电话咨询的,说的优惠6000元现金,其他没有说,要到店详谈。
<font color="#FF万
南京坤龙汽车
地址:江宁区东山街道润麒路19号
现在明锐 2015款 1.6L 自动逸俊版裸车价格:12.99万元
<font color="#FF万
<font color="#FF万
还没去过任何一家4S店。
团购车型:
加入微信号,了解汽车///活动
| 站长工具:
加入官方微信号
渠道报价/招聘
任你发任你查
All Rights Reserved.
珠江路在线版权所有
苏ICP备号 中文域名:
 |  | asp.net在页面中显示word内容(图文混排)
[问题点数:40分]
asp.net在页面中显示word内容(图文混排)
[问题点数:40分]
不显示删除回复
显示所有回复
显示星级回复
显示得分回复
只显示楼主
匿名用户不能发表回复!|
每天回帖即可获得10分可用分!小技巧:
你还可以输入10000个字符
(Ctrl+Enter)
请遵守CSDN,不得违反国家法律法规。
转载文章请注明出自“CSDN(www.csdn.net)”。如是商业用途请联系原作者。

我要回帖

更多关于 asp.net 显示office 的文章

 

随机推荐