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.

The issues you have found earlier (filed as CELLSNET-56735) have been fixed in this update. This message was posted using Bugs notification tool by johnson.shi

Thanks, I can confirm that it works fine now.

But an additional question: is it possible to disable the sheet bar context menu? Here, I can still delete the sheets though it was opened readonly.
sheetbar_contextmenu.png (7.5 KB)

I see that I can hide the bar completely (this.gridDesktop1.SheetsBarVisible = false;), but we might show workbooks with multiple sheets. So it is required for us.

@wknauf,

In Aspose.Cells for GridDesktop, there isn’t a direct property or method to completely disable the context menu for the sheet bar. This is same with MS Excel as default behavior. However, we can look into your desired option/requirements. 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-56968

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,

This is to inform you that your issue (Ticket ID: “CELLSNET-56968”) has been resolved. The fix/enhancement will be included in an upcoming release (Aspose.Cells.GridDesktop v25.5) that we plan to release either this week or in the next week of May 2025. You will be notified when the next version is released.

@wknauf
The issues you have found earlier (filed as CELLSNET-56968) have been fixed in this v25.5 release

@peter.zhou Thanks! But this fix introduces a regression: if you right click the sheet bar without first focusing the sheet data, the sheet bar shows a wrong context menu (and everything is enabled):

After having clicked the sheet content, everything works fine - no context menu is shown any more in read only mode.

@wknauf
Yes,we can reproduce it.
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-58385

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,

We are pleased to inform you that your issue (Ticket: “CELLSNET-58385 - Right click the sheet bar without first focusing the sheet data, the sheet bar shows a wrong context menu”) has been resolved. The fix/enhancement will be included in an upcoming release (Aspose.Cells.GridDesktop v25.6) that we plan to release in the first half of June 2025. You will be notified when the next version is released.

@wknauf
Please try the update.
We will release the official v25.6 release which includes this fix in next month.

Perfect, I can confirm that the sheet bar context menu is not shown any longer in read only mode.

Many thanks!

@wknauf
You are welcome! We will notify you here when we release 25.6 in the next month.