Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public static MemoryStream CreateExcel()
FileStream imageStream = new FileStream("AdventureCycles-Logo.png", FileMode.Open, FileAccess.Read);
IPictureShape shape = worksheet.Pictures.AddPicture(1, 1, imageStream, 20, 20);

imageStream.Dispose();

//Disable gridlines in the worksheet
worksheet.IsGridLinesVisible = false;

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -26,34 +26,48 @@ public IActionResult Index()
}
public IActionResult EditDocument()
{
//Create an instance of ExcelEngine
using (ExcelEngine excelEngine = new ExcelEngine())
{

//Instantiate the Excel application object
IApplication application = excelEngine.Excel;

//Assigns default application version
application.DefaultVersion = ExcelVersion.Xlsx;

//A existing workbook is opened.
//A existing workbook is opened.
IWorkbook workbook = application.Workbooks.Open("InputTemplate.xlsx");

//Access first worksheet from the workbook.
IWorksheet worksheet = workbook.Worksheets[0];

//Set Text in cell A3.
//Set the text in cell A3.
worksheet.Range["A3"].Text = "Hello World";

//Saving the Excel to the MemoryStream
//Access a cell value from Excel
var value = worksheet.Range["A1"].Value;

//Defining the ContentType for the Excel file.
string ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

//Define the file name.
string fileName = "EditExcel.xlsx";

//Creating stream object.
MemoryStream stream = new MemoryStream();

//Saving the workbook to the stream in XLSX format.
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 = "EditExcel.xlsx";
return fileStreamResult;
//Closing the workbook and disposing the engine.
workbook.Close();
excelEngine.Dispose();

//Creates a FileStreamResult object by using the file contents, content type, and file name.
return File(stream, ContentType, fileName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/// <summary>
/// Create and download the Excel document
/// </summary>
protected async void CreateDocument()
protected async Task CreateDocument()
{
excelStream = service.CreateExcel();
await JS.SaveAs("Sample.xlsx", excelStream.ToArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/// <summary>
/// Edit and download the Excel document
/// </summary>
protected async void EditDocument()
protected async Task EditDocument()
{
excelStream = service.EditExcel();
await JS.SaveAs("Sample.xlsx", excelStream.ToArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/// <summary>
/// Create and download the Excel document
/// </summary>
protected async void CreateExcel()
protected async Task CreateExcel()
{
excelStream = service.CreateDocument();
await JS.SaveAs("CreateExcel.xlsx", excelStream.ToArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/// <summary>
/// Create and download the Excel document
/// </summary>
protected async void EditExcel()
protected async Task EditExcel()
{
excelStream = service.EditDocument();
await JS.SaveAs("EditExcel.xlsx", excelStream.ToArray());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ private void CreateExcel(object sender, RoutedEventArgs e)
Save(stream, "CreateExcel");
}
}
async void Save(MemoryStream stream, string filename)
async Task Save(MemoryStream stream, string filename)
{

StorageFile stFile;
Expand Down
Loading