我正在做一个项目,我从一个excel文件中读取多个字段并将它们保存在db中。如果用户输入错误的值,如何在页面上显示多个错误消息。Aspose.cells 用于读取数据。我的代码是
public List<Data> ImportFromExcel(Stream bytes, out bool isFine)
{
isFine = true;
DateTime DOJ;
List<Data> list = new List<Data>();
DataTable dt = new DataTable();
Workbook workBook = new Workbook();
workBook.Open(bytes);
Worksheet workSheet = workBook.Worksheets[0];
try
{
dt = workSheet.Cells.ExportDataTable(0, 0, workSheet.Cells.MaxRow + 1, workSheet.Cells.MaxColumn + 1, true);
}
catch (Exception ex)
{
isFine = false;
ShowMessage("Your file has some invalid formats of data. Please review it and try again.", MessageType.Error, true);
return null;
}
try
{
int i = 1;
foreach (DataRow reader in dt.Rows)
{
if (reader["LetterId"].ToString().Length > 75)
{
isFine = false;
ShowMessage("In Row Number " + i + " Letter Id cannot exceed 75 characters.", MessageType.Error, true);
return null;
}
if (reader["Subject"].ToString().Length > 75)
{
isFine = false;
ShowMessage("In Row Number " + i + " Subject cannot exceed 75 characters.", MessageType.Error, true);
return null;
}
.
.
.
Show message 方法仅显示单个错误消息。