Example #1
0
        public IActionResult GetOutExcel()
        {
            PagedAndSortedResultRequestDto resultRequestDto = new PagedAndSortedResultRequestDto()
            {
                MaxResultCount = 200000, SkipCount = 0, Sorting = "Id"
            };
            var data = _alarmAppService.GetListAsync(resultRequestDto);
            var list = data.Result.Items.ToList();

            DataTable dataTable  = ListToDataTable.toDataTable <AlarmDto>(list);
            var       pathname   = $"{System.AppDomain.CurrentDomain.BaseDirectory}Basics\\OutExcel.xlsx";
            var       requst     = ExcelHelper.DataTableToExcel(dataTable, pathname, "Sheet1", true);
            var       stream     = System.IO.File.OpenRead(pathname);
            string    fileExt    = Path.GetExtension(pathname);
            var       provider   = new FileExtensionContentTypeProvider();
            var       meni       = provider.Mappings[fileExt];
            var       returnFile = File(stream, meni, Path.GetFileName(pathname));

            return(returnFile);
        }
Example #2
0
        public IActionResult GetOutExcel(QueryCondition condition)
        {
            PagedSortedRequestDto resultRequestDto = new PagedSortedRequestDto()
            {
                MaxResultCount = 1000, SkipCount = 0
            };
            var data = _cameraRepairAppService.GetRepairsListByCondition(condition, resultRequestDto);
            var list = data.Items.ToList();

            DataTable dataTable = ListToDataTable.toDataTable <RequstCameraRepairDto>(list);


            var    pathname   = $"{System.AppDomain.CurrentDomain.BaseDirectory}Basics\\OutExcel.xlsx";
            var    requst     = ExcelHelper.DataTableToExcel(dataTable, pathname, "Sheet1", true);
            var    stream     = System.IO.File.OpenRead(pathname);
            string fileExt    = Path.GetExtension(pathname);
            var    provider   = new FileExtensionContentTypeProvider();
            var    meni       = provider.Mappings[fileExt];
            var    returnFile = File(stream, meni, Path.GetFileName(pathname));

            return(returnFile);
        }