- C# code
-
string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + file + ";" + "Extended Properties='Excel 8.0;HDR=Yes;IMEX=1'"; OleDbDataAdapter ExcelDA = new OleDbDataAdapter("SELECT * FROM [Sheet1$]", strConn); DataSet ExcelDs = new DataSet(); try { ExcelDA.Fill(ExcelDs, "ExcelInfo"); DataTable dt = ExcelDs.Tables[0]; return dt; } catch (Exception err) { Response.Write(err.ToString()); } return null;
写文件:
以"\t" 和"\r\n"分隔文本输出,其中"\t"是列分隔符,"\r\n"是行分隔符,然后文件格式定义为XLS就可以,但如果想输出带格式设置的XLS文件,则需要使用EXCEL控件