Aspose.Cells 下载导出Excel插入图片

 前端


    $("#ExcelImg").click(function () {

       $.post("ExcelSet", function (data) {
window.location.href=data

        }

        window.location.href = "@Html.Raw(Url.Action("Export_G_SUP_STOREInfoExcelImg", new { condition = "_condition_"}))".replace('_condition_',  JSON.stringify(searchData()));
    });

后端

public ActionResult ExcelSet(string condition)
        {
                Workbook workbook = new Workbook();
                Worksheet worksheet = workbook.Worksheets[0];
//各种内容设置

//插入图片  行坐标,纵坐标,图片路径
int pictureIndex = worksheet.Pictures.Add(2 + i, 16 + a + 1, filename);
 //Accessing the newly added picture
 Aspose.Cells.Drawing.Picture picture = worksheet.Pictures[pictureIndex];
picture.Placement = Aspose.Cells.Drawing.PlacementType.FreeFloating;
 picture.Width = 100;//设置图片大小
 picture.Height = 60;


 return ExcelFilet(workbook, "名字" + DateTime.Now.ToString("yyyyMMdd") + ".xlsx");

}


        protected ActionResult ExcelFilet(Workbook workbook, string fileName)
        {
            if (workbook == null)
            {
                return Content("找不到excel");
            }


            MemoryStream ms = new MemoryStream();
            workbook.Save(ms, new XlsSaveOptions(SaveFormat.Xlsx));
            ms.Seek(0, SeekOrigin.Begin);
            return File(ms, @"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet.main+xml", fileName);
        }

你可能感兴趣的:(c#.net,mvc,前端,javascript,开发语言)