C#转换的.xls Excel中没有为.csv [英] C# converting .xls to .csv without Excel

查看:143
本文介绍了C#转换的.xls Excel中没有为.csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

需要转换的.xls或.xlsx为.csv没有在C#/ ASP.net web应用程序使用的Excel。该应用程序正在使用NPOI.dll一些功能,但我没有看到在CodePlex上维基NPOI该特定功能的任何信息。有没有人有什么建议?

Need to convert a .xls or .xlsx to a .csv without the use of Excel in an C#/ASP.net web app. The application is currently using the NPOI.dll for some functionality but I do not see any info on the codeplex wiki for NPOI for that particular functionality. Does anyone have any suggestions?

感谢

推荐答案

ADODB.NET可用于治疗Excel文件作为数据源。

ADODB.NET can be used to treat the Excel files as datasource.

//string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties=Excel 8.0;";
string ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0;";

ConnectionString = string.Format(ConnectionString, @"FullPathToExcelFile");

OleDbConnection conn = new OleDbConnection(ConnectionString);
conn.Open();

OleDbCommand cmdSelect = new OleDbCommand("SELECT * FROM [Sheet1$]", conn);
OleDbDataAdapter oleDBAdapter = new OleDbDataAdapter();
oleDBAdapter.SelectCommand = cmdSelect;

DataSet myDataset = new DataSet();
oleDBAdapter.Fill(myDataset);
conn.Close(); 

// Do whatever with data in myDataset including export to csv...

这篇关于C#转换的.xls Excel中没有为.csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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