Skip to content
14 changes: 7 additions & 7 deletions Document-Processing-toc.html
Original file line number Diff line number Diff line change
Expand Up @@ -6748,28 +6748,28 @@
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-remove-all-the-listobjects-from-the-sheet">How to remove all the ListObjects from the sheet?</a>
</li>
<li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-assign-cell-value-without-changing-format-type-in-xlsio">How to assign cell value without changing the format type in XlsIO?</a>
</li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-retrieve-data-from-merged-cells-using-xlsio">How to retrieve data from merged cells using XlsIO?</a>
</li>
<li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-convert-inches-to-points-in-syncfusion-xlsio">How to convert inches to points in Syncfusion XlsIO?</a>
</li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-preserve-line-breaks-when-saving-excel-as-csv">How to preserve line breaks when saving Excel as CSV?</a>
</li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-preserve-line-breaks-when-saving-excel-as-csv">How to preserve line breaks when saving Excel as CSV?</a>
</li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/why-text-with-double-quotes-gets-enclosed-in-double-quotes-when-saving-as-csv">Why does text with double quotes get enclosed in double quotes when saving as CSV?</a>
</li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-detect-whether-a-column-is-hidden-in-an-excel-file-using-xlsio">How to detect whether a column is hidden in an Excel file using XlsIO?</a>
</li>
<li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-set-invert-if-negative-option-for-a-chart">How to set invert if negative option for a chart using XLsIO?</a>
</li>
<li>
<li>
<a href="/document-processing/excel/excel-library/net/faqs/how-to-merge-cells-preserving-topleft-value-and-format-in-xlsio">How to merge cells preserving topleft value and format in XlsIO?</a>
</li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
---
title: How to Open Excel as Read‑Only using XlsIO | Syncfusion
description: This page explains how to to open Excel file as ReadOnly in MS Excel using XlsIO
platform: document-processing
control: XlsIO
documentation: UG

# How to open Excel file as ReadOnly in Microsoft Excel using XlsIO?

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";

// Set the workbook to be read-only recommended
workbook.ReadOnlyRecommended = true;

// 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";
// Set the workbook to be read-only recommended
workbook.ReadOnlyRecommended = true;

// 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"

' Set the workbook to be read-only recommended
workbook.ReadOnlyRecommended = true

' 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 <a href="https://github.com/SyncfusionExamples/XlsIO-Examples/tree/992377-ReadOnly-Excel/FAQ/ReadOnly%20Excel/.NET/Readonly%20Excel">this GitHub page</a>.