giovedì 14 novembre 2019

visualizza foglio excel in una pagina html ricerca con ajax - vbs

script: visualizza foglio excel in una pagina html ricerca con ajax - vbs

'
option explicit
' vbs Excel html
'
dim dbmodellohtml, modellohtml, shtml
dbmodellohtml = "C:\azioniprogrammate\tabella-jquery\db-tabella-ajax.txt"
modellohtml = leggifiletutto(dbmodellohtml)
'
dim foglioexcel, foglio, nomefoglio
dim dblog, slog
' =====================================
dblog = "C:\cartella-report\temp-report.html" ' === nome pagina html da creare
foglioexcel = "C:\fogli-excel\magazzino_2018_per_codici.xlsx"  ' file excel da leggere
nomefoglio = "dati"                             ' foglio excel da leggere
' =============
'
shtml = ""
shtml = shtml & modellohtml
'
dim app
set app = createobject("Excel.Application")
app.Visible = true
'
dim oExcelBook
'
Set oExcelBook = app.Workbooks.open(foglioexcel)
set foglio = oExcelBook.sheets(nomefoglio)
'
Dim quanterighe, contarighe,  contacolonne, quantecolonne, contenuto
'
quanterighe = foglio.Range(foglio.UsedRange.Cells(foglio.UsedRange.Rows.Count, 1).Address).Row
quantecolonne = foglio.Range(foglio.UsedRange.Cells(1, foglio.UsedRange.Columns.Count).Address).Column
'
contacolonne = 1
contarighe = 1
' scrive riga di intestazione
shtml = shtml & "<thead>" & "<tr>"
'
While contacolonne <= quantecolonne
   contenuto = "<th>" & foglio.Cells(contarighe, contacolonne).Value & "</th>"
  shtml = shtml & contenuto
   contacolonne = contacolonne + 1
Wend
'
shtml = shtml & "</tr>" &  "</thead>" & "<tbody id=""myTable"">"
'
' === scrive il dettaglio
contarighe = 2
While contarighe <= quanterighe
   contacolonne = 1
   shtml = shtml & "<tr>"
   While contacolonne <= quantecolonne
      contenuto = "<td>" & foglio.Cells(contarighe, contacolonne).Value & "</td>"
      shtml = shtml & contenuto
  
      contacolonne = contacolonne + 1
   Wend
   shtml = shtml & "</tr>"
   contarighe = contarighe + 1
   foglio.Cells(contarighe, "A").select
Wend
'
shtml = shtml & "</tbody>" & "</TABLE>"  & "</BODY>" & "</HTML>"
call SovraScriviFile(dblog, shtml)
'
'
oExcelBook.close
'
Set oExcelBook = Nothing
app.Quit
Set app = Nothing
'
' === sovra scrive file ===================
'
Sub SovraScriviFile(pNomeArchivio, pcosascrivere)
dim fso,  rifefile
Set fso=CreateObject("Scripting.FileSystemObject")
Set rifefile = fso.CreateTextFile(pNomeArchivio, TRUE)
rifefile.WriteLine(pcosascrivere)
rifefile.Close
set rifefile = Nothing
End Sub
'
' ===========
'
function leggifiletutto(sFilePathAndName)
dim sFileContents, oFS, oTextStream
Set oFS = CreateObject("Scripting.FileSystemObject")
If oFS.FileExists(sFilePathAndName) = True Then
     Set oTextStream = oFS.OpenTextFile(sFilePathAndName,1)
     sFileContents = oTextStream.ReadAll
     oTextStream.Close
     Set oTextStream = nothing
End if
Set oFS = nothing
'
leggifiletutto = sFileContents
'
end function
'
' =================
'
--- file: db-tabella-ajax.txt

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
  $("#myInput").on("keyup", function() {
    var value = $(this).val().toLowerCase();
    $("#myTable tr").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
  });
});
</script>
<style>
table {
  font-family: arial, sans-serif;
  border-collapse: collapse;
  width: 100%;
}
td, th {
  border: 1px solid #dddddd;
  text-align: left;
  padding: 8px;
}
tr:nth-child(even) {
  background-color: #dddddd;
}
</style>
</head>
<body>
<h2>ricerca</h2> 
<input id="myInput" type="text" placeholder="ricerca...">
<br>
<table>

Nessun commento:

Posta un commento