1
+ <div id="Saveasjson">
2
+ <label id="Heading">Save As Json Options:</label> <br>
3
+ <input type="checkbox" id="valueOnly" onchange="toggleCheckboxes()"><label for="valueOnly">Only Values</label>
4
+ <input type="checkbox" id="style"><label for="style">Ignore Style</label>
5
+ <input type="checkbox" id="formula"><label for="formula">Ignore Formula</label>
6
+ <input type="checkbox" id="format"><label for="format">Ignore Format</label>
7
+ <input type="checkbox" id="cf"><label for="cf">Ignore CF</label>
8
+ <input type="checkbox" id="dv"><label for="dv">Ignore Validation</label>
9
+ <input type="checkbox" id="freeze"><label for="freeze">Ignore Freezepane</label>
10
+ <input type="checkbox" id="wrap"><label for="wrap">Ignore Wrap</label>
11
+ <input type="checkbox" id="chart"><label for="chart">Ignore Chart</label>
12
+ <input type="checkbox" id="image"><label for="image">Ignore Image</label>
13
+ <input type="checkbox" id="note"><label for="note">Ignore Note</label>
14
+ <button id="save" onclick="saveFile()">Save with JSON Serialization</button>
15
+ </div>
16
+ <ejs-spreadsheet id="spreadsheet" openUrl="Open" allowOpen="true"> </ejs-spreadsheet>
17
+
18
+ <style>
19
+ #Saveasjson {
20
+ margin-top: 10px;
21
+ margin-bottom: 20px;
22
+ }
23
+
24
+ #Saveasjson input[type="checkbox"] {
25
+ margin: 7px;
26
+ }
27
+
28
+ #Saveasjson label {
29
+ font-size: 14px;
30
+ }
31
+
32
+ #Heading {
33
+ font-weight: bold;
34
+ }
35
+ </style>
36
+
37
+ <script>
38
+
39
+ function toggleCheckboxes() {
40
+ let valueOnlyCheckbox = document.getElementById('valueOnly');
41
+ let checkboxes = document.querySelectorAll('#Saveasjson input[type="checkbox"]:not(#valueOnly)');
42
+ checkboxes.forEach(checkbox => {
43
+ checkbox.disabled = valueOnlyCheckbox.checked;
44
+ if (valueOnlyCheckbox.checked) {
45
+ checkbox.checked = false;
46
+ }
47
+ });
48
+ }
49
+
50
+ function createOptions() {
51
+ const options = {};
52
+ options.ignoreStyle = document.getElementById('style').checked;
53
+ options.ignoreFormula = document.getElementById('formula').checked;
54
+ options.ignoreFormat = document.getElementById('format').checked;
55
+ options.ignoreConditionalFormat = document.getElementById('cf').checked;
56
+ options.ignoreValidation = document.getElementById('dv').checked;
57
+ options.ignoreFreezePane = document.getElementById('freeze').checked;
58
+ options.ignoreWrap = document.getElementById('wrap').checked;
59
+ options.ignoreChart = document.getElementById('chart').checked;
60
+ options.ignoreImage = document.getElementById('image').checked;
61
+ options.ignoreNote = document.getElementById('note').checked;
62
+ return options;
63
+ }
64
+
65
+ function saveFile() {
66
+ let valueOnlyCheckbox = document.getElementById("valueOnly").checked;
67
+ let options = valueOnlyCheckbox ? { onlyValues: true } : createOptions();
68
+ var spreadsheetObj = document.getElementById("spreadsheet").ej2_instances[0];
69
+ spreadsheetObj.saveAsJson(options).then((response) => {
70
+ let formData = new FormData();
71
+ formData.append('JSONData', JSON.stringify(response.jsonObject.Workbook));
72
+ formData.append('fileName', 'Sample');
73
+ formData.append('saveType', 'Xlsx');
74
+ formData.append('pdfLayoutSettings', JSON.stringify({ fitSheetOnOnePage: false, orientation: 'Portrait' }));
75
+ fetch('https://services.syncfusion.com/js/production/api/spreadsheet/save', {
76
+ method: 'POST',
77
+ body: formData,
78
+ }).then((response) => {
79
+ response.blob().then((data) => {
80
+ let anchor = document.createElement('a');
81
+ anchor.download = 'Sample.xlsx';
82
+ let url = URL.createObjectURL(data);
83
+ anchor.href = url;
84
+ document.body.appendChild(anchor);
85
+ anchor.click();
86
+ URL.revokeObjectURL(url);
87
+ document.body.removeChild(anchor);
88
+ });
89
+ });
90
+ });
91
+ }
92
+ </script>
0 commit comments