相关疑难解决方法(0)

使用Oledb读取Excel文件 - 将excel文件的内容视为仅文本

我正在使用C#和OleDb从excel 2007文件中读取数据.

我正在使用的连接字符串是:

Provider=Microsoft.ACE.OLEDB.12.0;Data Source=c:\myFolder\myExcel2007file.xlsx;Extended Properties="Excel 12.0 Xml;HDR=YES;IMEX=1";
Run Code Online (Sandbox Code Playgroud)

以下是读取excel的代码:

private OleDbConnection con = null;
private OleDbCommand cmd = null;
private OleDbDataReader dr = null;
private OleDbDataAdapter adap = null;
private DataTable dt = null;
private DataSet ds = null;
private string query;
private string conStr;

public MainWindow()
{
    this.InitializeComponent();
    this.query = "SELECT * FROM [Sheet1$]";
    this.conStr = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\\Users\\301591\\Desktop\\Fame.xlsx;Extended Properties=\"Excel 12.0 Xml;HDR=YES;IMEX=1;TypeGuessRows=0;ImportMixedTypes=Text\"";
}

private void btnImport_Click(object sender, RoutedEventArgs e)
{
    this.ImportingDataSetWay();
}

private void ImportingDataSetWay()
{
    con = new OleDbConnection(conStr); …
Run Code Online (Sandbox Code Playgroud)

c# oledb wpf excel-2007

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

c# ×1

excel-2007 ×1

oledb ×1

wpf ×1