GridDesktop: readonly grid

I want to show an excel file and prevent the user from editing it. But I fail to make it readonly.

I tried:

  • GridDesktop.ImportExcelFile with parameter “openasReadOnly = true”

  • “gridDesktop.Worksheets[0].SetAllCellsReadonly()”

  • “gridDesktop.Worksheets[0].Protected = true” (source: Aspose.grid.desktop does'nt support readonly mode? )

  • setting “locked” in style for all cells:

    for (int r = 0; r < this.gridDesktop1.Worksheets[0].RowsCount; r++)
    {
      for (int c = 0; c < this.gridDesktop.Worksheets[0].ColumnsCount; c++)
      {
        Style s = this.gridDesktop.Worksheets[0].Cells[r, c].GetStyle();
        s.CellLocked = true;
        this.gridDesktop.Worksheets[0].Cells[r, c].SetStyle(s);
      }
    }
    

None of them seem to have the effect that I expected.

Attached is a small sample.
GridDesktopReadonly.zip (11.3 KB)

@wknauf,

After initial testing, I am able to reproduce the issue as you mentioned. I could not make the Aspose.Cells.GridDesktop control read-only.

We require thorough evaluation of the issue. We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): CELLSNET-56735

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@wknauf
Sorry for the inconvenience, the openAsReadOnly does not take effect.
We will fix it soon.
For the workaround, you need to do init work after the file is loaded,
Please try the below code:

  private void button1_Click(object sender, EventArgs e)
        {
            this.gridDesktop1.ImportExcelFile(@"C:\Users\peter\Downloads\test.xlsx");
            this.gridDesktop1.FinishLoadFile += gridDesktop1_Finish;
        }
//you may do init work after the file is loaded
        private void gridDesktop1_Finish(object sender, WorkBookEvents args)
        {
            for (int i = 0; i < this.gridDesktop1.Worksheets.Count; i++)
            {
                this.gridDesktop1.Worksheets[i].SetAllCellsReadonly();
            }
        }

@wknauf,

Moreover, we are pleased to inform you your issue (Ticket ID: “CELLSNET-56735”) has been resolved now. The fix/enhancement will be incorporated in the next release (Aspose.Cells v24.10 package) scheduled for the first half of October 2024. You will receive a notification once the new release is available.