Ejemplo n.º 1
0
        public async Task <IActionResult> SearchExcel([FromBody] AuditRecSearch model)
        {
            var data = await _service.SearchExcel(model, "2");

            var path = Path.Combine(_webHostEnvironment.ContentRootPath, "Resources\\Template\\WT_Summary.xlsx");
            WorkbookDesigner designer = new WorkbookDesigner();

            designer.Workbook = new Workbook(path);
            //lưu data với ASPO vào excel
            designer.SetDataSource("result", data);
            designer.Process();
            Worksheet ws = designer.Workbook.Worksheets[0];

            for (var i = 1; i <= data.Count; i++)
            {
                var filePathB4    = "wwwroot\\uploaded\\images\\" + data[i - 1].Before_Picture;
                var filePathAfter = "wwwroot\\uploaded\\images\\" + data[i - 1].After_Picture;

                if (System.IO.File.Exists(filePathB4))
                {
                    var pictureIndex = ws.Pictures.Add(i, 17, filePathB4);
                    Aspose.Cells.Drawing.Picture picture = ws.Pictures[pictureIndex];
                    picture.Width  = 100;
                    picture.Height = 100;
                    //margin
                    picture.Top  = 3;
                    picture.Left = 3;
                    //set lại Height cho dòng có image
                    ws.Cells.Rows[i].Height = 80;
                }
                if (System.IO.File.Exists(filePathAfter))
                {
                    //Add picture và set Size cho image
                    var pictureIndex = ws.Pictures.Add(i, 18, filePathAfter);
                    Aspose.Cells.Drawing.Picture picture = ws.Pictures[pictureIndex];
                    picture.Width  = 100;
                    picture.Height = 100;
                    //margin
                    picture.Top  = 3;
                    picture.Left = 3;
                    //set lại Height cho dòng có image
                    ws.Cells.Rows[i].Height = 80;
                }
            }
            MemoryStream stream = new MemoryStream();

            if (data.Count != 0)
            {
                designer.Workbook.Save(stream, SaveFormat.Xlsx);
            }
            // designer.Workbook.Save (path + "Test.xlsx", SaveFormat.Xlsx);

            byte[] result = stream.ToArray();

            return(File(result, "application/xlsx", "WT_Summary" + DateTime.Now.ToString("dd_MM_yyyy_HH_mm_ss") + ".xlsx"));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> GetSearchExcel([FromBody] AuditRecSearch model)
        {
            var auditRecs = await _service.SearchExcel(model);

            return(Ok(auditRecs));
        }