asp.net導入後臺代碼
public void Upload(string information){
int Bank = 0;
for (int i = 0; i <Request.Files.Count; i++)
{
var httpfile = Request.Files[i];
string getFileName= httpfile.FileName;
string getfile= getFileName.Substring(getFileName.LastIndexOf("."));
IWorkbook workbook = null;
if (getfile.Equals(".xls"))
{
workbook = new HSSFWorkbook(httpfile.InputStream);
}
if (getfile.Equals(".xlsx"))
{
workbook = new XSSFWorkbook(httpfile.InputStream);
}
ISheet sheet= workbook.GetSheetAt(0);
for (int k = 1; k <7; k++)
{
IRow cells = sheet.GetRow(k);
string sql = string.Format("insert into " + information + "(StudentName,StudentAge) values(");
for (int j = 0; j < cells.LastCellNum; j++)
{
string value = cells.GetCell(j)+"";
sql += string.Format("‘" + value.ToString() + "‘,");
}
sql = sql.Substring(0, sql.Length - 1) + ")";
Bank= DBHelper1.ExecuteNonQuery(sql);
}
}
}
asp.net導入後臺代碼