Excel 批量出来数据
Posted zkbfighting
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Excel 批量出来数据相关的知识,希望对你有一定的参考价值。
try { string sheetname = TextBox1.Text.Trim(); HttpPostedFile upLoadPostFile = FileUpload1.PostedFile; string upLoadPath = FileUpload1.PostedFile.FileName; if (upLoadPath == "") { ShowAlertMessage("请选择上传文件!"); return; } string excelType = upLoadPath.Split(‘.‘)[1].ToString(); if (excelType != "xls" && excelType != "xlsx") { ShowAlertMessage("此文件不是xls或者xlsx格式,请重新选择上传文件格式!"); } else { InvoiceData.PutInvoiceJsonByExcel(sheetname, upLoadPostFile); ShowAlertMessage("发送开票请求完毕!"); } } catch (Exception ex) { CustomValidator1.ErrorMessage = ex.Message; CustomValidator1.IsValid = false; }
public static void PutInvoiceJsonByExcel(string sheetName, HttpPostedFile upLoadPostFile) { try { //创建一个数据链接 StringBuilder strCon = new StringBuilder(); strCon.Append("Provider=Microsoft.ACE.OLEDB.12.0;"); strCon.Append("Data Source=" + upLoadPostFile.FileName + ";"); strCon.Append("Extended Properties="Excel 12.0;IMEX=1;""); OleDbConnection myConn = new OleDbConnection(strCon.ToString()); string strCom = "SELECT * FROM [" + sheetName + "$] "; myConn.Open(); //打开数据链接,得到一个数据集 OleDbDataAdapter myCommand = new OleDbDataAdapter(strCom, myConn); DataSet myDataSet = new DataSet(); //得到自己的DataSet对象 myCommand.Fill(myDataSet, sheetName); myConn.Close(); myConn.Dispose(); foreach (DataRow dr in myDataSet.Tables[0].Rows) { string strOrderSn = dr[0].ToString().Trim(); DataTable dt = OrderData.GetInvoiceByOrderSn(strOrderSn); InvoiceData.PutInvoiceJson(dt); } } catch (Exception ex) { throw new Exception("PutInvoiceJsonByExcel Error: " + ex.Message); } }
以上是关于Excel 批量出来数据的主要内容,如果未能解决你的问题,请参考以下文章