using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application =
excelEngine.Excel;
application.DefaultVersion =
ExcelVersion.Excel2013;
IWorkbook workbook =
application.Workbooks.Create(1);
IWorksheet sheet =
workbook.Worksheets[0];
ITextBoxShape textbox =
sheet.TextBoxes.AddTextBox(2, 2, 30, 200);
textbox.Text = "TextBox";
IRichTextString richText =
textbox.RichText;
IFont font = workbook.CreateFont();
font.Bold = true;
font.RGBColor = Color.Red;
richText.SetFont(0, 6, font);
//Saving the Excel to the MemoryStream
MemoryStream stream = new
MemoryStream();
workbook.SaveAs(stream);
//Set the position as '0'.
stream.Position = 0;
//Download the Excel file in the
browser
FileStreamResult fileStreamResult = new
FileStreamResult(stream, "application/excel");
fileStreamResult.FileDownloadName =
"Output.xlsx";
return fileStreamResult;
}
|