简体   繁体   English

填写Excel电子表格的表格

[英]Form to fill excel spreadsheet

I've been trying to build an application to submit form selections to an existing spreadsheet on a local machine. 我一直在尝试构建一个应用程序,以将表单选择提交给本地计算机上的现有电子表格。 This is intended for a windows machine, but I am working on ubuntu, and don't have access to a windows development environment. 这适用于Windows机器,但是我正在使用ubuntu,并且无法访问Windows开发环境。 With this, I'm trying to parse an excel document, find the bottom row, capture the 'ingredients' list, or other form values, then insert the value of the hash into the excel column and save the changes to the document. 有了这个,我试图解析一个excel文档,找到底行,捕获“成分”列表或其他表单值,然后将哈希值插入excel列并将更改保存到文档中。 Any suggestions on where I should start would be great. 关于我应该从哪里开始的任何建议都会很棒。 -- Thanks a million - 太感谢了

 //Script $(document).ready(doInput); function doInput(){ var ingreds = $('.ingredients'); var count = $('.count'); var runs = $('#runs'); var cb = $('.cb'); var bb = $('.bb'); var fullDate = new Date(); var twoDigitMonth = ((fullDate.getMonth().length+1) === 1)? (fullDate.getMonth()+1) : '0' + (fullDate.getMonth()+1); var currentDate = twoDigitMonth + "/" + fullDate.getDate() + "/" + fullDate.getFullYear(); var bbDate = fullDate.getMonth() + 8; cb.html("C&B:<br />" + currentDate); if (bbDate > 12){ bb.html("BB:<br />" + "0" + (bbDate - 12) + "/" + fullDate.getDate() + "/" + (fullDate.getFullYear() + 1)); }else{ bb.html("Best By:<br />" + bbDate + "/" + fullDate.getDate() + "/" + fullDate.getFullYear()); } var recipes = { 'Volvo': { 'Torq': 1231, 'Leather': 131, 'Blue': 22 }, 'Jet': { 'HP': 1233, 'Leather': 121, 'Candy': 1313, 'Gas': 1313, 'Billiard': 223 }, 'Mac': { 'Torq': 12111, 'Cheddar': 123 }, 'Hog': { 'Torq': 475, 'Sugar': 12, 'Sheer': 11, 'Water': 2323, 'Wheels': 3 } } var recipe; ingreds.html("Ingredients:<br />"); count.html("The Yield is:" + $('#yield').val() + "?<br />"); if ($("option:selected").val() == 'volv') { recipe = recipes['Volvo']; }else if($("option:selected").val() == 'jet') { recipe = recipes['Jet']; }else if($("option:selected").val() == 'mac') { recipe = recipes['Mac']; }else if($("option:selected").val() == 'hog') { recipe = recipes['Hog']; } for (key in recipe){ if(key == 'Sugar'){ ingreds.append(key + ": " + recipe[key] * runs.val() + 'Lbs<br />'); }else{ ingreds.append(key + ": " + recipe[key] * runs.val() + 'g<br />'); } } return true; } 
 body { background: rgba(150,150,150,.5); } .container { width: 80%; margin: auto; padding: 10px; } .ingredients { padding: 10px; padding-left: 20px; } .count { margin-top: 25px; font-weight: Bold; color: #700; } .submit, .ingredients, .flavor, .runs, .yieldShell, .bestBy, .cb, .bb { min-width: 215px; } .count { min-width: 190px; } .row { margin-right: -15px; margin-left: -15px; } .row:before, .row:after { display: table; content: " "; } .row:after { clear: both; } .col-sm-4{ position: relative; min-height: 1px; padding-right: 15px; padding-left: 15px; } @media (min-width: 540px) { .container { width: 750px; } .col-sm-4 { float: left; width: 33.33333333333333%; } } 
 <script src="https://code.jquery.com/jquery-3.3.1.min.js" integrity="sha256-FgpCb/KJQlLNfOu91ta32o/NMZxltwRo8QtmkMRdAu8=" crossorigin="anonymous"></script> <div class="container"> <form oninput="doInput()"> <div class="row"> <div class="flavor col-sm-4"> Flavor:<br /> <select name="flavors"> <option value="volv" selected="selected">Volvo</option> <option value="jet">Jet</option> <option value="mac">Mac</option> <option value="hog">Hog</option> </select> </div> <div class="runs col-sm-4"> Number of runs:<br /> <input type="number" id="runs" name="runs" value="1"> </div> </div> <div class="row"> <div class="ingredients col-sm-4"></div> <div class="yieldShell col-sm-4"> <div class="yield">Yield:<br /> <input type="number" id="yield" name="yield" value="450"> </div> <div class="count col-sm-4"></div> </div> </div> <div class="row"> <div class="submit col-sm-4"> <input type="submit" value="Save to Production Log?"> </div> <div class="bestBy col-sm-4"> <div class="row"> <div class="col-sm-4 cb"></div> </div> <div class="row"> <div class="col-sm-4 bb"></div> </div> </div> </div> </form> </div> 

Are you not looking at this from the wrong angle? 您不是从错误的角度看这个吗?

Rarely would you try to access an Excel document directly, since the quantity of 'irrelevant' data is huge (data needed by Excel to reconstruct the page itself, but not directly related to the data the user is storing - meta-data if you will; ie font used, size of font, etc.). 很少尝试直接访问Excel文档,因为“无关”的数据量很大(Excel重建页面本身所需的数据,但与用户存储的数据不直接相关-如果您愿意,则为元数据) ;即使用的字体,字体大小等)。

Usually you would output the data to a CSV and allow the user to import the data into any spreadsheet program, which gives you greater flexibility and is simpler to code. 通常,您会将数据输出到CSV,并允许用户将数据导入任何电子表格程序,这为您提供了更大的灵活性并且更易于编写代码。

In terms of adding the data, you could easily open the existing CSV and append new data, or search the file and insert the data where required. 在添加数据方面,您可以轻松地打开现有CSV并添加新数据,或者搜索文件并在需要的地方插入数据。 However, if others are to use the CSV then I'd save the data in a single-table database as well as in the CSV. 但是,如果其他人要使用CSV,那么我会将数据保存在单表数据库以及CSV中。 Then you simply construct a new CSV each time, overwriting any existing file if necessary. 然后,您每次只需构造一个新的CSV,并在必要时覆盖任何现有文件。

No code help here at present, and I might be wrong, but this is the approach I have used and seen used. 目前,这里没有代码帮助,我可能错了,但这是我已经使用并看到使用过的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM