I have requirement where I want to display Excel in viewer instead of downloading it in Salesforce.
I am using
/sfc/servlet.shepherd/document/download/+ ID to download Excel.
Is there any way to open it in browser itself.
If you are talking about file and not the attachment, you can do it as follow:-
Note:- Use contentdocument id instead of contentversion.
It will open the file detail with preview. If salesforce can not provide the preview it will come as below, else preview will come in preview section.
If you have an attachment, You can view it by using:-
Note it will only work for file type that can be preview in Salesforce. You are talking about excel, and they cannot be preview. So everytime it will be downloaded. If it is pdf or image, You can preview it