尝试这个
System.Data.OleDb.OleDbConnection mCon;
mCon = new System.Data.OleDb.OleDbConnection();
mCon.ConnectionString = ("Provider=Microsoft.ACE.OLEDB.12.0;data source=" + pathOfFile + ";Extended Properties=\"Excel 12.0;HDR=YES\";");
System.Data.OleDb.OleDbCommand Command = new System.Data.OleDb.OleDbCommand();
DataTable DTable = new DataTable();
string strSelectQuery, mstrDBTable;
System.Data.OleDb.OleDbDataAdapter DataAdapter = new System.Data.OleDb.OleDbDataAdapter();
strSelectQuery = "SELECT * FROM [" + YourSheetName + "]";
// YourSheetName is the sheet in xls from where you want to load data e.g Sheet1$
if (mCon.State == ConnectionState.Closed)
{
mCon.Open();
}
DataAdapter = new System.Data.OleDb.OleDbDataAdapter(strSelectQuery, mCon);
DataAdapter.Fill(DTable );
mCon.Close();
现在您的 Excel 工作表在数据表中,您可以遍历它来操作 URL 中的字符串值
编辑
用于获取字符串
for(int i = 0; i<Dtable.Rows.Count;i++)
{
string str = Dtable.Rows[i][1].ToString();
string YourNumber = str.Substring((str.IndexOf('=') + 1), (str.IndexOf('%') - str.IndexOf('=')-1));
}