如何在未安装Office的情况下处理vb.net中的Excel文件 [英] How to process excel file in vb.net without office installed

查看:317
本文介绍了如何在未安装Office的情况下处理vb.net中的Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是VB.net的新手,从未使用它来处理Office文件. 现在,我必须查看Excel文件并根据单元格中的数据发送一些电子邮件.我不需要向这些文件写任何东西. 到目前为止,我已经阅读了很多有关PIA的文章,到目前为止,看来我必须针对特定的Office版本设计应用程序了吗? 有没有一种方法可以编写可以处理由不同版本的MS Excel创建的文件的应用程序? 我希望能够在不将Office完全安装在计算机上的情况下处理这些文件,有什么办法吗?

I am fairly new to VB.net and never used it for processing Office files. Right now I have to look at Excel file and send some emails based on the data in the cells. I do not need to write anything to these files. So far I have read quite a bit about PIAs and so far it looks that I have to design my application for particular Office version? Is there a way to write the application which could handle files created by different versions of MS Excel? I would like to be able to process these files without Office being installed on the computer at all, is there any way to do it?

推荐答案

无需安装Office即可从excel文件中获取数据.

Don't need to install Office for getting data from excel file.

但是要从EXCEL文件中获取数据,如果您将应用程序托管在服务器上,则必须在本地计算机和服务器中安装OLEDB驱动程序.

But for getting data from EXCEL fileyou have to install OLEDB driver in your local machine as well as server if you are hosted your application on server.

您可以从 MICROSOFT 下载OLEDB驱动程序.

You can download OLEDB driver from MICROSOFT.

 con = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + YourEXCELFilePath + ";Extended Properties=Excel 12.0;")

con.Open()
atatable = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, Nothing)
sheetname = datatable.Rows(0)("table_name").ToString
excelcomm = New OleDbCommand("select * from [" + sheetname + "]", con)
adexcel = New OleDbDataAdapter(excelcomm)
adexcel.Fill(Dataset)

此代码之后,您将在数据集中获取excel工作表数据.

After this code you will get excel sheet data in dataset.

此代码可以帮助您从excel文件中获取数据.

Might this code can help you to get data from excel file.

(注意:此代码位于vb.net中)

(NOTE:this code is in vb.net)

这篇关于如何在未安装Office的情况下处理vb.net中的Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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