Hi Shamini,
I understand how Protected View works, but I get weird results.
My code looks like this:
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2016;
FileStream inputStream = new FileStream("test.xlsx", FileMode.Open, FileAccess.Read);
IWorkbook workbook = application.Workbooks.Open(inputStream);
IWorksheet visualizationSheet = workbook.Worksheets[0];
IWorksheet dataSheet = workbook.Worksheets[1];
DataTable dataTable = SampleDataTable();
dataSheet.ImportDataTable(dataTable, false, 1, 1);
visualizationSheet.EnableSheetCalculations();
//string value = visualizationSheet.Range["A1"].CalculatedValue;
//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;
}
I've attached two files, the only difference is that I commented this line in the second file:
string value = visualizationSheet.Range["A1"].CalculatedValue;
see results:
both files are opened in protected view, but the one that was created with an uncommented line shows the calculated value.
I think that when I try to read that calculated value it is somehow updated in the output excel file, so excel don't need to calculate it again when I open the file (it can't recalculate in protected view).
This is my requirement. I want to recalculate all formulas and update the values in the saved file, so when it is sent via email and someone will open it in protected view he will see the correct values.
Sorry for not describing everything correctly, but I hope now everything will be clear.
Best regards,
Tomasz
Attachment:
Test_c97aed32.zip