function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
TechiesTechies 

How to insert an image in to a vf page where content type is msexcel

Pradeep_NavatarPradeep_Navatar

For ms-excel document having content type 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' , tryout this sample code given below :

 

List<Document> lstDoc = Database.query('SELECT d.Id, d.Name, d.Body, d.ContentType, d.IsPublic, d.FolderId  FROM Document d WHERE d.Name Like \'' + Userinfo.getUserName() + '%\'');

if(propFileBody != null && propFileName != null && propContentType != null && propContentType != '')

{

if(lstDoc != null && lstDoc.size() > 0 && (lstDoc[0].ContentType == 'image/png' || lstDoc[0].ContentType == 'image/x-png' || lstDoc[0].ContentType == 'image/pjpeg' || lstDoc[0].ContentType == 'image/jpeg' || lstDoc[0].ContentType == 'image/gif' || lstDoc[0].ContentType == 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet')) //Update Record

                                                                {

                                                                                lstDoc[0].Name = Userinfo.getUserName();

                                                                                lstDoc[0].Body = propFileBody;

                                                                                lstDoc[0].ContentType = propContentType;

                                                                                lstDoc[0].Type = propContentType.substring((propContentType.indexOf('/')+1),propContentType.length());

                                                                                system.debug('Updated*********');

                                                                                Database.SaveResult sr = Database.Update(lstDoc[0]);

                                                                }

                                                }      

 

Hope this helps.