离线Javascript Ran自动更新计算器和电子表格

时间:2016-04-27 05:37:45

标签: javascript html5 spreadsheet openoffice.org

说明

我需要制作一个电子表格类型计算器来跟踪在线游戏(ArcheAge)中的信息。这个"电子表格"必须保存信息并自动更新一组值,增量为5分钟(最好保存为文件到他们的计算机。这是我正在处理的离线应用程序。)

详细信息:

我被要求协助设置OpenOffice电子表格以跟踪和保存信息。大多数数据都是手动输入并保存在他们已经制作的电子表格中,但是他有一个问题是让一个字段以5分钟的增量自动更新。

我看了一下他有什么,并试图设置一个简单的(劳动=劳动+ 10 [每5分钟])类型的公式,但由于电子表格不能使用循环引用,因此无法将该字段设置为自动每5分钟更新一次。

电子表格包含9列数据和24行组。列是(id)(charName)(人工)(freeLabor)(职业)(令牌)(timeOnline)(realTime)(订阅),加上他添加了一个单元格来保存日期而另一个单位来保存时间(两者都来自系统)时钟 - 日期()和现在())。

每行是1个字符的信息(会考虑数据库表)。

他希望每个角色的(人工)值每5分钟自动更新一次,其值为劳动力(人工=劳动力+10),但这是循环参考,电子表格不能执行此功能(至少没有第三方程序或加载项,据我所知)。

所以,我看着它,试图找到一个解决方法。在网上查了很多帖子,接近找到了解决方案,但没有人帮我们做什么。因此,我提议为他设置.html文档以使用离线并将其编码为电子表格。代码如下。

需要: 编辑:参考变更3以下。

我需要尝试找到一种方法将此表单数据保存到主机PC上的文件中(离线),这样用户无需在每次运行表单时手动重新输入所有数据

注意 - 此部分已在此行下方更改。

我需要非PhP(javascript和html或其他方法)解决方案来增加每个字符集的劳动力单元格,每5分钟增加10点。他希望单元数据可以在不破坏代码的情况下进行修改(比如getData,运行代码来递增,并将新值重写到单元格)。我还想尝试将代码保存到文件中,因此每次运行文档时都不必重新输入值。

解决方案应该在使用html和javascript时显示表格,电子表格或数据库等数据。如果您有其他解决方法,请随时添加您对如何创建此数据表的想法。

编辑1:我想我应该提到(工党)的价值不应超过5,000,不能低于0. - 添加01:43 27Apr2016

编辑2:更好地识别了需要"需要"块。 - 添加01:51 2016年4月27日

编辑3:修改了人工计算的第一个Javascript代码。它现在是 for 循环中的嵌套 if 语句,现在可以完美运行。现在我需要的是一种将表单数据保存到文档的方法,或者一个单独的文档,供程序调用(如果可能)。更新需求部分。 - 2016年4月27日05:52

以下是代码:

HTML

<section>
<!-- Used to create time stamp at top of page. -->
<p id="time"></p>

<!-- Name of page. -->
<header style="text-align: center;">ArcheAge Test Calculator</header>
<br />

<!-- The Form shown on the page. -->
<form id-form1" name="testcalc">
    <!-- Nested Table in Form.-->
    <table>
        <tr>
            <th>Character Name</th>
            <th>Labor</th>
            <th>Free Labor</th>
            <th>Vocation</th>
            <th>Tokens</th>
            <th>Time/Online</th>
            <th>Subscription</th>
        </tr>
        <tr>
            <td><input type="text" id="name1" value="Solareclipse" name="charname"/></td>
            <td><input type="text" id="labor1" value="" name="labor"/></th>
            <td><input type="text" id="free1" value="Test data" name="freelabor"/></td>
            <td><input type="text" id="vocation1" value="Test data" name="voc"/></td>
            <td><input type="text" id="tokens1" value="Test data" name="token"/></td>
            <td><input type="text" id="online1" value="Test data" name="online"/></td>
            <td><input type="text" id="sub1" value="Test data" name="sub"/></td>        
        </tr>
        <tr>
            <td><input type="text" id="name2" value="Farmergirl" name="charname"/></td>
            <td><input type="text" id="labor2"/></td>
            <td><input type="text" id="free2" value="" name="freelabor"/></td>
            <td><input type="text" id="vocation2" value="" name="voc"/></td>
            <td><input type="text" id="tokens2" value="" name="token"/></td>
            <td><input type="text" id="online2" value="" name="online"/></td>
            <td><input type="text" id="sub2" value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name3" value="Peacemaker" name="charname"/></td>
            <td><input type="text" id="labor3"/></td>
            <td><input type="text" id="free3" value="" name="freelabor"/></td>
            <td><input type="text" id="vocation3" value="" name="voc"/></td>
            <td><input type="text" id="tokens3" value="" name="token"/></td>
            <td><input type="text" id="online3" value="" name="online"/></td>
            <td><input type="text" id="sub3" value="" name="sub"/></td>         
        </tr>
        <tr>
            <td><input type="text" id="name4" value="Irene" name="charname"/></td>
            <td><input type="text" id="labor4"/></td>
            <td><input type="text" id="free4" value="" name="freelabor"/></td>
            <td><input type="text" id="vocation4" value="" name="voc"/></td>
            <td><input type="text" id="tokens4" value="" name="token"/></td>
            <td><input type="text" id="online4" value="" name="online"/></td>
            <td><input type="text" id="sub4" value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name5" value="Admiral" name="charname"/></td>
            <td><input type="text" id="labor5"/></td>
            <td><input type="text" id="free5" value="" name="freelabor"/></td>
            <td><input type="text" id="vocation5" value="" name="voc"/></td>
            <td><input type="text" id="tokens5" value="" name="token"/></td>
            <td><input type="text" id="online5" value="" name="online"/></td>
            <td><input type="text" id="sub5" value="" name="sub"/></td>         
        </tr>
        <tr>
            <td><input type="text" id="name6" value="Huffer" name="charname"/></td>
            <td><input type="text" id="labor6"/></td>
            <td><input type="text" id="free6" value="" name="freelabor"/></td>
            <td><input type="text" id="vocation6" value="" name="voc"/></td>
            <td><input type="text" id="tokens6" value="" name="token"/></td>
            <td><input type="text" id="online6" value="" name="online"/></td>
            <td><input type="text" id="sub6" value="" name="sub"/></td> 
        </tr>
        <tr>
            <td><input type="text" id="name7" value="Sisco" name="charname"/></td>
            <td><input type="text" id="labor7"/></td>
            <td><input type="text" id="free7" value="" name="freelabor"/></td>
            <td><input type="text" id="vocation7" value="" name="voc"/></td>
            <td><input type="text" id="tokens7" value="" name="token"/></td>
            <td><input type="text" id="online7" value="" name="online"/></td>
            <td><input type="text" id="sub7" value="" name="sub"/></td> 
        </tr>
        <tr>
            <td><input type="text" id="name8" value="Martha" name="charname"/></td>
            <td><input type="text" id="labor8"/></td>
            <td><input type="text" id="free8" value="" name="freelabor"/></td>
            <td><input type="text" id="vocation8" value="" name="voc"/></td>
            <td><input type="text" id="tokens8" value="" name="token"/></td>
            <td><input type="text" id="online8" value="" name="online"/></td>
            <td><input type="text" id="sub8" value="" name="sub"/></td> 
        </tr>
        <tr>
            <td><input type="text" id="name9" value="Octavia" name="charname"/></td>
            <td><input type="text" id="labor9"/></td>
            <td><input type="text" id="free9" value="" name="freelabor"/></td>
            <td><input type="text" id="vocation9"value="" name="voc"/></td>
            <td><input type="text" id="tokens9"value="" name="token"/></td>
            <td><input type="text" id="online9"value="" name="online"/></td>
            <td><input type="text" id="sub9"value="" name="sub"/></td>  
        </tr>
        <tr>
            <td><input type="text" id="name10" value="Samantha" name="charname"/></td>
            <td><input type="text" id="labor10"/></td>
            <td><input type="text" id="free10"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation10"value="" name="voc"/></td>
            <td><input type="text" id="tokens10"value="" name="token"/></td>
            <td><input type="text" id="online10"value="" name="online"/></td>
            <td><input type="text" id="sub10"value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name11" value="Joker" name="charname"/></td>
            <td><input type="text" id="labor11"/></td>
            <td><input type="text" id="free11"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation11"value="" name="voc"/></td>
            <td><input type="text" id="tokens11"value="" name="token"/></td>
            <td><input type="text" id="online11"value="" name="online"/></td>
            <td><input type="text" id="sub11"value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name12" value="GoodKush" name="charname"/></td>
            <td><input type="text" id="labor12"/></td>
            <td><input type="text" id="free12"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation12"value="" name="voc"/></td>
            <td><input type="text" id="tokens12"value="" name="token"/></td>
            <td><input type="text" id="online12"value="" name="online"/></td>
            <td><input type="text" id="sub12"value="" name="sub"/></td> 
        </tr>
        <tr>
            <td><input type="text" id="name13" value="Minerguy" name="charname"/></td>
            <td><input type="text" id="labor13"/></td>
            <td><input type="text" id="free13"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation13"value="" name="voc"/></td>
            <td><input type="text" id="tokens13"value="" name="token"/></td>
            <td><input type="text" id="online13"value="" name="online"/></td>
            <td><input type="text" id="sub13"value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name14" value="Lunareclipse" name="charname"/></td>
            <td><input type="text" id="labor14"/></td>
            <td><input type="text" id="free14"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation14"value="" name="voc"/></td>
            <td><input type="text" id="tokens14"value="" name="token"/></td>
            <td><input type="text" id="online14"value="" name="online"/></td>
            <td><input type="text" id="sub14"value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name15" value="Peacemaker" name="charname"/></td>
            <td><input type="text" id="labor15"/></td>
            <td><input type="text" id="free15"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation15"value="" name="voc"/></td>
            <td><input type="text" id="tokens15"value="" name="token"/></td>
            <td><input type="text" id="online15"value="" name="online"/></td>
            <td><input type="text" id="sub15"value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name16" value="Minergirl" name="charname"/></td>
            <td><input type="text" id="labor16"/></td>
            <td><input type="text" id="free16"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation16"value="" name="voc"/></td>
            <td><input type="text" id="tokens16"value="" name="token"/></td>
            <td><input type="text" id="online16"value="" name="online"/></td>
            <td><input type="text" id="sub16"value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name17" value="Commander" name="charname"/></td>
            <td><input type="text" id="labor17"/></td>
            <td><input type="text" id="free17"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation17"value="" name="voc"/></td>
            <td><input type="text" id="tokens17"value="" name="token"/></td>
            <td><input type="text" id="online17"value="" name="online"/></td>
            <td><input type="text" id="sub17"value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name18" value="Minerguyy" name="charname"/></td>
            <td><input type="text" id="labor18"/></td>
            <td><input type="text" id="free18"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation18"value="" name="voc"/></td>
            <td><input type="text" id="tokens18"value="" name="token"/></td>
            <td><input type="text" id="online18"value="" name="online"/></td>
            <td><input type="text" id="sub18"value="" name="sub"/></td>         
        </tr>
        <tr>
            <td><input type="text" id="name19" value="Odoo" name="charname"/></td>
            <td><input type="text" id="labor19"/></td>
            <td><input type="text" id="free19"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation19"value="" name="voc"/></td>
            <td><input type="text" id="tokens19"value="" name="token"/></td>
            <td><input type="text" id="online19"value="" name="online"/></td>
            <td><input type="text" id="sub19"value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name20" value="Pheobe" name="charname"/></td>
            <td><input type="text" id="labor20"/></td>
            <td><input type="text" id="free20"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation20"value="" name="voc"/></td>
            <td><input type="text" id="tokens20"value="" name="token"/></td>
            <td><input type="text" id="online20"value="" name="online"/></td>
            <td><input type="text" id="sub20"value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name21" value="Spacewalker" name="charname"/></td>
            <td><input type="text" id="labor21"/></td>
            <td><input type="text" id="free21"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation21"value="" name="voc"/></td>
            <td><input type="text" id="tokens21"value="" name="token"/></td>
            <td><input type="text" id="online21"value="" name="online"/></td>
            <td><input type="text" id="sub21"value="" name="sub"/></td>         
        </tr>
        <tr>
            <td><input type="text" id="name22" value="Drunkflowers" name="charname"/></td>
            <td><input type="text" id="labor22"/></td>
            <td><input type="text" id="free22"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation22"value="" name="voc"/></td>
            <td><input type="text" id="tokens22"value="" name="token"/></td>
            <td><input type="text" id="online22"value="" name="online"/></td>
            <td><input type="text" id="sub22"value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name23" value="Joker" name="charname"/></td>
            <td><input type="text" id="labor23"/></td>
            <td><input type="text" id="free23"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation23"value="" name="voc"/></td>
            <td><input type="text" id="tokens23"value="" name="token"/></td>
            <td><input type="text" id="online23"value="" name="online"/></td>
            <td><input type="text" id="sub23"value="" name="sub"/></td>     
        </tr>
        <tr>
            <td><input type="text" id="name24" value="Badkush" name="charname"/></td>
            <td><input type="text" id="labor24"/></td>
            <td><input type="text" id="free24"value="" name="freelabor"/></td>
            <td><input type="text" id="vocation24"value="" name="voc"/></td>
            <td><input type="text" id="tokens24"value="" name="token"/></td>
            <td><input type="text" id="online24"value="" name="online"/></td>
            <td><input type="text" id="sub24"value="" name="sub"/></td>     
        </tr>   
    </table><!-- End Table -->
</form><!-- End Form -->

的JavaScript

&#13;
&#13;
<!-- Script to run Labor calculations. -->
<script type="text/javascript">
	
	function increment(){
		for(var i=1; i<=24; i++){
			var id = "labor"+i;
			var points = document.getElementById(id).value;
			if(points>=4990){
				document.getElementById(id).value=5000;
			}
			else{
				document.getElementById(id).value=Number(document.getElementById(id).value)+10;
			}
		}
	}
	increment()
</script>

<!-- Script to run Time Stamp at top of page. -->
<script type="text/javascript">
	var date = new Date();
	var n = date.toDateString();
	var time = date.toLocaleTimeString();
	
	document.getElementById('time').innerHTML = n + ' ' + time;
</script>
&#13;
&#13;
&#13;

1 个答案:

答案 0 :(得分:1)

你还没有真正说出你的问题所在,所以我会向你介绍for循环的魔力。

不要写24次相同的行,而是编写一次这段代码!

for(var i=1; i<=24; i++){
    var id = "labor" + i;
    var n = Number(document.getElementById(id).innerHTML);
    n += 10;
    document.getElementById(id).innerHTML = n;
}

说明:

for循环在开头创建变量i,并将其设置为1.对于第一个循环,我们需要文本&#34; labor1&#34;,因此创建另一个变量id,即劳动和#34;的联合无论我是什么(现在,1)。

然后做你的document.getElementById("labor1").value事情,但因为变量id已经是&#34; labor1&#34;我们可以在循环中替换它。 + = 10位只是&#34;这个值加10的简写。&#34;

for循环然后检查我是否小于24(它是)并且i ++位将i加1(所以它现在为2)。然后循环重复相同的代码23次,直到i> 1。 24。

如果你很聪明,你也可以通过编程方式创建页面,因为看起来很多元素都会重复出现。