The code is simple , but result is strange.
- Code: Select all
[HttpGet("excel")]
public ActionResult Excel()
{
using (var workbook = new Workbook())
{
workbook.CustomFontFilePaths = new string[] { "msyh.ttf" };
Worksheet sheet = workbook.Worksheets[0];
sheet.Range["A1"].Text = "Hello,World!";
var image = sheet.ToImage(1, 1, sheet.LastRow, sheet.LastColumn);
using (var sheetms = new MemoryStream())
{
image.Save(sheetms, ImageFormat.Png);
return File(sheetms.ToArray(), "image/png");
}
}
}
And this is the font file where i downloaded:
github.com/chenqing/ng-mini/blob/master/font/msyh.ttf