Click here to Skip to main content
15,885,435 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I am working on MFC application that opens excel file in a IE specific file viewer on CHtmlView using navigate method. I have also changed its browserflags and editflag both. but the preview control is still blank. Really appreciate your help.

What I have tried:

DWORD dwValue=0x80000a00;
	DWORD dwEdit=0x00010000;


if (RegOpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes\\Excel.Sheet.12"), &hExcel2k7) == ERROR_SUCCESS)
	{
		if (RegSetValueEx(hExcel2k7,_T("BrowserFlags"),NULL,REG_DWORD,(PBYTE)&dwValue,sizeof(PDWORD))==ERROR_SUCCESS)
		{
			if (RegSetValueEx(hExcel2k7,_T("EditFlags"),NULL,REG_DWORD,(PBYTE)&dwEdit,sizeof(PDWORD))==ERROR_SUCCESS)
			{
				RegCloseKey(hExcel2k7);
			}
		}
	}
	if (RegOpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes\\Excel.Sheet.8"), &hExcel2k7) == ERROR_SUCCESS)
	{
		if (RegSetValueEx(hExcel2k7,_T("BrowserFlags"),NULL,REG_DWORD,(PBYTE)&dwValue,sizeof(PDWORD))==ERROR_SUCCESS)
		{	
			if(RegSetValueEx(hExcel2k7,_T("EditFlags"),NULL,REG_DWORD,(PBYTE)&dwEdit,sizeof(PDWORD))==ERROR_SUCCESS)
			{
				RegCloseKey(hExcel2k7);
			}
		}
	}
	if (RegOpenKey(HKEY_LOCAL_MACHINE, _T("SOFTWARE\\Classes\\Excel.SheetMacroEnabled.12"), &hExcel2k7) == ERROR_SUCCESS)
	{
		if (RegSetValueEx(hExcel2k7,_T("BrowserFlags"),NULL,REG_DWORD,(PBYTE)&dwValue,sizeof(PDWORD))==ERROR_SUCCESS)
		{	
			if(RegSetValueEx(hExcel2k7,_T("EditFlags"),NULL,REG_DWORD,(PBYTE)&dwEdit,sizeof(PDWORD))==ERROR_SUCCESS)
			{
				RegCloseKey(hExcel2k7);
			}
		}
	}


method:
p_RView->Navigate2(pApp->strTargetPath,0,0);



However what registry settings are needed for Office 2021 to make excel documents to open in IE?
Posted
Updated 9-Mar-22 21:15pm
v3
Comments
Maciej Los 8-Mar-22 11:33am    
An Excel file is NOT just a simple Xml. It's OpenXml document. So, you can't open it directly in a browser.
Aashish_stellar 8-Mar-22 23:26pm    
Its working fine in my application for office 2019. Now I am trying to upgrade it for office 2021 which is creating problem.

1 solution

Quote:
I am working on MFC application that opens excel file in a IE specific file viewer on CHtmlView using navigate method. I have also changed its browserflags and editflag both. but the preview control is still blank. Really appreciate your help.


You're basically having two options:

1. If you want to open the xls-file in your MFC application, you should use the OLE Automation, something just like you do in your code, elaborated.

2. If you want to embed the xls-document view into an HTML document, rendered by CHTMLView, you should not implement any code in C++ MFC in your application. Instead, design an HTML document, that opens the xls-sheet, implementing the function in JavaScript that does it for you. Finally, you can render this page with CHTMLView in your C++/MFC application. This must work for you just fine if you make sure that JavaScript execution support is enabled for the CHTMLView.

Edit:

Here's my solution using Google Docs and JavaScript:

HTML
<!DOCTYPE html>
<html>
<head>
  <script type="text/javascript">
    function load_xls(url) {
	 document.getElementById('xls').src="https://docs.google.com/gview?url="+url+"&embedded=true";
    }
  </script>
</head>
<body>
  <iframe onload="load_xls('<url-to-your-xls-file')" style="width: 100%; height:800px" id="xls"></iframe>
</body>
</html>


Good Luck! :)
 
Share this answer
 
v2
Comments
Aashish_stellar 9-Mar-22 23:06pm    
Can you please help me out how can we do it in JavaScript ?
Arthur V. Ratz 10-Mar-22 4:17am    
Yes. Thanks. I've corrected this.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900