1

I have implemented the code below, all headers and data are added without any problem. If he wants to block the possibility of editing individual fields or columns in the excel file that is downloaded by the user, then there is a problem, because nothing is blocked

i use for freeze columns/rows, but when i export file and i open file i can edit any fields worksheet.SheetView.Freeze(1,3);

    [HttpGet]
    public IActionResult ExportAsExcel()
    {
        IEnumerable<Employee> employees = this.repo.GetAll<Employee>();
        List<EmployeeDTO> employeeDTO = this._mapper.Map<List<EmployeeDTO>>(employees);

        using (var workbook = new XLWorkbook())
        {
            var woorksheet = workbook.Worksheets.Add("Sheet1");
            var currentRow = 1;

            woorksheet.Cell(currentRow, 1).Value = "ID";
            woorksheet.Cell(currentRow, 2).Value = "name";
  

            foreach (var empDtos in employeeDTO)
            {
                currentRow++;
                woorksheet.Cell(currentRow, 1).Value = empDtos.EmployeeId;
                woorksheet.Cell(currentRow, 2).Value = empDtos.Name;
            }


            using (var stream = new MemoryStream())
            {
                workbook.SaveAs(stream);
                var content = stream.ToArray();

                return File(
                    content,
                    "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                    "Employee.xlsx"
                    );
            }
        }
    }
WiceJav
  • 75
  • 5

1 Answers1

0

Freezing a column/row means that while scrolling, the frozen area stays within view.

If you want to protect the document from editing, I would look into sheet protection.

Wolfware
  • 51
  • 4