1) I have a sqlite file with information 2) Through a program I generate a * .csv file.
I would like on a NetBook or iPad or CromeCast or Cell, r display such information sequentially or at the user's request.
For example, if the user uses: +, right arrow or up arrow: advance 1 in 1 -, down arrow, or left arrow: go back 1 in 1 home: go to the beginning end: go to the end if you enter a number and then enter the corresponding line
I do not want to install an apache service or use iis, but I do use the browser.
By means of html and javascript I have managed to do it but the user before starting must select the file.csv
I would like you to click on the file.html or on a shortcut on the desktop, it is not necessary to select the .csv file.
What I have found on the web has allowed me to do this:
<div id="page-wrapper">
<div>
Seleccionar Archivo:
<input type="file" id="fileInput">
</div>
<input type = 'text' value= '1' id='txtLote' onkeypress="return runScript(event)" onkeyup="runScript(event)"style="text-align:right;"/>
<pre id="fileDisplayArea"></pre>
<div id="divData" style="font-size:50px">
</div>
</div>
<style>
input:focus {
background-color: yellow;
}
body{
font-family: courier;
}
.tbl{font-size:50px;
font-weight: bold}
</style>
<script>
var nwLote = 0;
var array;
var maxArray;
document.getElementById("txtLote").focus();
document.getElementById("txtLote").select();
function runScript(e)
{
if (e.keyCode == 13)
{
var tb = document.getElementById("txtLote");
nwLote = tb.value;
if (nwLote > maxArray)
{
nwLote = maxArray;
}
if (nwLote < 1)
{
nwLote = 1;
}
mostrarDato(nwLote);
return false;
}
if (e.keyCode == 43) // +
{
nwLote = + nwLote + 1;
if (nwLote > maxArray)
{
nwLote = maxArray;
}
document.getElementById("txtLote").value=nwLote;
mostrarDato(nwLote);
return false;
}
if (e.keyCode == 45) // -
{
nwLote = nwLote - 1;
if (nwLote < 1)
{
nwLote = 1;
}
document.getElementById("txtLote").value=nwLote;
mostrarDato(nwLote);
return false;
}
if (e.keyCode == 39) // derecha
{
nwLote = + nwLote + 1;
if (nwLote > maxArray)
{
nwLote = maxArray;
}
document.getElementById("txtLote").value=nwLote;
mostrarDato(nwLote);
return false;
}
if (e.keyCode == 37) // izquierda
{
nwLote = nwLote - 1;
if (nwLote < 1)
{
nwLote = 1;
}
document.getElementById("txtLote").value=nwLote;
mostrarDato(nwLote);
return false;
}
if (e.keyCode == 38) // arriba
{
nwLote = + nwLote + 1;
if (nwLote > maxArray)
{
nwLote = maxArray;
}
document.getElementById("txtLote").value=nwLote;
mostrarDato(nwLote);
return false;
}
if (e.keyCode == 40) // abajo
{
nwLote = nwLote - 1;
if (nwLote < 1)
{
nwLote = 1;
}
document.getElementById("txtLote").value=nwLote;
mostrarDato(nwLote);
return false;
}
if (e.keyCode == 36) // home
{
nwLote = 1;
document.getElementById("txtLote").value=nwLote;
mostrarDato(nwLote);
return false;
}
if (e.keyCode == 35) // end
{
nwLote = maxArray;
document.getElementById("txtLote").value=nwLote;
mostrarDato(nwLote);
return false;
}
return true;
}
function mostrarDato(nwLote){
var divData = document.getElementById('divData');
var string = array[nwLote-1] ;
var array1 = string.split(",");
var contenido = "<table class='tbl'>";
contenido += "<tr><td>LOTE</td><td>" + array1[0] + "</td></tr>";
contenido += "<tr><td>DETALLE</td><td>" + array1[1] + "</td></tr>";
contenido += "<tr><td>CANTIDAD </td><td>" + array1[2] + "</td></tr>";
contenido += "<tr><td>BASE</td><td>" + array1[3] + "</td></tr>";
contenido += "<tr><td>REMITE</td><td>" + array1[6] + "</td></tr>";
contenido += "<tr><td>REMITO</td><td>" + array1[4] + "</td></tr>";
contenido += "<tr><td>RENGLON</td><td>" + array1[5] + "</td></tr>";
contenido += "</table>";
divData.innerHTML = contenido;
document.getElementById("txtLote").focus();
document.getElementById("txtLote").select();
}
window.onload = function() {
var fileInput = document.getElementById('fileInput');
var fileDisplayArea = document.getElementById('fileDisplayArea');
fileInput.addEventListener('change', function(e) {
var file = fileInput.files[0];
var textType = /text.*/;
if (file.type.match(textType)) {
var reader = new FileReader();
reader.onload = function(e) {
var string = reader.result ;
array = string.split("|");
maxArray = array.length-1;
var string1 = array[0] ;
var array1 = string1.split(",");
var contenido = "<table class='tbl'>";
contenido += "<tr><td>LOTE</td><td>" + array1[0] + "</td></tr>";
contenido += "<tr><td>DETALLE</td><td>" + array1[1] + "</td> </tr>";
contenido += "<tr><td>CANTIDAD </td><td>" + array1[2] + "</td></tr>";
contenido += "<tr><td>BASE</td><td>" + array1[3] + "</td></tr>";
contenido += "<tr><td>REMITE</td><td>" + array1[6] + "</td></tr>";
contenido += "<tr><td>REMITO</td><td>" + array1[4] + "</td></tr>";
contenido += "<tr><td>RENGLON</td><td>" + array1[5] + "</td></tr>";
contenido += "</table>";
divData.innerHTML = contenido;
document.getElementById("txtLote").focus();
document.getElementById("txtLote").select();
}
reader.readAsText(file);
} else {
fileDisplayArea.innerText = "File not supported!"
}
});
}
</script>
I have found many sites where it is reported that in html5 you can not access a file for a security topic (in a programmatic way), which is necessary to give the user the possibility to search for said file through the "input" that is find the beginning of the code.
QUESTION A) I find it much more unsafe for the user to search the file, I do not understand why they say it's safer?
QUESTION B) Is there a way to access this file without the need for "input", indicating by programming what the file is and how would it be done?
All this using HTML and javascript.
Here I leave part of the .csv file so you can try it.
1, TV 14, 0.00, 1, 337721, 7, QUORTIONI RUBEN | 2, ENVELOPES OF NYLON, 0.00, 400, 337656, 25, PEREZ LUIS | 3, LOT WITH HANGERS, 0.00, 1, 337664, 1, RODOLFO REY | 4, CAJON DE MADERA VALIJA, 0.00, 1, 337723, 5, COLOMBO CARMELO | 5, HOOKS FOR BOARD, 0.00, 60, 337656, 24, PEREZ LUIS | 6, SOPORTE P / TV, 0.00, 1, 337726, 5, TAMBORINI CARLOS | 7, LOTE C / REVISTAS, 0.00, 1, 337727, 8, VARELA ANA | 8, MUSIC TEAM C / 6 PARLANTES, 0.00, 1, 337723, 8, COLOMBO CARMELO | 9, LOTS C / BOOKS, 0.00, 2, 337707, 16, PEREYRA ANDRES |