C#使用httpWebRequest抓取出的数据是application/vnd.ms-excel格式,应如何读取?
发布网友
发布时间:2022-04-28 11:36
我来回答
共2个回答
热心网友
时间:2023-10-06 05:00
xls你已经下来回来了吧?
读取xls内容
public DataSet ExcelDataSource(string filepath, string sheetname)
{
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
OleDbDataAdapter oada = new OleDbDataAdapter("select * from [" + sheetname + "]", strConn);
DataSet ds = new DataSet();
oada.Fill(ds);
conn.Close();
return ds;
}
//获得Excel中的所有sheetname。
public ArrayList ExcelSheetName(string filepath)
{
ArrayList al = new ArrayList();
string strConn;
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + filepath + ";Extended Properties=Excel 8.0;";
OleDbConnection conn = new OleDbConnection(strConn);
conn.Open();
DataTable sheetNames = conn.GetOleDbSchemaTable
(System.Data.OleDb.OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
conn.Close();
foreach (DataRow dr in sheetNames.Rows)
{
al.Add(dr[2]);
}
return al;
}
热心网友
时间:2023-10-06 05:00
aspose.cells 或者npoi读取xls追问有详细的代码可以参考一下么?谢谢!