-
StackOverflow 文档
-
epplus 教程
-
从现有文件导入数据
-
使用 FileUpload Control 从 Excel 文件导入数据
//check if there is actually a file being uploaded
if (FileUpload1.HasFile)
{
//load the uploaded file into the memorystream
using (MemoryStream stream = new MemoryStream(FileUpload1.FileBytes))
using (ExcelPackage excelPackage = new ExcelPackage(stream))
{
//loop all worksheets
foreach (ExcelWorksheet worksheet in excelPackage.Workbook.Worksheets)
{
//loop all rows
for (int i = worksheet.Dimension.Start.Row; i <= worksheet.Dimension.End.Row; i++)
{
//loop all columns in a row
for (int j = worksheet.Dimension.Start.Column; j <= worksheet.Dimension.End.Column; j++)
{
//add the cell data to the List
if (worksheet.Cells[i, j].Value != null)
{
excelData.Add(worksheet.Cells[i, j].Value.ToString());
}
}
}
}
}
}