Excel file on a dialog
- Antonio Linares
- Site Admin
- Posts: 42836
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 169 times
- Been thanked: 123 times
- Contact:
Re: Excel file on a dialog
You may use a TWebView2 control and use this HTML code:
Code: Select all | Expand
<input type="file" id="input" accept=".xlsx, .xls" />
<div id="output"></div>
<script src="https://cdn.sheetjs.com/xlsx-latest/xlsx.full.min.js"></script>
<script>
document.getElementById("input").addEventListener("change", async (e) => {
const file = e.target.files[0];
const data = await file.arrayBuffer();
const workbook = XLSX.read(data);
const firstSheet = workbook.Sheets[workbook.SheetNames[0]];
const html = XLSX.utils.sheet_to_html(firstSheet);
document.getElementById("output").innerHTML = html;
});
</script>
Re: Excel file on a dialog
Antonio, how can I open a specific document (C:\MyFile.xlsx) in webview ?
- Antonio Linares
- Site Admin
- Posts: 42836
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 169 times
- Been thanked: 123 times
- Contact:
Re: Excel file on a dialog
This should should work:
webviewexcel.prg
webviewexcel.prg
Code: Select all | Expand
#include "FiveWin.ch"
function Main()
local oWebView := TWebView2():New()
oWebView:SetHtml( Html() )
oWebView:SetTitle( "Microsoft Edge WebView working from FWH" )
oWebView:SetUserAgent( "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36" )
oWebView:Run()
oWebView:End()
return nil
function Html()
local cHtml
TEXT INTO cHtml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Read Excel File</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
table {
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
#output p {
color: red;
}
</style>
</head>
<body>
<h1>Upload and Display Excel File</h1>
<input type="file" id="input" accept=".xlsx, .xls" />
<div id="output"></div>
<script src="https://cdn.sheetjs.com/xlsx-latest/xlsx.full.min.js"></script>
<script>
document.getElementById('input').addEventListener('change', async (e) => {
const file = e.target.files[0];
if (!file) return;
try {
const data = await file.arrayBuffer();
const workbook = XLSX.read(data);
const firstSheet = workbook.Sheets[workbook.SheetNames[0]];
const html = XLSX.utils.sheet_to_html(firstSheet);
document.getElementById('output').innerHTML = html;
} catch (error) {
console.error('Error reading file:', error);
document.getElementById('output').innerHTML = '<p>Error reading file.</p>';
}
});
</script>
</body>
</html>
ENDTEXT
return cHtml
Re: Excel file on a dialog
Sorry, I don't understand. This example does not allow to open the file C:\MyFile.xlsx
- Antonio Linares
- Site Admin
- Posts: 42836
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 169 times
- Been thanked: 123 times
- Contact:
Re: Excel file on a dialog
This version is working fine here:
Code: Select all | Expand
#include "FiveWin.ch"
function Main()
local oWebView := TWebView2():New()
oWebView:SetHtml( Html() )
oWebView:SetTitle( "Microsoft Edge WebView working from FWH" )
oWebView:SetUserAgent( "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.53 Mobile Safari/537.36" )
// oWebView:OpenDevToolsWindow( .T. ) // Open DevTools
oWebView:Run()
oWebView:End()
return nil
function Html()
local cHtml
TEXT INTO cHtml
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Read Excel File</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 20px;
}
table {
border-collapse: collapse;
margin-top: 20px;
}
th, td {
border: 1px solid #ddd;
padding: 8px;
text-align: left;
}
th {
background-color: #f2f2f2;
}
#output p {
color: red;
}
</style>
</head>
<body>
<h1>Upload and Display Excel File</h1>
<input type="file" id="input" accept=".xlsx, .xls" />
<div id="output"></div>
<script src=https://cdn.sheetjs.com/xlsx-0.20.3/package/dist/xlsx.full.min.js></script>
<script>
document.getElementById('input').addEventListener('change', async (e) => {
const file = e.target.files[0];
if (!file) return;
try {
const data = await file.arrayBuffer();
const workbook = XLSX.read(data);
const firstSheet = workbook.Sheets[workbook.SheetNames[0]];
const html = XLSX.utils.sheet_to_html(firstSheet);
document.getElementById('output').innerHTML = html;
} catch (error) {
console.error('Error reading file:', error);
document.getElementById('output').innerHTML = '<p>Error reading file.</p>';
}
});
</script>
</body>
</html>
ENDTEXT
return cHtml
Re: Excel file on a dialog
When I select a file I get the message "Error reading file" (maybe I have an old version of WebView).
Is it possible to get properties of WebView object via GetProp(), GetPropA() ?
Is it possible to get properties of WebView object via GetProp(), GetPropA() ?
- Lailton
- Posts: 187
- Joined: Fri Jul 20, 2012 1:49 am
- Location: Brazil
- Has thanked: 2 times
- Been thanked: 13 times
- Contact:
Re: Excel file on a dialog
To load local files you can combine the BIND events and send some request from web page to the FWH take the file ( convert to base64 ) and
read it from webpage.

read it from webpage.

Regards,
Lailton Fernando Mariano
Lailton Fernando Mariano
- Antonio Linares
- Site Admin
- Posts: 42836
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 169 times
- Been thanked: 123 times
- Contact:
Re: Excel file on a dialog
Please double check that you are using https://cdn.sheetjs.com/xlsx-0.20.3/pac ... ull.min.jsNatter wrote: Wed Apr 23, 2025 8:25 am When I select a file I get the message "Error reading file" (maybe I have an old version of WebView).
Is it possible to get properties of WebView object via GetProp(), GetPropA() ?
Here it works very fine

Re: Excel file on a dialog
Lailton, could you give me a small example?To load local files you can combine the BIND events and send some request from web page to the FWH take the file ( convert to base64 ) and
read it from webpage.
- Antonio Linares
- Site Admin
- Posts: 42836
- Joined: Thu Oct 06, 2005 5:47 pm
- Location: Spain
- Has thanked: 169 times
- Been thanked: 123 times
- Contact:
Re: Excel file on a dialog
Dear Yuri,
Please email me your excel file and I will provide you a screenshot and the EXE
Please email me your excel file and I will provide you a screenshot and the EXE