forked from terrywbrady/PlainTextCSV_GoogleAppsScript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathIndex.html
112 lines (112 loc) · 4.08 KB
/
Index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
//Pass the uploaded file object (formObject.file) to the web service, extract CSV content from the uploaded file
function handleFormSubmit(formObject) {
jQuery("input:button").attr("disabled",true);
google.script.run.withSuccessHandler(updateOutput).withFailureHandler(fail).processFile(formObject);
}
//Pass CSV content as a string (formObject.data)
function handleFormPost(formObject) {
jQuery("input:button").attr("disabled",true);
google.script.run.withSuccessHandler(updateOutput).withFailureHandler(fail).doTextPost(formObject);
}
//Display the name and URL of the Google Sheet that was created
function updateOutput(data) {
var resp = jQuery.parseJSON(data);
document.getElementById("output").innerHTML="<a href='"+resp.url+"'>"+resp.name+"</a> created on Google Drive";
}
//Display and error dialog
function fail(data) {
alert("FAIL: "+data);
}
</script>
<style type="text/css">
fieldset {
width: 750px;
margin-bottom: 5px;
}
</style>
</head>
<body>
<h2>Create a Plain Text Google Spreadsheet That Prevents Auto-Format of Data Cells</h2>
<div>In addition to the forms provided below, you can POST data to this webservice directly.</div>
<h4>Link to new Spreadsheet</h4>
<div id="output">Once you upload data, a link to the Google Sheet will appear here</div>
<hr/>
<h4>Upload a CSV File</h4>
<form id="myForm">
<div>
<fieldset>
<legend><label for="name">Name to assign to spreadsheet (optional)</label></legend>
<input name="name" id="name" size="60"></input>
</fieldset>
</div>
<div>
<fieldset>
<legend><label for="folderid">Google Sheets Folder Id (optional)</label></legend>
<input name="folderid" id="folderid" size="60"></input>
</fieldset>
</div>
<div>
<fieldset>
<legend><label for="delim">Delimiter</label></legend>
<select name="delim" id="delim">
<option value=",">comma</option>
<option value=";">semicolon</option>
<option value="	">tab</option>
<option value="|">pipe</option>
</select>
</fieldset>
</div>
<div>
<fieldset>
<legend><label for="file">CSV File to Upload</label></legend>
<input name="file" type="file" id="file"/>
<div>
<input type="button" value="Upload CSV" name="button" onclick="handleFormSubmit(document.getElementById('myForm'))"/>
</div>
</fieldset>
</div>
</form>
<hr/>
<h4>Upload the Text from a CSV file</h4>
<form id="myPostForm" method="POST">
<div>
<fieldset>
<legend><label for="name2">Name to assign to spreadsheet (optional)</label></legend>
<input name="name" size="60" id="name2"></input>
</fieldset>
</div>
<div>
<fieldset>
<legend><label for="folderid2">Google Sheets Folder Id (optional)</label></legend>
<input name="folderid" size="60" id="folderid2"></input>
</fieldset>
</div>
<div>
<fieldset>
<legend><label for="delim2">Delimiter</label></legend>
<select name="delim" id="delim2">
<option value=",">comma</option>
<option value=";">semicolon</option>
<option value="	">tab</option>
<option value="|">pipe</option>
</select>
</fieldset>
</div>
<div>
<fieldset>
<legend><label for="data2">CSV File to Upload</label></legend>
<textarea name="data" rows="10" cols="100" id="data2"></textarea>
<div>
<input type="button" value="Upload Data" name="button" onclick="handleFormPost(document.getElementById('myPostForm'))"/>
</div>
</fieldset>
</div>
</form>
</body>
</html>