私はExcelファイルのアップロードに取り組んでいます。私はdatatable
に以下のように変換しました。Excelシートをアップロードし、異なるモデルクラスにマッピングする
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つの列を1つのモデルに保存するにはどうしたらいいですか? – Sana
私はあなたが必要とするようにデザインを変更しました。モデルは現在 "Model1"です。ファクトリは、設定するモデル名を取得するようになりました。各モデルには、データ表を取り込むための任意の列値を必要に応じてフィールドに取り込むことができる独自のオーバーライド可能な作成メソッドがあります。 – Wheels73
ExcelとExcelの間のマッピング方法はありますか? – Sana