Skip to content

Commit

Permalink
Loading and Saving
Browse files Browse the repository at this point in the history
  • Loading branch information
Kurmitha4004 committed Aug 1, 2024
1 parent 762c417 commit 174c54b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,42 +17,34 @@ public HomeController(ILogger<HomeController> logger)
}
public async Task<IActionResult> EditDocument()
{
try
using (ExcelEngine excelEngine = new ExcelEngine())
{
//Retrieve the document from DropBox
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;

//Download the document from DropBox
MemoryStream stream = await GetDocumentFromDropBox();

//Set the position as '0'
stream.Position = 0;

using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Xlsx;
//Load the downloaded document
IWorkbook workbook = application.Workbooks.Open(stream);

//Load the downloaded document
IWorkbook workbook = application.Workbooks.Open(stream);
IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Range["A3"].Text = "Hello world";

IWorksheet worksheet = workbook.Worksheets[0];
worksheet.Range["A3"].Text = "Hello world";
//Saving the Excel to the MemoryStream
MemoryStream outputStream = new MemoryStream();
workbook.SaveAs(outputStream);

//Saving the Excel to the MemoryStream
MemoryStream outputStream = new MemoryStream();
workbook.SaveAs(outputStream);

//Set the position as '0'
outputStream.Position = 0;
//Set the position as '0'
outputStream.Position = 0;

//Download the Excel file in the browser
FileStreamResult fileStreamResult = new FileStreamResult(outputStream, "application/excel");
fileStreamResult.FileDownloadName = "EditExcel.xlsx";
return fileStreamResult;
}
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex.Message}");
return Content("Error occurred while processing the file.");
//Download the Excel file in the browser
FileStreamResult fileStreamResult = new FileStreamResult(outputStream, "application/excel");
fileStreamResult.FileDownloadName = "EditExcel.xlsx";
return fileStreamResult;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<ItemGroup>
<PackageReference Include="Dropbox.Api" Version="7.0.0" />
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="26.2.7" />
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<ItemGroup>
<PackageReference Include="Dropbox.Api" Version="7.0.0" />
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="26.2.7" />
<PackageReference Include="Syncfusion.XlsIO.Net.Core" Version="*" />
</ItemGroup>

</Project>

0 comments on commit 174c54b

Please sign in to comment.