Example #1
0
        public ActionResult Index(SelectionResult selectionResult)
        {
            ReportTemplateResult result = ToReportTemplate(selectionResult);
            string shortName            = DateTime.Now.ToString("yyyyMMdd-hhmmss");
            string filename             = HttpContext.Server.MapPath(@"~/App/temp/") + shortName + ".docx";

            result.Filename = shortName;
            using (DocxGenerator gen = new DocxGenerator(HttpContext.Server.MapPath(@"~/App/docTemplate/选型简表结果.docx")))
            {
                gen.AddMachinePicture(MapPath(result.MachinePicture))
                .AddSimulationPictures(MapPath(result.SimulationPictures.ToArray()))
                .AddContent(result)
                .SaveAs(filename);
            }
            return(View(result));
        }
        public IActionResult GenerateDocument([FromQuery] string fileID, [FromQuery] string userName, [FromBody] SelectionResult selectionResult)
        {
            if (string.IsNullOrEmpty(fileID) || fileID == "null")
            {
                return(BadRequest());
            }
            if (string.IsNullOrEmpty(userName) || userName == "null")
            {
                return(BadRequest());
            }
            string workPath             = Path.Combine(_webRootPath, "Users", userName, fileID, "report");
            ReportTemplateResult result = ToReportTemplate(selectionResult, workPath);
            string shortName            = "选型结果简表";
            string filename             = Path.Combine(workPath, shortName + ".docx");

            using (DocxGenerator gen = new DocxGenerator(MapPath(@"选型简表结果.docx")))
            {
                gen.AddMachinePicture(MapPath(result.MachinePicture))
                .AddSimulationPictures(result.SimulationPictures.ToArray())
                .AddContent(result)
                .SaveAs(filename);
            }
            return(Created(Path.Combine("Users", userName, fileID, "report"), null));
        }