服务器端读取excel

发布于 2024-12-10 17:45:23 字数 371 浏览 0 评论 0原文

我需要开发一个服务并将其安装到 w2003 盒子中以读取 excel 文件,然后处理其信息。过程如下,用户将使用 FTP 上传 Excel 文件,然后我的服务必须获取这些文件,验证然后更新 SQL Server 数据库。

该应用程序在我的计算机上运行良好,但在服务器上它要求提供库,但当我尝试安装 MS Office 2003 主互操作程序集时,系统显示“请在安装产品之前安装 Microsoft Office 2003”。

我宁愿远离任何服务器升级,因为我们应该要求确定等。那么,有没有一种简单的方法可以读取 Excel 文件,而无需在服务器中安装任何更新。

欢迎任何评论。

谢谢, m0dest0。

附:使用 vb.net 和 vs 2008。

I need to develop a service and install it into a w2003 box to read excel files a then process its info. The process is as follows, users will upload excel files using FTP and then my service must take those files, validate and then update a SQL Server DB.

The application runs fine on my computer but on the server it asks for the libraries but when I try to install the MS office 2003 Primary Interop Assemblies, system displays "Please install Microsoft Office 2003 before installing the product".

I'd prefer to stay away of any server upgrade as we should require OKs, etc.. so, is there a simple way to just read excel files without having to install any update in the server.

any comments are welcome.

Thanks,
m0dest0.

ps. using vb.net and vs 2008.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只为一人 2024-12-17 17:45:23

MS 不支持在服务器上使用 Interop - 请参阅 http ://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

自 Windows Vista MS 引入了一些与安全相关的措施来阻止 Windows 服务执行以下操作: “类似桌面”的东西......这意味着您必须规避多种安全措施才能使其正常工作(不推荐!)。

要在服务器场景中处理 Excel,有多种选择(免费和商业):

我可以推荐 Aspose.CellsFlexcel...没有尝试SpreadsheetGear,但听到+阅读了很多关于它的好处...

免费选项(尽管仅适用于较新的 xlsx 格式!)例如 来自 MS 的 OpenXML 2EPPlus

Using Interop on the server is NOT supported by MS - see http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2

Since Windows Vista MS introduced several security-related measures which prevent a Windows Service from doing "desktop-like" things... which means you would have to circumvent several security measures to get it to work (NOT recommended!).

To deal with Excel in a server-scenario there are several options (free and commercial) out there:

I can recommend Aspose.Cells and Flexcel... didn't try SpreadsheetGear but hear+read lots of good things about it...

Free options (though for the newer xlsx format only!) are for example OpenXML 2 from MS and EPPlus.

長街聽風 2024-12-17 17:45:23

对于在任何最新版本的 Windows Server 上无需安装任何内容的解决方案......我不确定确切的 VB.NET 代码,但您应该能够轻松地在任何使用 Microsoft OLEDB 驱动程序的计算机上执行此操作可在任何最新版本的 Windows Server 上使用,也可以从 Microsoft 网站上免费下载非常旧版本的 Windows Server 进行安装。我将尝试对此进行伪代码,因此您必须针对 VB.NET 进行调整。请注意,为了按名称引用字段,工作表中选定区域的第一行必须包含列值中的字段名称。否则,您只需使用数值按列位置对每个返回的字段进行索引。

Set objExcelConnection = CreateObject("ADODB.Connection")
objExcelConnection.Provider = "Microsoft.Jet.OLEDB.4.0"
objExcelConnection.ConnectionString = "Data Source=d:\path\to\excel\file\on\your\server.xls;Extended Properties=""Excel 8.0;IMEX=1;"";"
objExcelConnection.CursorLocation = 3
objExcelConnection.Open


sSQL = "select * from [worksheetname$]"
set rsWorksheet = objExcelConnection.Execute(sSQL)
do while not rsWorksheet.Eof
    sValue = rsWorksheet("FieldName")
    rsWorksheet.MoveNext
loop
rsWorksheet.Close

set objExcelConnection = nothing

For a solution with nothing to install on any recent versions of Windows Server..... I'm not sure the exact VB.NET code, but you should easily be able to do this on any machine using the Microsoft OLEDB drivers that should be available on any recent version of windows server or can be installed from a free download off of the Microsoft website for very old versions of windows server. I'll try to pseudo code this, so you will have to adapt it for VB.NET. Note that in order to reference your fields by name, the first row of the selected area in the worksheet must contain the fieldnames in the column values. Otherwise you will simply have to use numeric values to index each returned field by column position.

Set objExcelConnection = CreateObject("ADODB.Connection")
objExcelConnection.Provider = "Microsoft.Jet.OLEDB.4.0"
objExcelConnection.ConnectionString = "Data Source=d:\path\to\excel\file\on\your\server.xls;Extended Properties=""Excel 8.0;IMEX=1;"";"
objExcelConnection.CursorLocation = 3
objExcelConnection.Open


sSQL = "select * from [worksheetname$]"
set rsWorksheet = objExcelConnection.Execute(sSQL)
do while not rsWorksheet.Eof
    sValue = rsWorksheet("FieldName")
    rsWorksheet.MoveNext
loop
rsWorksheet.Close

set objExcelConnection = nothing
沒落の蓅哖 2024-12-17 17:45:23

当我需要处理 Excel 文件时,我使用 Excel Data Reader (http://exceldatareader.codeplex.com/)。它可以顺利处理 xls 和 xlsx 文件,并且我已经让它在服务器操作系统上的一些应用程序中运行。它将每个工作表保存为一个DataTable对象,DataTable中的每个“单元格”都对应于具有相同地址的Excel单元格。根据您设置 SQL Server 链接的方式,将内容转储到数据库中可能不需要太多转换。

I use the Excel Data Reader (http://exceldatareader.codeplex.com/) when I need to process Excel files. It handles xls and xlsx files without a hitch, and I've got it running in a few applications on a server OS. It saves each sheet as a DataTable object, and each "cell" in the DataTable corresponds to the Excel cell with the same address. Depending on how you set up your SQL server link, there might not be too much conversion required to dump the contents into the DB.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文