diff --git a/Document-Processing-toc.html b/Document-Processing-toc.html index 26c1bfa6f..c1894ca35 100644 --- a/Document-Processing-toc.html +++ b/Document-Processing-toc.html @@ -6748,17 +6748,17 @@
  • How to remove all the ListObjects from the sheet?
  • -
  • +
  • How to assign cell value without changing the format type in XlsIO?
  • How to retrieve data from merged cells using XlsIO?
  • -
  • +
  • How to convert inches to points in Syncfusion XlsIO? -
  • -
  • - How to preserve line breaks when saving Excel as CSV? +
  • +
  • + How to preserve line breaks when saving Excel as CSV?
  • Why does text with double quotes get enclosed in double quotes when saving as CSV? @@ -6766,12 +6766,15 @@
  • How to detect whether a column is hidden in an Excel file using XlsIO?
  • -
  • +
  • How to set invert if negative option for a chart using XLsIO?
  • -
  • +
  • How to merge cells preserving topleft value and format in XlsIO?
  • +
  • + How to open Excel file as ReadOnly in Microsoft Excel using XlsIO? +
  • diff --git a/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-open-excel-file-as-readonly-option-in-microsoft-excel-using-xlsio.md b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-open-excel-file-as-readonly-option-in-microsoft-excel-using-xlsio.md new file mode 100644 index 000000000..ce1898a04 --- /dev/null +++ b/Document-Processing/Excel/Excel-Library/NET/faqs/how-to-open-excel-file-as-readonly-option-in-microsoft-excel-using-xlsio.md @@ -0,0 +1,94 @@ +--- +title: How to Open Excel as Read‑Only using XlsIO | Syncfusion +description: Shows how to set the 'Read-only recommended' flag when saving an Excel workbook with Syncfusion XlsIO so Excel prompts to open it as read-only. +platform: document-processing +control: XlsIO +documentation: UG +--- + +# How to open Excel file as ReadOnly in Microsoft Excel using XlsIO? + +You can make Excel prompt users to open a workbook as read-only by setting the Read-only recommended flag on the workbook before saving. The example below shows how to set this flag with Syncfusion XlsIO and save the file so Microsoft Excel offers the "Read-only recommended" option when the file is opened. + +The following code examples illustrate this. + +{% tabs %} +{% highlight c# tabtitle="C# [Cross-platform]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + // Instantiate the Excel application object + IApplication application = excelEngine.Excel; + + // Assigns default application version + application.DefaultVersion = ExcelVersion.Xlsx; + + // Create a workbook with 1 worksheet + IWorkbook workbook = application.Workbooks.Create(1); + + // Access first worksheet from the workbook + IWorksheet worksheet = workbook.Worksheets[0]; + + // Adding text to a cell + worksheet.Range["A1"].Text = "Hello World"; + + // Protect the worksheet + worksheet.Protect("syncfusion", ExcelSheetProtection.All); + + // Save the workbook to disk in XLSX format + workbook.SaveAs(Path.GetFullPath("Output/Output.xlsx")); +} +{% endhighlight %} + +{% highlight c# tabtitle="C# [Windows-specific]" %} +using (ExcelEngine excelEngine = new ExcelEngine()) +{ + // Instantiate the Excel application object + IApplication application = excelEngine.Excel; + + // Assigns default application version + application.DefaultVersion = ExcelVersion.Xlsx; + + // Create a workbook with 1 worksheet + IWorkbook workbook = application.Workbooks.Create(1); + + // Access first worksheet from the workbook + IWorksheet worksheet = workbook.Worksheets[0]; + + // Adding text to a cell + worksheet.Range["A1"].Text = "Hello World"; + + // Protect the worksheet + worksheet.Protect("syncfusion", ExcelSheetProtection.All); + + // Save the workbook to disk in XLSX format + workbook.SaveAs("Output.xlsx"); +} +{% endhighlight %} + +{% highlight vb.net tabtitle="VB.NET [Windows-specific]" %} +Using excelEngine As New ExcelEngine() + ' Instantiate the Excel application object + Dim application As IApplication = excelEngine.Excel + + ' Assigns default application version + application.DefaultVersion = ExcelVersion.Xlsx + + ' Create a workbook with 1 worksheet + Dim workbook As IWorkbook = application.Workbooks.Create(1) + ' Access first worksheet from the workbook + Dim worksheet As IWorksheet = workbook.Worksheets(0) + + ' Adding text to a cell + worksheet("A1").Text = "Hello World" + + ' Protect the worksheet + worksheet.Protect("syncfusion", ExcelSheetProtection.All) + + ' Save the workbook to disk in XLSX format + workbook.SaveAs("Sample.xlsx") +End Using +{% endhighlight %} +{% endtabs %} + + +A complete working example in C# is present on this GitHub page.