0
엑셀 파일 업로드 작업 중입니다. 다음과 같이 datatable
으로 변환했습니다.엑셀 시트 업로드 및 다른 모델 클래스 매핑하기
public static DataTable ConvertExcelFileToDataTable(HttpPostedFileBase upload)
{
// ExcelDataReader works with the binary Excel file, so it needs a FileStream
// to get started. This is how we avoid dependencies on ACE or Interop:
Stream stream = upload.InputStream;
IExcelDataReader reader = null;
if (upload.FileName.EndsWith(".xls"))
{
reader = ExcelReaderFactory.CreateBinaryReader(stream);
}
else if (upload.FileName.EndsWith(".xlsx"))
{
reader = ExcelReaderFactory.CreateOpenXmlReader(stream);
}
reader.IsFirstRowAsColumnNames = true;
DataTable dtProductCatalog = reader.AsDataSet().Tables[0];
reader.Close();
return dtProductCatalog;
}
지금 내가 datatable column
은 어떤 모델에 변환되는 것을 포함하는 매퍼 타입 일을 만들려고합니다. 그리고 datatable
을 각각의 모델 목록으로 변환하십시오. 나는 그걸 어떻게 시작해야할지 모르겠다.
한 방법으로 3 개의 열을 유지하는 방법은 무엇입니까? – Sana
내가 원하는대로 디자인을 변경했습니다. 모델은 이제 "Model1"입니다. 이제 팩토리는 채우려는 모델 이름을 사용합니다. 각 모델에는 필요에 따라 필드를 채우기 위해 모든 열 값을 사용할 수 있도록 데이터 테이블을 가져 오는 자체 overrideable populate 메소드가 있습니다. – Wheels73
위와 같이 Excelable 열 사이의 매핑 방법이 datatable 단계없이 직접 다른 모델 목록에 있습니다. – Sana