在Windows服务中创建Excel文件. [英] Creating Excel file in Windows service.

查看:104
本文介绍了在Windows服务中创建Excel文件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好
我对编程不是很陌生,我正在开发Windows服务,该服务将从MS SQL数据库获取数据到数据表中,然后创建一个excel文件,然后将数据表中的数据添加到excel文件中,然后将包含excel文件的电子邮件作为附件,我在Windows Server 2008上安装了该服务,并且从Windows Service中收到此错误

Hi all
Im fairly new to Programming ,Im developing a windows service that gets data from MS SQL database into a Datatable and then I create an excel file and adds the data from the Datatable into the excel file and then sends an email with the excel file as an attachment,I install the service on a Windows Server 2008 and I get this error from the Windows Service

System.Runtime.InteropServices.COMException (0x80040154): Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80040154 Class not registered (Exception from HRESULT: 0x80040154 (REGDB_E_CLASSNOTREG)).
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache)
   at System.RuntimeType.CreateInstanceDefaultCtor(Boolean publicOnly, Boolean skipVisibilityChecks, Boolean skipCheckThis, Boolean fillCache)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)



请提供帮助,谢谢.



Please help,Thanks in advance

推荐答案

您已经直接根据Excel库构建了服务,并且服务器上未安装excel. ...至少与您构建应用所基于的版本不同.

通常,您还是不想这样做.除了刻录昂贵的Office许可证外,它还会涉及扩展问题,并且可能还会存在安全问题,具体取决于服务终结点的部署方式.如果要执行此操作,建议您使用Office工具(提供一个将您的应用与Office库隔离的互操作层),或者最好使用MS提供的OpenXML库来创建和管理Excel文件.直接...无需依赖实际的Excel.

您也没有提到邮件部分的问题,但是我猜您可能已经使用了Outlook库,因为您使用的是Excel库.如果您在那里遇到问题,建议您使用兑换库.在Windows上,它使从代码发送电子邮件变得轻而易举,并绕开了Outlook在从代码发送电子邮件的方式中放置的所有安全障碍.
You have built your service directly against the Excel libraries and you don''t have excel installed on your server. ...at least not the same version you built your app against.

Generally, you don''t want to do that anyway. Besides burning an expensive Office license, it will have scaling issues and probably security issues depending on how the service endpoint is deployed. If you want to do this, I suggest you either use the Tools For Office (which provides an interop layer that isolates your app from the Office libraries) or, better yet, use the OpenXML libraries that MS provides to create and manage the Excel file directly... without relying on actual Excel.

You didn''t mention problems with the mailing part of it either, but I''m guessing you might have used the Outlook libraries since you use the Excel ones. If you run into issues there, I recommend the Redemption library. It makes e-mailing from code a breeze on Windows and bypasses all of the security roadblocks that Outlook puts in the way to sending e-mail from code.


这篇关于在Windows服务中创建Excel文件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆