- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何使我的Excel文件作为网页工作,人们可以在其中输入数据并将其保留在那里?我是新来的!
最佳答案
该练习所需的技术:JavaScript,JQuery,PHP,AJAX和MySQL。和Excel!所有这一切都需要进行较小的编辑,仅向生成的html页面添加3行文本。
http://ip.jawfin.net上正在运行演示
我想指出,Excel另存为html的格式已被严重破坏-Excel 2013生成了非常干净的html,其样式内置于注释中(因此仅生成了1个文件,没有CSS),它的缩进和简单易用读书。唯一的缺点是样式的类名称相当随意!没有JavaScript,只有纯HTML,这是一个不错的开始,然后在Notepad ++或您喜欢的编辑器中进行优化。请注意,缺少CSS可能会再次咬住您,为广泛使用,我建议提取注释以从中构建CSS。
首先,我们的Excel。这是我制作的,这是一个简单的应用程序,它将您的IP放在屏幕上选择的单元格中。 (此方法的实际用途是安排一个月的调度程序,这种“选择颜色”可以很好地演示所有功能,希望可以轻松适应。)不过,有一项更改是,我将访问者的IP用作保护。
这是我的Excel文件:http://ip.jawfin.net/ip.xlsx
我们不会导出整个电子表格,只需选择要构成网页的单元格即可。就我而言:-
选择单元格后,进入"file" /“另存为”,选择文件夹,另存为网页(* .htm),仅选择“选择项”,如果需要,为其命名,将其命名为index.htm,然后保存!
现在,将index.htm重命名为index.php,因为我们将php代码放入其中。现在,使这3行代码成为一个交互式网页。在底部的</body>
和</html>
之间插入以下3行:-
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<?php include 'excel.php';?>
<script src="excel.js"></script>
所以我们有:-
</body>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<?php include 'excel.php';?>
<script src="excel.js"></script>
</html>
导入JQuery的第一行可让我们的AJAX正常工作。
field:cell; type:integer; index:primary + unique
field:ip; type:text
或如phpMyAdmin中所示:-
index.php the one we just created in Excel, goes in the web folder
excel.php the file which fetches server-side variables (note we could also use this to inject dynamically created controls)
excel.js the script running local interface, also communicates with the server
server.php the database handler on the server, deals with the AJAX requests and database manipulations
settings.php just a means of storing the database configuration in a safe place
<?php //excel.php
//Let's create a string specific to the user without giving away private info
$ip = $_SERVER['REMOTE_ADDR']; //I'm going with hashing the md5 of their IP, then mod'ing back to 12 digits (from 38)
$hash = fmod(hexdec(md5($ip)),1e12);
echo '<script>'; //clever means of getting a php variable into javascript
echo 'var user_ip = ' . json_encode($hash) . ';'; //replace $hash with $ip you want to see the real address!
echo '</script>';
?>
excel.js
//excel.js
$.ajaxSetup({ cache: false }); //needed to stop IE/Edge from caching AJAX GET requests
var cells = document.getElementsByTagName("td"); //array of all cells, excel assigns them type HTML table cell "td"
var updating = false; //prevent flicker if writing to the dataset and a read overwrites our status messages
var reentry = false; //prevent overlapping refresh. polls 1 a sec, 5 second time-out, could lead to massive overlap!
var addingStr = ' -- Adding IP --'; //const not used for backwards compatibility, IE9 etc.
var removeStr = ' -- Removing IP --';
var replaceStr = ' -- Replacing IP --';
for (var i = 0; i < cells.length; i++) { //you can assign different aspects by the .innerHTML
cells[i].style.cursor = 'cell'; //or 'pointer' - the default is the edit caret cursor which looks ugly
cells[i].id = i; //tag our elements, but note this is happening AFTER the DCOM scan so getElementById() won't work
cells[i].onclick = function() { cellClick(this); };
}
refreshScreen();
setInterval(function() { //ajax poll, refresh every second!
refreshScreen();
}, 1000);
function cellClick(cell) {
updating = true; //don't allow the refresh to remove our status comment in the cell
var mydata = 'action=';
if (cell.innerHTML == "" || cell.innerHTML == " ") {
cell.innerHTML = addingStr;
mydata += 'c'; //write into this cell the users IP
} else {
if (cell.innerHTML == user_ip) { //let's be smart and allow them to remove their own IP :)
cell.innerHTML = removeStr;
mydata += 'd'; //clear/delete this cell
} else { //it's someone else, hijack them!!
cell.innerHTML = replaceStr;
mydata += 'u'; //update this cell
}
}
mydata += '&cell=' + cell.id + '&ip=' + user_ip; //add our parameters
$.ajax({ //JQuery ajax, so much cleaner and safer than using JavaScript ajax
url: "server.php", //our server-side worker
type: 'POST', //database changes, use POST, we don't want a webcrawler or a cache hitting a GET with parameters
data: mydata,
timeout: 5000, //5 second should be ample, but if they lose connectivity allow it to fail
success:
function(data) {
updating = false;
if (data != 1) { //no matter what, in this CRUD only 1 record should have been affected
alert('Data update error. Parameters: ' + data + '. Result: ' + data);
}
refreshScreen(); //refresh screen with new data
},
error:
function(xhr, ajaxOptions, thrownError) { //put better error handling in if this fires too often!
// alert('Data = ' + mydata + '. Error # = ' + xhr.status + '. Message = '+thrownError); //uncommend to debug
updating = false;
refreshScreen();
}
});
}
function refreshScreen() {
if (updating) return; //just wait a second
if (reentry) return; //we're already pending a refresh
reentry = true;
var mydata = 'action=r'; //we want to Read the data - stored in a varible in case we turn on our error alert
$.ajax({
url: "server.php",
type: 'POST',
data: mydata,
timeout: 5000,
// dataType: 'json', //just saves us a line of formatting text on success. !!commented out, not debug friendly
success: function(data) { //on recieve of reply
reentry = false;
if (updating) return; //they clicked between the request and the return here, just wait it out, next second!
data = JSON.parse(data); //i prefer this instead of dataType:'json' so I check server script errors in the throw
var results = []; //get our data into a 2 dimensional array (has 2 dimensions as our query returned 2 fields
for(var x in data) { //get all the data ready before we touch the screen, cut down any possibly latency
results.push(data[x]);
}
for (var i = 0; i < cells.length; i++) { //reset screen
if (cells[i].innerHTML != removeStr) { //skipping the "Remove" messages (dirty read) - will clean up below if they were removed!
cells[i].innerHTML = ""; //clear field
}
}
for (var i = 0; i < results.length; i++) { //now we stuff our cells with the IPs we have
cells[results[i][0]].innerHTML = results[i][1]; //first array element is cell number, the second is the IP
}
//as the "Remove" status was skipped above need to loop again to clear any found
for (var i = 0; i < cells.length; i++) { //backwards clean
if (cells[i].innerHTML == removeStr) { //text is here as this cell didn't come through the SELECT
cells[i].innerHTML = ""; //clear field
}
}
},
error:
function(xhr, ajaxOptions, thrownError) { //uncomment alert for debugging
reentry = false;
// alert('Query = ' + mydata + '. Error # = ' + xhr.status + '. Message = '+thrownError);
//Note that xhr.status == 200 is an OK from the server but JSON invalid, so check for that first!
}
});
}
server.php
<?php //server.php
if (!isset($_POST['action'])) exit; //no action parameter, just leave. could echo an error message if required though
$action = $_POST['action'];
if (!strpos(' crud',$action)) { //note the space out front, or else it'll fail on 'c' as it returns zero, which = false
echo("Unknown action='$action'"); // took me ages to debug that, resulting in this line of code!!!!
exit; //otherwise not one of ours, quit before SQL stuff starts
}
require "../settings.php"; //lazy place to easily store settings out of reach from the Internet, parent of the web root.
//Be aware I used ".." - if this server.php is not in the webroot then the database.php is not out of reach.
//Note this method is easier than loading an .ini file and parsing it within an array.
if ($db_server == "") { //ASSERT: this should never fire as the require would fail on not find, but can't be too sure
echo "Problem getting database settings.";
exit;
}
$connection = mysql_connect($db_server, $db_username, $db_password); // Establishing Connection with Server
if (!$connection) {
echo "Error connecting to database.";
exit;
}
$db = mysql_select_db($db_database_ip, $connection); // Selecting Database
if (!$db) {
echo "Specific database not found.";
exit;
}
if ($action == 'c') { //note this will fail if there is a blank record against this cell, so check here
$cell = mysql_real_escape_string($_POST['cell']); //extract our parameter
$ip = mysql_real_escape_string($_POST['ip']);
if ($ip == "") {
echo "Cannot add blank IP in cell '$cell'";
} else {
$query = mysql_query("INSERT INTO cell_ip(cell, ip) values ('$cell', '$ip')"); //Create Query
echo $query; //always return the result, even if its unexpected. can hold error messages for debugging
}
}
if ($action == 'r') { //JSON our database back to the client.
//Note I am using the POST protol instead of GET, tidier on this server.php keeping all my server requests in one file
$result = mysql_query("SELECT cell, ip FROM cell_ip"); //Read Query
while ($row = mysql_fetch_row($result)) {
$table_data[] = $row;
}
echo json_encode($table_data); //return the whole dataset
}
if ($action == 'u') { //pinching someone else's cell with our ip, make sure the new ip exists too
$cell = mysql_real_escape_string($_POST['cell']);
$ip = mysql_real_escape_string($_POST['ip']);
if ($ip == "") {
echo "Cannot edit to a blank IP in cell '$cell'";
} else {
$query = mysql_query("UPDATE cell_ip SET ip = '$ip' WHERE cell = '$cell'"); //Update Query
echo $query;
}
}
if ($action == 'd') { //delete this cell
$cell = mysql_real_escape_string($_POST['cell']); //extract our parameter
$query = mysql_query("DELETE FROM cell_ip WHERE cell = '$cell'"); //Delete Query
echo $query;
}
mysql_close($connection); //Note this was never opened if the caller failed the "action" validation, being polite to our sql
?>
settings.php(这进入根目录,更改其中的值以适合)
<?php //settings.php
$db_server='localhost';
$db_username='root';
$db_password='root_password';
$db_database_ip='excel_ip';
?>
注意事项:-
关于javascript - 如何使Excel文件成为交互式网页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36822392/
我正在开发一个使用 JTable 的简单 Java 应用程序。我正在尝试实现我所看到的here 。给定链接上的表格的行为与我在表格中想要的行为完全相同。我已完全按照引用链接上显示的方式进行操作。 但是
我需要将 *.ml 文件加载到 Ocaml 顶层(交互式解释器,当您在 shell 中键入“ocaml”时),然后从 Matlab 进程发送指令,获取指令结果,发送返回另一条指令,... 我编写了这个
我正在尝试实现交互式 UILocalNotifications。 以下是我的代码。我无法获得接收通知的 3 个操作按钮。 UIMutableUserNotificationAction *nActio
我不是一个干净的 CSS 编码器,所以这可能是我问题的症结所在……但是……我从本教程中拼凑了一张交互式 map :http://www.noobcube.com/tutorials/html-css/
这个问题在这里已经有了答案: 关闭 13 年前。 Possible Duplicate: How to save a Python interactive session? 我可以在“头脑 Stor
我试图在不扩展 ListActivity 类的情况下创建交互式 ListView。布局应该是左侧的 RatingBar 和标签向右。这是我目前的代码,没有任何编译错误,但在应用程序启动时崩溃: pub
我正在尝试使用 antlr 编写一种简单的交互式(使用 System.in 作为源)语言,但我遇到了一些问题。我在网上找到的例子都是使用每行循环,例如: while(readline) resul
我想创建一个交互式 JTable。为此,我想在表格的单元格中添加 JPanel。一旦 JPanel 位于单元格中,我就可以将我的各种组件添加到 JPanel 中,从而使表格具有交互性。每个 JPane
我有两个具有完全相同文件的分支(如果您想知道它是一个 .sql 文件),我想以交互方式 merge 它。 我非常想像在发生冲突(或命令行)时那样打开一个 diff 程序,然后准确选择行到哪里。 有什么
我想用交互式 rebase 编辑一个提交。当我用 edit 替换 pick 时,此提交的更改仍应用于 repo(以便我可以编辑提交)但我想从头开始重写它。我该怎么做? 最佳答案 在交互式 rebase
来自 Python relative imports for the billionth time : 要使 from .. import 起作用,模块名称中的点数必须至少与 import 语句中的点
如何使条形与一整天一样宽?现在,条形图更像是划分一天的开始的线。我是否从条形标记切换到矩形标记?我会玩带秤吗?或者我是否在不修改数据的情况下强制分箱? 现在条形图太细了。因为图形是交互式的,所以我无法
是否有任何命令行技巧可以让 SVN 添加来自 svn stat 的所有丢失的文件?互动? 例如,类似于: svn add --interactive $ new file: file1.tmp
我想知道这是否可以(可能不是)使用 R 中的并行处理后端之一来完成。 .我尝试了一些谷歌搜索,但一无所获。 我目前遇到的一般问题: 我有一些大物体需要大约半小时才能到达 load 我想在数据上生成一系
我一直在关注问题 here 的建议暂时将各种提示/信息放在我在 Altair 中的地 block 上。但是,如果 Altair 绘图设置为 interactive(),则此建议不起作用 - 在我看来,
简短的问题是,如果 shell 位于不拥有 tty 的孤立进程组中,它应该做什么?但我建议阅读长问题,因为它很有趣。 这是一种有趣且令人兴奋的方法,可以使用您最喜欢的 shell 将您的笔记本电脑变成
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 这个问题似乎不是关于 a specific programming problem, a software
已关闭。此问题不符合Stack Overflow guidelines 。目前不接受答案。 要求我们推荐或查找工具、库或最喜欢的场外资源的问题对于 Stack Overflow 来说是偏离主题的,因为
有没有办法实现交互式 cli,允许您从多个选项中进行选择? 我想要实现如下目标: 显示的示例是使用 JavaScript 中的 Quirer.js 库实现的,但我似乎找不到在 Java 中实现类似功能
我正在尝试使用运行一些命令的输入脚本来运行交互式 R (Windows XP),然后让我进入 R 命令行提示符。但是,当我运行它时,它会退出。 例如,这是输入文件: test.r: x = 1 x 以
我是一名优秀的程序员,十分优秀!