Back to column formats
Column formattingSharePoint Online

Open Office Documents in View Mode

By default, office documents in a SharePoint document library open in Edit mode, switching the default open behaviour from Edit to View prevents common day-to-day issues.

Open Office Documents in View Mode formatting preview
Sample preview · View original image

Copy. Apply. Make it yours.

Get this format

1 definition

Review the requirements below, then paste this JSON into the matching formatting panel. Show me where.

Use your list's internal column names and replace any tenant-specific URLs or flow IDs. Formatting is presentation, not a way to secure data.

Column formatting
Download JSON
{
  "$schema": "https://developer.microsoft.com/json-schemas/sp/v2/column-formatting.schema.json",
  "elmType": "a",
  "txtContent": "@currentField",
  "style": {
    "text-decoration": "none",
    "color": "inherit",
    "padding-left": "8px"
  },
  "attributes": {
    "class": "ms-fontSize-m",
    "target": "=if([$FSObjType]=='1', '_self', '_blank')",
    "href": "=if([$FSObjType]=='1', [$FileRef], if(indexOf('docx,docm,doc,xlsx,xlsm,xls,pptx,pptm,ppt', [$File_x0020_Type]) != -1, @currentWeb + '/_layouts/15/Doc.aspx?sourcedoc=' + [$UniqueId] + '&action=' + if(indexOf('pptx,pptm,ppt', [$File_x0020_Type]) != -1, 'embedview', 'view'), [$FileRef]))"
  }
}

From the contributor

How to use this sample

# Open Office Documents in View Mode

Summary

By default, office documents in a SharePoint document library open in Edit mode, switching the default open behaviour from Edit to View prevents common day-to-day issues.

Why defaulting documents to Read-Only in SharePoint Online makes sense:

  • Prevent accidental changes
  • Better data integrity and cleaner version history
  • Improved user experience

You can achieve this by using column formatting on the Name column.

screenshot of the sample

View requirements

This format can be applied to the Name column (file name) within a SharePoint document library.

[!NOTE]

File Type Extensions Parameters
Word docx, docm, doc embedview, interactivepreview, View, ServerRedirectedEmbedUrl
Excel xlsx, xlsm, xls embedview, interactivepreview, View
PowerPoint pptx, pptm, ppt embedview, interactivepreview, ServerRedirectedEmbedUrl
Other types e.g., pdf FileRef

Sample

Solution Author(s)
filename-open-document-in-view-mode.json Watana

Version history

Version Date Comments
1.0 April 12, 2026 Initial release

Disclaimer

THIS CODE IS PROVIDED AS IS WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.