示例#1
0
        public void ConvertXlsBytesTest()
        {
            var models = GetModels();
            var bytes  = ExcelHelper.ObjectToExcelBytes(models);

            Assert.IsTrue(bytes.Length > 0);
            var importer = new ExcelImporter();
            var result   = importer.ExcelToObject <ReportModel>(bytes).ToList();

            models.AreEqual(result);
        }
示例#2
0
        public void ConvertXlsxBytesTest()
        {
            var models = GetModels();
            var array  = ExcelHelper.ObjectToExcelBytes(models, ExcelType.Xlsx);

            Assert.IsTrue(array.Length != 0);
            var excelImporter = new ExcelImporter();
            var result        = excelImporter.ExcelToObject <ReportModel>(array).ToList();

            models.AreEqual(result);
        }
示例#3
0
        public void ConvertTest1()
        {
            var models = GetModels();
            var bytes  = ExcelHelper.ObjectToExcelBytes(models);


            Assert.IsTrue(bytes.Length > 0);
            var importer = new ExcelImporter();
            var result   = importer.ExcelToObject <ReportModel>(bytes);

            Assert.AreEqual(models.Count, result.Count());
        }
示例#4
0
        public void ConvertXlsFileUseObjectToExcelTest()
        {
            var models = GetModels();
            var path   = GetFilePath("test.xls");

            ExcelHelper.ObjectToExcel(models, path);
            Assert.IsTrue(File.Exists(path));
            var importer = new ExcelImporter();
            var result   = importer.ExcelToObject <ReportModel>(path).ToList();

            Assert.AreEqual(models.Count, result.Count);
            models.AreEqual(result);
        }
示例#5
0
 public void Test()
 {
     var models = GetModels();
     var exporter = new ExcelExporter();
     var bytes = exporter.ObjectToExcelBytes(models);
     var path = GetFilePath("text.xls");
     Console.WriteLine(path);
     File.WriteAllBytes(path, bytes);
     Assert.IsTrue(File.Exists(path));
     var importer = new ExcelImporter();
     var result = importer.ExcelToObject<ReportModel>(path);
     Assert.AreEqual(models.Count, result.Count());
 }
示例#6
0
        public void ConvertTest()
        {
            var models = GetModels();
            var bytes  = ExcelHelper.ObjectToExcelBytes(models);
            var path   = GetFilePath("text.xls");

            File.WriteAllBytes(path, bytes);
            Assert.IsTrue(File.Exists(path));
            var importer = new ExcelImporter();
            var result   = importer.ExcelToObject <ReportModel>(path);

            Assert.AreEqual(models.Count, result.Count());
        }
示例#7
0
        public void EmptyFirstProperty()
        {
            var models = GetModels();
            var bytes  = ExcelHelper.ObjectToExcelBytes(models);

            Assert.IsNotNull(bytes);
            Assert.IsTrue(bytes.Length > 0);
            var importer = new ExcelImporter();
            var result   = importer.ExcelToObject <ReportModel>(bytes).ToList();

            Console.WriteLine(result.FirstOrDefault());
            Assert.AreEqual(models.Count, result.Count());
            models.AreEqual(result);
        }
示例#8
0
            public static IEnumerable <TModel> ExcelToObject <TModel>(string path, string sheetname) where TModel : class, new()
            {
                var importer = new ExcelImporter();

                return(importer.ExcelToObject <TModel>(path, sheetname));
            }