Skip to content

Word Excel viewer Example - #132

Open
ioa747 wants to merge 1 commit into
mainfrom
Word-Excel-viewer
Open

Word Excel viewer Example#132
ioa747 wants to merge 1 commit into
mainfrom
Word-Excel-viewer

Conversation

@ioa747

@ioa747 ioa747 commented Aug 13, 2026

Copy link
Copy Markdown
Owner

Important

Thanks for your effort and interest 💛 in improving the project. It's very appreciated.

Description

Word Excel viewer Example

🔗 Linked GitHub Issues

#40 (comment)

Closes #\40

📋 What is the current behavior?

🚀 What is the new behavior?


Type of changes

  • 🪲 Bugfix (change which fixes an issue)
  • ⭐ New Feature (change which adds functionality)
  • ⭐ New Example (this PR adds a new example)
  • 🔒 Security fix (change which improves security)
  • 🔮 Code style update (formatting, renaming)
  • 🔨 Refactoring (code optimization without functional change)
  • 📚 Documentation (updates to README or docs)
  • ⚙️ Build or CI related changes
  • 🧿 Other type

Breaking changes 🔥

  • Yes
  • No

How and where was this tested?

🖥️ Describe where you tested your changes

System:

  • Windows 11 (x64)
  • Windows 10 (x64)
  • Windows 10 (x86)
  • Windows Server ......

Context:

  • COM object NetJson.Parser
  • COM object NetWebView2.Manager - WebView2
  • COM object NetWebView2.Manager - Bridge
  • UDF - NetWebView2Lib.au3
  • Examples: 025_Example_XlsxViewer.au3, 025_Example_DocxViewer.au3
  • with ...

🔬 Describe how you tested your changes

  • Manually tested in system and context shown above
  • Ran automatic tests (unit tests, integration tests, etc.)
  • Other ways

Checklist

  • I have read and understood the available contributing guidelines.
  • I have ensured my code follows the available code conventions.
  • I have reviewed my changes.
  • I have made corresponding changes to the documentation (if applicable).
  • I have added/updated necessary tests to cover the changes (if applicable).
  • I have checked for potential security implications.

Additional context

Screenshots

Note to reviewers

Word Excel viewer Example

We have successfully implemented a clean, offline solution for viewing both Word (.docx) and Excel (.xlsx) documents directly inside WebView2 using client-side JavaScript rendering combined with _NetWebView2_SetVirtualHostNameToFolderMapping.

Key Technical Insights:
Chromium Flag Fix: To bypass local fetch/CORS restrictions when loading binary files locally,
we pass the --allow-file-access-from-files switch during manager initialization:

Local $oWebV2M = _NetWebView2_CreateManager("", "", "--allow-file-access-from-files")

Client-Side Libraries (100% Offline):

Word (.docx): Rendered using docx-preview (requires JSZip).

Excel (.xlsx): Rendered using SheetJS (xlsx.full.min.js), which supports tab switching for multiple worksheets.

Dynamic File Loading Pattern:
Instead of reloading the page with NavigateToString, the HTML viewer page is loaded once.
When selecting a new document via FileOpenDialog, AutoIt updates the active file in the mapped folder and triggers a lightweight JS render function via _NetWebView2_ExecuteScript:

; Copy selected file to mapped folder
FileCopy($sFilePath, $sMappedFolder & "\active_file.docx", $FC_OVERWRITE)
; Trigger dynamic render (Fire-and-Forget mode 0)
_NetWebView2_ExecuteScript($oWebV2M, "renderLocalDocx('active_file.docx');")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant