예제 #1
0
        public void TestNpoiExcelExport()
        {
            ServiceCollection services = new ServiceCollection();

            services.AddNpoiOffice();
            IServiceProvider serviceProvider = services.BuildServiceProvider();
            IOffice          office          = serviceProvider.GetRequiredService <IOffice>();
            string           fileName        = Guid.NewGuid().ToString();

            office.ExportToExcel(GetDemoDatas(), $"{fileName}.xlsx", new ExportOption()
            {
                SheetName = "sheet3"
            });
            Assert.IsTrue(File.Exists($"{fileName}.xlsx"));
        }
예제 #2
0
        public void TestNpoiExcelImport()
        {
            ServiceCollection services = new ServiceCollection();

            services.AddNpoiOffice();
            IServiceProvider serviceProvider = services.BuildServiceProvider();
            IOffice          office          = serviceProvider.GetRequiredService <IOffice>();
            string           fileName        = Guid.NewGuid().ToString();

            office.ExportToExcel(GetDemoDatas(), $"{fileName}.xlsx", new ExportOption()
            {
                SheetName = "sheet3"
            });
            var result = office.ImportFromExcel <DemoData>($"{fileName}.xlsx");

            Assert.IsNotNull(result);
            Assert.IsTrue(result.Any());
        }