Posts: 41
Threads: 12
Joined: 27.01.2025
I'd like to display DOCX and XLSX files with their full visual content.
But, I need for the solution to NOT require Word/Excel be installed on a user's PC.
Is that possible?
Posts: 41
Threads: 12
Joined: 27.01.2025
The Everything author, David Carpenter, mentioned to me that he uses the IPreviewHandler interface to display docx/xlsx files. I see that in a Jose INC but don't see any forum examples to go with it.
Posts: 92
Threads: 5
Joined: 30.05.2024
Google AIi says:
Can IPreviewHandler display word documents if word is not installed
No, if Microsoft Word is not installed, the built-in Windows
File Explorer preview handler cannot display Word documents because it requires the Microsoft Office preview handler, which is installed with Word, to interpret and render the document's contents for a preview. To view Word documents without having Word installed, you need to use alternative software or services, such as Google Drive's online editor, other word processing suites that provide their own preview handlers, or a dedicated document preview utility.
--
New PowerBASIC User Community Forum:
https://pbusers.org/forum
Posts: 41
Threads: 12
Joined: 27.01.2025
18.09.2025, 03:33 PM
(This post was last modified: 18.09.2025, 03:37 PM by Gary Beene.)
Howdy, Stuart!
Thanks for the reply! There may be more to it.
I have PCs which do not have 365 installed and they can run the Everything preview (which uses IPreviewHandler) just fine.
The include file shobjidl.inc is present in Jose's include files and contains content about IParentHandler. David passed on this code for me to look at.
Is that information inconsistent with Google AI? It may be because I see some SHELLEX commands, but I really don't know squat about the language.
Code: // Given extension, determine the CLSID of its handler
static int _ui_preview_CLSID_from_filename(const utf8_t *filename,int is_folder,CLSID *clsid)
{
int ret;
utf8_buf_t data_cbuf;
utf8_buf_t key_cbuf;
ret = 0;
utf8_buf_init(&data_cbuf);
utf8_buf_init(&key_cbuf);
// CONFIG_PREVIEW_HANDLERS
if (!ret)
{
if (_ui_preview_get_config_preview_handler(is_folder,filename,clsid))
{
debug_printf("got preview handler from config\n");
ret = 1;
}
}
if (is_folder)
{
if (!ret)
{
utf8_buf_printf(&key_cbuf,"%s\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}","Folder");
if (_ui_preview_CLSID_from_key(key_cbuf.buf,clsid))
{
ret = 1;
}
}
}
else
{
utf8_buf_t perceived_type_cbuf;
const utf8_t *extension_with_dot;
int got_perceived_type;
utf8_buf_init(&perceived_type_cbuf);
got_perceived_type = 0;
extension_with_dot = utf8_string_get_extension_including_dot(filename);
// if there's no extension, use "." like Windows Explorer.
if (!*extension_with_dot)
{
extension_with_dot = (const utf8_t *)".";
}
// try EverythingSystemFileAssociations
/*
if (!ret)
{
utf8_buf_printf(&key_cbuf,"EverythingSystemFileAssociations\\%s\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}",extension_with_dot);
if (os_registry_get_string(HKEY_CLASSES_ROOT,key_cbuf.buf,0,&data_cbuf))
{
if (os_CLSIDFromString(data_cbuf.buf,clsid))
{
//debug_printf("got preview handler {%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}\n",clsid->Data1,clsid->Data2,clsid->Data3,clsid->Data4[0],clsid->Data4[1],clsid->Data4[2],clsid->Data4[3],clsid->Data4[4],clsid->Data4[5],clsid->Data4[6],clsid->Data4[7]) ;
debug_printf("got preview handler from esfa\n");
ret = 1;
}
}
}
*/
// try ext
if (!ret)
{
utf8_buf_printf(&key_cbuf,"%s\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}",extension_with_dot);
if (_ui_preview_CLSID_from_key(key_cbuf.buf,clsid))
{
ret = 1;
}
}
// try class first (like Windows Explorer)
if (!ret)
{
if (os_registry_get_string(HKEY_CLASSES_ROOT,extension_with_dot,0,&data_cbuf))
{
if (*data_cbuf.buf)
{
utf8_buf_printf(&key_cbuf,"%s\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}",data_cbuf.buf);
if (_ui_preview_CLSID_from_key(key_cbuf.buf,clsid))
{
ret = 1;
}
}
}
}
// try SystemFileAssociations
if (!ret)
{
utf8_buf_printf(&key_cbuf,"SystemFileAssociations\\%s\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}",extension_with_dot);
if (_ui_preview_CLSID_from_key(key_cbuf.buf,clsid))
{
ret = 1;
}
}
// same as Windows Explorer, try *
// after SystemFileAssociations\.extension
if (!ret)
{
utf8_buf_printf(&key_cbuf,"%s\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}","*");
if (_ui_preview_CLSID_from_key(key_cbuf.buf,clsid))
{
ret = 1;
}
}
// like Windows Explorer, check PerceivedType for text and use the builtin txt preview handler CLSID.
if (!ret)
{
if (os_registry_get_string(HKEY_CLASSES_ROOT,extension_with_dot,(const utf8_t *)"PerceivedType",&perceived_type_cbuf))
{
got_perceived_type = 1;
if (_ui_preview_CLSID_from_perceived_type(perceived_type_cbuf.buf,clsid))
{
ret = 1;
}
}
}
// like Windows Explorer, check PerceivedType for text in SystemFileAssociations.
if (!ret)
{
// same as:
// Computer\HKEY_LOCAL_MACHINE\SOFTWARE\Classes\SystemFileAssociations\.log
utf8_buf_printf(&key_cbuf,"SystemFileAssociations\\%s",extension_with_dot);
if (os_registry_get_string(HKEY_CLASSES_ROOT,key_cbuf.buf,(const utf8_t *)"PerceivedType",&perceived_type_cbuf))
{
got_perceived_type = 1;
if (_ui_preview_CLSID_from_perceived_type(perceived_type_cbuf.buf,clsid))
{
ret = 1;
}
}
}
// try our text/plain extensions.
if (!ret)
{
if (file_content_is_text_plain_extension(extension_with_dot))
{
got_perceived_type = 1;
if (_ui_preview_CLSID_from_perceived_type("text",clsid))
{
ret = 1;
}
}
}
if (!ret)
{
if (!got_perceived_type)
{
utf8_buf_printf(&key_cbuf,"%s\\ShellEx\\{8895b1c6-b41f-4c1c-a562-0d564250836f}","Unknown");
if (_ui_preview_CLSID_from_key(key_cbuf.buf,clsid))
{
ret = 1;
}
}
}
utf8_buf_kill(&perceived_type_cbuf);
}
utf8_buf_kill(&key_cbuf);
utf8_buf_kill(&data_cbuf);
return ret;
}
static _ui_preview_IPreviewHandler_t *_ui_preview_handler_create_instance(CLSID *clsid)
{
_ui_preview_IPreviewHandler_t *ret;
_ui_preview_IPreviewHandler_t *preview_handler;
HRESULT hres;
ret = NULL;
// MUST be CLSCTX_LOCAL_SERVER for IID_IPreviewHandler
// we can use CoCreateInstance to create multiple instances.
// Its slower than CoGetClassObject, but we dont care about performance here.
hres = CoCreateInstance(clsid,NULL,CLSCTX_LOCAL_SERVER,&_ui_preview_IID_IPreviewHandler,(LPVOID*)&preview_handler);
if (SUCCEEDED(hres))
{
ret = preview_handler;
}
else
{
debug_error_printf("CoCreateInstance %08x\n",hres);
}
return ret;
}
Posts: 31
Threads: 5
Joined: 27.05.2024
Here is another AI answer, I fed everything including the source code from this thread ...
It is not possible to use the IPreviewHandler interface to display full visual previews of DOCX or XLSX files without Microsoft Office (Word/Excel) installed on the user's PC. The preview handlers for these file formats are registered by Office itself in the Windows registry under the relevant ShellEx keys (like the {8895b1c6-b41f-4c1c-a562-0d564250836f} GUID shown in the code). Without Office, those CLSIDs are not present, and CoCreateInstance will fail to instantiate the handler.
Everything (from voidtools) relies on the same system-registered IPreviewHandlers as Windows File Explorer. If previews work on your PCs without Office 365, it's likely because a perpetual version of Office (e.g., 2019 or 2021) is installed, providing the necessary handlers—Office 365 refers specifically to the subscription model, not all Office installations.
The Microsoft Office Compatibility Pack does not register preview handlers; it only enables opening/editing newer formats in older Office versions. LibreOffice and similar free alternatives also do not register IPreviewHandler for DOCX/XLSX in Explorer or compatible apps like Everything. Windows itself has no built-in handlers for these formats without Office.
To implement this in PowerBASIC using Jose's shobjidl.inc, you could adapt the provided C code logic to query the registry for the CLSID (via RegOpenKeyEx, RegQueryValueEx, etc.), then use CoCreateInstance to get the IPreviewHandler interface pointer, followed by calls to IInitializeWithFile (or IInitializeWithStream), SetWindow, SetRect, and DoPreview. However, this will only succeed if the handler is registered (i.e., Office is installed). Without it, you'd need to fall back to custom rendering, which is impractical for full visual fidelity—DOCX/XLSX are complex ZIP+XML formats requiring parsing layouts, fonts, embeds, formulas, etc.
Alternatives without Office:
- Third-party tools like QuickLook or Seer can preview these files, but they don't integrate via IPreviewHandler and require installation.
- Embed a WebBrowser or WebView2 control in your app to load the file via Office Online (requires internet) or a local library like Mammoth.js for basic DOCX-to-HTML conversion (but loses full visuals).
- Use COM/ActiveX components if available (e.g., paid ones like Aspose or free limited viewers), but none are drop-in replacements without extra setup.
If your goal is truly zero dependencies on Office-like software, the short answer is no for full visual previews via IPreviewHandler or similar native means.
Posts: 41
Threads: 12
Joined: 27.01.2025
Howdy, Jules!
Thank you for that additional information! I may not like the answer but it is what it is.
I had to chuckle at this, from the Seer page ... "The price of the official version is $12.18.". What an odd price!?
Have you used Seer? The web page is not very informative.
Posts: 92
Threads: 5
Joined: 30.05.2024
(19.09.2025, 03:35 PM)Gary Beene Wrote: "The price of the official version is $12.18.". What an odd price!?
I'd guess they want to clear $12 and that includes 15% Tax or similar.
--
New PowerBASIC User Community Forum:
https://pbusers.org/forum
Posts: 6
Threads: 1
Joined: 28.05.2025
(18.09.2025, 04:30 AM)Gary Beene Wrote: I'd like to display DOCX and XLSX files with their full visual content.
But, I need for the solution to NOT require Word/Excel be installed on a user's PC.
Is that possible?
Yes, I have a utility called doc2text.exe which can produce a flat txt file from a docx file - that can then bo viewed with eg notepad. Not sure what it will do with xls files but if you're interested, can try it.
Posts: 92
Threads: 5
Joined: 30.05.2024
05.10.2025, 04:12 AM
(This post was last modified: 05.10.2025, 04:12 AM by Stuart McLachlan.)
(05.10.2025, 02:56 AM)Owen_English Wrote: (18.09.2025, 04:30 AM)Gary Beene Wrote: I'd like to display DOCX and XLSX files with their full visual content.
...
Yes, I have a utility called doc2text.exe which can produce a flat txt file from a docx file - that can then bo viewed with eg notepad. Not sure what it will do with xls files but if you're interested, can try it.
" with their full visual content."
A "flat txt file" is not what was asked for.
--
New PowerBASIC User Community Forum:
https://pbusers.org/forum
Posts: 74
Threads: 5
Joined: 27.05.2024
05.10.2025, 05:05 AM
(This post was last modified: 05.10.2025, 05:09 AM by Dale Yarker.)
NOT disagreeing with above, another option/suggestion.
search: is docx proprietary:
"Proprietary format: DOCX is a proprietary file format owned by Microsoft, which means that full compatibility and functionality may be limited to Microsoft Word and other licensed applications." (bold added)
Can docx originator be asked to provide in different file format? Or, can someone who does have MS Word do a Save As for you?
---------------------------------
search: can ms word save as html
https://support.microsoft.com/en-us/topi...8c0e405c44
--------------------------------------
rearch: can ms word save as pdf
https://support.microsoft.com/en-us/offi...4bf7c7c110
Cheers,
|