简体   繁体   English

如何在没有安装Office的情况下处理vb.net中的excel文件

[英]How to process excel file in vb.net without office installed

I am fairly new to VB.net and never used it for processing Office files. 我是VB.net的新手,从未用它来处理Office文件。 Right now I have to look at Excel file and send some emails based on the data in the cells. 现在我必须查看Excel文件并根据单元格中的数据发送一些电子邮件。 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? 到目前为止,我已经阅读了很多关于PIA的内容,到目前为止看起来我必须为特定的Office版本设计我的应用程序? Is there a way to write the application which could handle files created by different versions of MS Excel? 有没有办法编写可以处理由不同版本的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,有什么办法吗?

您可以使用Open XML SDK 2.0 for Microsoft Office 链接

Don't need to install Office for getting data from excel file. 不需要安装Office以从excel文件获取数据。

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

You can download OLEDB driver from MICROSOFT . 您可以从MICROSOFT下载OLEDB驱动程序。

 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)

After this code you will get excel sheet data in dataset. 在此代码之后,您将获得数据集中的Excel工作表数据。

Might this code can help you to get data from excel file. 可能这段代码可以帮助您从excel文件中获取数据。

(NOTE:this code is in vb.net) (注意:此代码在vb.net中)

you can use 您可以使用

  1. npoi NPOI

  2. epplus epplus

    which do not require excel 这不需要excel

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM