gridjs-spreadsheet 24.12.0 → 25.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{9ab1b217edd126e8925e88cc8f25a154.svg → 555f60323063f2b68b6eac7ce9c45b19.svg} +88 -88
- package/{2922578eabb1a88d1974da56c65189ba.svg → a3b683289420fd8ec937908397907279.svg} +907 -907
- package/example/.classpath +41 -0
- package/example/.project +23 -0
- package/example/Dockerfile +53 -0
- package/example/HELP.md +34 -0
- package/example/README.md +35 -0
- package/example/compose.yaml +1 -0
- package/example/mvnw +250 -0
- package/example/mvnw.cmd +146 -0
- package/example/pom.xml +118 -0
- package/example/src/main/java/com/aspose/gridjs/demo/GridjsdemoApplication.java +91 -0
- package/example/src/main/java/com/aspose/gridjs/demo/LocalFileCache.java +92 -0
- package/example/src/main/java/com/aspose/gridjs/demo/ModifyMonitor.java +21 -0
- package/example/src/main/java/com/aspose/gridjs/demo/controller/DataController.java +128 -0
- package/example/src/main/java/com/aspose/gridjs/demo/controller/GridJs2Controller.java +558 -0
- package/example/src/main/resources/application.properties +17 -0
- package/example/src/main/resources/static/xspread/555f60323063f2b68b6eac7ce9c45b19.svg +88 -0
- package/example/src/main/resources/static/xspread/a3b683289420fd8ec937908397907279.svg +907 -0
- package/example/src/main/resources/static/xspread/bootstrap.min.22.5.5.2.css +1 -0
- package/example/src/main/resources/static/xspread/content/img/20130527034914143.gif +0 -0
- package/example/src/main/resources/static/xspread/content/img/20130527034914229.gif +0 -0
- package/example/src/main/resources/static/xspread/content/img/20130527034916363.gif +0 -0
- package/example/src/main/resources/static/xspread/content/img/20130527034917946.gif +0 -0
- package/example/src/main/resources/static/xspread/content/img/20130527034918372.gif +0 -0
- package/example/src/main/resources/static/xspread/content/img/loading.gif +0 -0
- package/example/src/main/resources/static/xspread/content/img/testupdating.gif +0 -0
- package/example/src/main/resources/static/xspread/content/img/testupdating1.png +0 -0
- package/example/src/main/resources/static/xspread/content/img/updating.gif +0 -0
- package/example/src/main/resources/static/xspread/jquery-2.1.1.js +9190 -0
- package/example/src/main/resources/static/xspread/jquery-ui.min.css +7 -0
- package/example/src/main/resources/static/xspread/jquery-ui.min.js +6 -0
- package/example/src/main/resources/static/xspread/jszip.min.js +13 -0
- package/example/src/main/resources/static/xspread/xspreadsheet.css +1953 -0
- package/example/src/main/resources/static/xspread/xspreadsheet.js +21 -0
- package/example/src/main/resources/templates/fileFromUpload.html +297 -0
- package/example/src/main/resources/templates/index.html +296 -0
- package/example/src/main/resources/templates/list.html +98 -0
- package/example/wb/Sales Report.xlsx +0 -0
- package/example/wb/SampleFile2.xlsx +0 -0
- package/example/wb/TextBoxExample.xlsx +0 -0
- package/example/wb/chart.xlsx +0 -0
- package/example/wb/controls.xlsx +0 -0
- package/example/wb/studenttop.xlsx +0 -0
- package/example/wb/to-do-list.xlsx +0 -0
- package/package.json +1 -1
- package/preview.gif +0 -0
- package/readme.md +42 -8
- package/xspreadsheet.css +27 -3
- package/xspreadsheet.js +5 -5
- package/package.json.bak +0 -52
- package/readme.md.bak +0 -246
|
@@ -0,0 +1,558 @@
|
|
|
1
|
+
package com.aspose.gridjs.demo.controller;
|
|
2
|
+
|
|
3
|
+
import java.io.ByteArrayInputStream;
|
|
4
|
+
import java.io.ByteArrayOutputStream;
|
|
5
|
+
import java.io.FileInputStream;
|
|
6
|
+
import java.io.IOException;
|
|
7
|
+
import java.io.InputStream;
|
|
8
|
+
import java.net.URL;
|
|
9
|
+
import java.net.URLConnection;
|
|
10
|
+
import java.nio.file.Files;
|
|
11
|
+
import java.nio.file.Path;
|
|
12
|
+
import java.nio.file.Paths;
|
|
13
|
+
import java.util.concurrent.ExecutorService;
|
|
14
|
+
import java.util.concurrent.Executors;
|
|
15
|
+
import java.util.zip.GZIPOutputStream;
|
|
16
|
+
|
|
17
|
+
import org.springframework.beans.factory.annotation.Value;
|
|
18
|
+
import org.springframework.core.io.InputStreamResource;
|
|
19
|
+
import org.springframework.http.HttpHeaders;
|
|
20
|
+
import org.springframework.http.HttpStatus;
|
|
21
|
+
import org.springframework.http.MediaType;
|
|
22
|
+
import org.springframework.http.ResponseEntity;
|
|
23
|
+
import org.springframework.web.bind.annotation.GetMapping;
|
|
24
|
+
import org.springframework.web.bind.annotation.PathVariable;
|
|
25
|
+
import org.springframework.web.bind.annotation.PostMapping;
|
|
26
|
+
import org.springframework.web.bind.annotation.RequestMapping;
|
|
27
|
+
import org.springframework.web.bind.annotation.RequestParam;
|
|
28
|
+
import org.springframework.web.bind.annotation.RestController;
|
|
29
|
+
import org.springframework.web.multipart.MultipartFile;
|
|
30
|
+
import org.springframework.web.servlet.ModelAndView;
|
|
31
|
+
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody;
|
|
32
|
+
|
|
33
|
+
import com.aspose.cells.LoadFormat;
|
|
34
|
+
import com.aspose.cells.Workbook;
|
|
35
|
+
import com.aspose.gridjs.Config;
|
|
36
|
+
import com.aspose.gridjs.GridCellException;
|
|
37
|
+
import com.aspose.gridjs.GridInterruptMonitor;
|
|
38
|
+
import com.aspose.gridjs.GridJsWorkbook;
|
|
39
|
+
|
|
40
|
+
import javax.servlet.http.HttpServletRequest;
|
|
41
|
+
import javax.servlet.http.HttpServletResponse;
|
|
42
|
+
import javax.servlet.http.Part;
|
|
43
|
+
|
|
44
|
+
@RestController
|
|
45
|
+
@RequestMapping({"/GridJs2"})
|
|
46
|
+
public class GridJs2Controller {
|
|
47
|
+
@Value("${testconfig.ListDir}")
|
|
48
|
+
private String listDir;//="D:\\codebase\\customerissue\\wb\\tempfromdownload\\";
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
@GetMapping("/DetailFileJsonWithUid")
|
|
53
|
+
public ResponseEntity<String> detailFileJsonWithUid(@RequestParam String filename, @RequestParam String uid) {
|
|
54
|
+
try {
|
|
55
|
+
|
|
56
|
+
Path filePath = Paths.get(listDir, filename);
|
|
57
|
+
GridJsWorkbook wbj = new GridJsWorkbook();
|
|
58
|
+
|
|
59
|
+
// Check if already in cache
|
|
60
|
+
StringBuilder sb = wbj.getJsonByUid(uid, filename);
|
|
61
|
+
if (sb == null) {
|
|
62
|
+
Workbook wb = new Workbook(filePath.toString());
|
|
63
|
+
wbj.importExcelFile(uid, wb);
|
|
64
|
+
sb = wbj.exportToJsonStringBuilder(filename);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Return the content as plain text with UTF-8 encoding
|
|
68
|
+
return ResponseEntity.ok()
|
|
69
|
+
.header("Content-Type", "text/plain; charset=UTF-8")
|
|
70
|
+
.body(sb.toString());
|
|
71
|
+
} catch (Exception e) {
|
|
72
|
+
return ResponseEntity.status(500).body("Error processing the file: " + e.getMessage());
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
@GetMapping("/DetailStreamJsonWithUid")
|
|
77
|
+
public void detailStreamJsonWithUid(@RequestParam String filename, @RequestParam String uid,HttpServletResponse response) {
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
Path filePath = Paths.get(listDir, filename);
|
|
81
|
+
GridJsWorkbook wbj = new GridJsWorkbook();
|
|
82
|
+
|
|
83
|
+
response.setContentType("application/json");
|
|
84
|
+
response.setHeader("Content-Encoding", "gzip");
|
|
85
|
+
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(response.getOutputStream())) {
|
|
86
|
+
boolean isdone= wbj.jsonToStreamByUid(gzipOutputStream,uid, filename);
|
|
87
|
+
if (!isdone) {
|
|
88
|
+
Workbook wb = new Workbook(filePath.toString());
|
|
89
|
+
wbj.importExcelFile(uid,wb);
|
|
90
|
+
wbj.jsonToStream(gzipOutputStream, filename);
|
|
91
|
+
}
|
|
92
|
+
} catch (IOException e) {
|
|
93
|
+
// TODO Auto-generated catch block
|
|
94
|
+
e.printStackTrace();
|
|
95
|
+
} catch (Exception e) {
|
|
96
|
+
// TODO Auto-generated catch block
|
|
97
|
+
e.printStackTrace();
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@Value("${testconfig.UploadPath}")
|
|
103
|
+
private String uploadDir;
|
|
104
|
+
|
|
105
|
+
@GetMapping("/DetailStreamJsonWithUidFromUpload")
|
|
106
|
+
public void detailStreamJsonWithUidFromUpload(@RequestParam String filename, @RequestParam String uid,HttpServletResponse response) {
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
Path filePath = Paths.get(uploadDir, filename);
|
|
110
|
+
GridJsWorkbook wbj = new GridJsWorkbook();
|
|
111
|
+
|
|
112
|
+
response.setContentType("application/json");
|
|
113
|
+
response.setHeader("Content-Encoding", "gzip");
|
|
114
|
+
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(response.getOutputStream())) {
|
|
115
|
+
boolean isdone= wbj.jsonToStreamByUid(gzipOutputStream,uid, filename);
|
|
116
|
+
if (!isdone) {
|
|
117
|
+
Workbook wb = new Workbook(filePath.toString());
|
|
118
|
+
wbj.importExcelFile(uid,wb);
|
|
119
|
+
wbj.jsonToStream(gzipOutputStream, filename);
|
|
120
|
+
}
|
|
121
|
+
} catch (IOException e) {
|
|
122
|
+
// TODO Auto-generated catch block
|
|
123
|
+
e.printStackTrace();
|
|
124
|
+
} catch (Exception e) {
|
|
125
|
+
// TODO Auto-generated catch block
|
|
126
|
+
e.printStackTrace();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
@PostMapping("/LazyLoading")
|
|
131
|
+
public void lazyLoadingStreamJson(
|
|
132
|
+
@RequestParam(value = "name", required = false) String sheetName,
|
|
133
|
+
@RequestParam(value = "uid", required = false) String uid,
|
|
134
|
+
HttpServletResponse response) throws IOException {
|
|
135
|
+
|
|
136
|
+
GridJsWorkbook wbj = new GridJsWorkbook();
|
|
137
|
+
|
|
138
|
+
// 设置响应头
|
|
139
|
+
response.setContentType(MediaType.APPLICATION_JSON_VALUE);
|
|
140
|
+
response.setHeader(HttpHeaders.CONTENT_ENCODING, "gzip");
|
|
141
|
+
|
|
142
|
+
try (GZIPOutputStream gzipOutputStream = new GZIPOutputStream(response.getOutputStream())) {
|
|
143
|
+
try {
|
|
144
|
+
wbj.lazyLoadingStream(gzipOutputStream, uid, sheetName);
|
|
145
|
+
} catch (Exception e) {
|
|
146
|
+
// TODO Auto-generated catch block
|
|
147
|
+
e.printStackTrace();
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
@PostMapping("/UpdateCell")
|
|
153
|
+
public ResponseEntity<String> updateCell(HttpServletRequest request) {
|
|
154
|
+
String p = request.getParameter("p");
|
|
155
|
+
String uid = request.getParameter("uid");
|
|
156
|
+
GridJsWorkbook gwb = new GridJsWorkbook();
|
|
157
|
+
String ret;
|
|
158
|
+
try {
|
|
159
|
+
ret = gwb.updateCell(p, uid);
|
|
160
|
+
return new ResponseEntity<>(ret, HttpStatus.OK);
|
|
161
|
+
} catch (Exception e) {
|
|
162
|
+
// TODO Auto-generated catch block
|
|
163
|
+
return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.OK);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
@PostMapping("/AddImage_FAIL")
|
|
169
|
+
public ResponseEntity<String> addImageFail(HttpServletRequest request) {
|
|
170
|
+
String uid = request.getParameter("uid");
|
|
171
|
+
String p = request.getParameter("p");
|
|
172
|
+
String isControl = request.getParameter("control");
|
|
173
|
+
String ret = null;
|
|
174
|
+
GridJsWorkbook gwb = new GridJsWorkbook();
|
|
175
|
+
try {
|
|
176
|
+
if (isControl == null) {
|
|
177
|
+
Part filePart = request.getPart("image"); // Retrieves <input type="file" name="file">
|
|
178
|
+
if (filePart == null || filePart.getSize() == 0) {
|
|
179
|
+
// for add shape,need to set p.type as one of AutoShapeType
|
|
180
|
+
ret = gwb.insertImage(uid, p, null, null);
|
|
181
|
+
|
|
182
|
+
} else {
|
|
183
|
+
try (InputStream inputStream = filePart.getInputStream()) {
|
|
184
|
+
ret = gwb.insertImage(uid, p, inputStream, null);
|
|
185
|
+
} catch (IOException e) {
|
|
186
|
+
return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.BAD_REQUEST);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
ret = gwb.insertImage(uid, p, null, null);
|
|
191
|
+
}
|
|
192
|
+
return new ResponseEntity<>(ret, HttpStatus.OK);
|
|
193
|
+
} catch (Exception e) {
|
|
194
|
+
// TODO Auto-generated catch block
|
|
195
|
+
return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.OK);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@PostMapping("/AddImage")
|
|
200
|
+
public ResponseEntity<String> handleFileUpload(@RequestParam(value = "image", required = false) MultipartFile file,
|
|
201
|
+
@RequestParam("uid") String uid,
|
|
202
|
+
@RequestParam("p") String p,
|
|
203
|
+
@RequestParam(value = "control", required = false) String isControl) {
|
|
204
|
+
String ret = null;
|
|
205
|
+
GridJsWorkbook gwb = new GridJsWorkbook();
|
|
206
|
+
try {
|
|
207
|
+
if (isControl == null) {
|
|
208
|
+
if (file != null && !file.isEmpty()) {
|
|
209
|
+
try (InputStream inputStream = file.getInputStream()) {
|
|
210
|
+
// Files.copy(inputStream, Paths.get("D:\\tmpdel\\tmp\\gridjsjava\\upload\\123.png"));
|
|
211
|
+
ret = gwb.insertImage(uid, p, inputStream, null);
|
|
212
|
+
|
|
213
|
+
} catch (IOException e) {
|
|
214
|
+
return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.BAD_REQUEST);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
} else {
|
|
219
|
+
// for add shape,need to set p.type as one of AutoShapeType
|
|
220
|
+
ret = gwb.insertImage(uid, p, null, null);
|
|
221
|
+
|
|
222
|
+
}
|
|
223
|
+
} else {
|
|
224
|
+
ret = gwb.insertImage(uid, p, null, null);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return new ResponseEntity<>(ret, HttpStatus.OK);
|
|
228
|
+
} catch (Exception e) {
|
|
229
|
+
e.printStackTrace();
|
|
230
|
+
return ResponseEntity.internalServerError().body("Error occurred while uploading file");
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
@PostMapping("/CopyImage")
|
|
235
|
+
public ResponseEntity<String> copyImage(HttpServletRequest request) {
|
|
236
|
+
String uid = request.getParameter("uid");
|
|
237
|
+
String p = request.getParameter("p");
|
|
238
|
+
GridJsWorkbook gwb = new GridJsWorkbook();
|
|
239
|
+
try {
|
|
240
|
+
String ret = gwb.copyImageOrShape(uid, p);
|
|
241
|
+
|
|
242
|
+
return new ResponseEntity<>(ret, HttpStatus.OK);
|
|
243
|
+
} catch (Exception e) {
|
|
244
|
+
// TODO Auto-generated catch block
|
|
245
|
+
return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.OK);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private static InputStream getStreamFromUrl(String url) throws IOException {
|
|
250
|
+
URL imageUrl = new URL(url);
|
|
251
|
+
URLConnection connection = imageUrl.openConnection();
|
|
252
|
+
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
|
253
|
+
byte[] buffer = new byte[1024];
|
|
254
|
+
int bytesRead;
|
|
255
|
+
try (InputStream in = connection.getInputStream()) {
|
|
256
|
+
while ((bytesRead = in.read(buffer)) != -1) {
|
|
257
|
+
baos.write(buffer, 0, bytesRead);
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return new ByteArrayInputStream(baos.toByteArray());
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
@PostMapping("/AddImageByURL")
|
|
264
|
+
public ResponseEntity<String> addImageByUrl(HttpServletRequest request) {
|
|
265
|
+
String uid = request.getParameter("uid");
|
|
266
|
+
String p = request.getParameter("p");
|
|
267
|
+
String imageUrl = request.getParameter("imageurl");
|
|
268
|
+
String ret = null;
|
|
269
|
+
GridJsWorkbook gwb = new GridJsWorkbook();
|
|
270
|
+
try {
|
|
271
|
+
if (imageUrl != null) {
|
|
272
|
+
try (InputStream stream = getStreamFromUrl(imageUrl)) {
|
|
273
|
+
ret = gwb.insertImage(uid, p, stream, imageUrl);
|
|
274
|
+
} catch (IOException e) {
|
|
275
|
+
return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.BAD_REQUEST);
|
|
276
|
+
}
|
|
277
|
+
} else {
|
|
278
|
+
return new ResponseEntity<>(gwb.errorJson("image url is null"), HttpStatus.BAD_REQUEST);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
return new ResponseEntity<>(ret, HttpStatus.OK);
|
|
282
|
+
} catch (Exception e) {
|
|
283
|
+
// TODO Auto-generated catch block
|
|
284
|
+
return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.OK);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
@GetMapping("/Image")
|
|
289
|
+
public ResponseEntity<InputStreamResource> getImage(HttpServletRequest request) {
|
|
290
|
+
String fileId = request.getParameter("id");
|
|
291
|
+
String uid = request.getParameter("uid");
|
|
292
|
+
try {
|
|
293
|
+
InputStream imageStream = GridJsWorkbook.getImageStream(uid, fileId);
|
|
294
|
+
if (imageStream == null) {
|
|
295
|
+
return ResponseEntity.notFound().build();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
return ResponseEntity.ok()
|
|
299
|
+
.contentType(MediaType.IMAGE_PNG)
|
|
300
|
+
.body(new InputStreamResource(imageStream));
|
|
301
|
+
} catch (Exception e) {
|
|
302
|
+
e.printStackTrace();
|
|
303
|
+
return ResponseEntity.notFound().build();
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
/*
|
|
307
|
+
@GetMapping("/ImageTest")
|
|
308
|
+
public ResponseEntity<InputStreamResource> getImageTest(HttpServletRequest request) {
|
|
309
|
+
try {
|
|
310
|
+
// Load the image file from the classpath (resources folder)
|
|
311
|
+
String fileId = request.getParameter("id");
|
|
312
|
+
String uid = request.getParameter("uid");
|
|
313
|
+
|
|
314
|
+
InputStream imageStream = GridJsWorkbook.getImageStream(uid, fileId);
|
|
315
|
+
if (imageStream == null) {
|
|
316
|
+
return ResponseEntity.notFound().build();
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
// Set the headers for the response
|
|
320
|
+
HttpHeaders headers = new HttpHeaders();
|
|
321
|
+
headers.add("Content-Type", "image/jpeg");
|
|
322
|
+
|
|
323
|
+
// Return the InputStreamResource with the headers
|
|
324
|
+
return ResponseEntity
|
|
325
|
+
.ok()
|
|
326
|
+
.headers(headers)
|
|
327
|
+
.body(new InputStreamResource(imageStream));
|
|
328
|
+
} catch (Exception e) {
|
|
329
|
+
e.printStackTrace();
|
|
330
|
+
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
@GetMapping("/PImage")
|
|
335
|
+
public ResponseEntity<InputStreamResource> getPImage(HttpServletRequest request) {
|
|
336
|
+
String fileId = request.getParameter("id");
|
|
337
|
+
String uid = request.getParameter("uid");
|
|
338
|
+
try {
|
|
339
|
+
InputStream imageStream = GridJsWorkbook.getImageStream(uid, fileId);
|
|
340
|
+
if (imageStream == null) {
|
|
341
|
+
return ResponseEntity.notFound().build();
|
|
342
|
+
}
|
|
343
|
+
InputStreamResource resource = new InputStreamResource(imageStream);
|
|
344
|
+
MediaType mediaType = MediaType.IMAGE_PNG;
|
|
345
|
+
return ResponseEntity.ok()
|
|
346
|
+
.contentType(mediaType)
|
|
347
|
+
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + fileId + "\"")
|
|
348
|
+
.body(resource);
|
|
349
|
+
} catch (Exception e) {
|
|
350
|
+
e.printStackTrace();
|
|
351
|
+
return ResponseEntity.notFound().build();
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
@GetMapping("/pimages/{imageName}")
|
|
356
|
+
public ResponseEntity<InputStreamResource> getImage(@PathVariable("imageName") String imageName) {
|
|
357
|
+
try {
|
|
358
|
+
// Read the image file
|
|
359
|
+
FileInputStream fis = new FileInputStream("C:\\Users\\peter\\Pictures\\test\\" + imageName);
|
|
360
|
+
InputStreamResource resource = new InputStreamResource(fis);
|
|
361
|
+
|
|
362
|
+
// Set the content type based on the image type (JPEG, PNG, etc.)
|
|
363
|
+
MediaType mediaType = MediaType.IMAGE_JPEG; // Change this based on your image type
|
|
364
|
+
|
|
365
|
+
// Create the response entity with the appropriate headers
|
|
366
|
+
return ResponseEntity.ok()
|
|
367
|
+
.contentType(mediaType)
|
|
368
|
+
.header(HttpHeaders.CONTENT_DISPOSITION, "inline; filename=\"" + imageName + "\"")
|
|
369
|
+
.body(resource);
|
|
370
|
+
} catch (IOException e) {
|
|
371
|
+
// Handle the exception, e.g., log it
|
|
372
|
+
e.printStackTrace();
|
|
373
|
+
return ResponseEntity.notFound().build();
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
*/
|
|
377
|
+
|
|
378
|
+
@GetMapping("/Ole")
|
|
379
|
+
public ResponseEntity<?> getOle(HttpServletRequest request) {
|
|
380
|
+
int oleId = Integer.parseInt(request.getParameter("id"));
|
|
381
|
+
String uid = request.getParameter("uid");
|
|
382
|
+
String sheet = request.getParameter("sheet");
|
|
383
|
+
|
|
384
|
+
GridJsWorkbook gwb = new GridJsWorkbook();
|
|
385
|
+
String[] filename = new String[1];
|
|
386
|
+
try {
|
|
387
|
+
byte[] fileByte = gwb.getOle(uid, sheet, oleId, filename);
|
|
388
|
+
|
|
389
|
+
if (filename != null) {
|
|
390
|
+
return ResponseEntity.ok()
|
|
391
|
+
.contentType( (getMimeType(filename[0])))
|
|
392
|
+
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + filename[0] + "\"")
|
|
393
|
+
.body(fileByte);
|
|
394
|
+
} else {
|
|
395
|
+
return ResponseEntity.notFound().build();
|
|
396
|
+
}
|
|
397
|
+
} catch (Exception e) {
|
|
398
|
+
// TODO Auto-generated catch block
|
|
399
|
+
return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.OK);
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
@GetMapping("/ImageUrl")
|
|
405
|
+
public ResponseEntity<String> getImageUrl(@RequestParam String id, @RequestParam String uid) {
|
|
406
|
+
if (GridJsWorkbook.CacheImp != null) {
|
|
407
|
+
return ResponseEntity.ok(GridJsWorkbook.getImageUrl(uid, id, "."));
|
|
408
|
+
} else {
|
|
409
|
+
String file = uid + "." + id;
|
|
410
|
+
return ResponseEntity.ok("/GridJs2/GetZipFile?f=" + file);
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
@GetMapping("/GetZipFile")
|
|
415
|
+
public ResponseEntity<StreamingResponseBody> getZipFile(@RequestParam String f) {
|
|
416
|
+
Path filePath = Paths.get(Config.getFileCacheDirectory(), f);
|
|
417
|
+
|
|
418
|
+
if (!Files.exists(filePath)) {
|
|
419
|
+
return ResponseEntity.notFound().build();
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
StreamingResponseBody responseBody = outputStream -> {
|
|
423
|
+
try (InputStream inputStream = Files.newInputStream(filePath)) {
|
|
424
|
+
byte[] buffer = new byte[1024];
|
|
425
|
+
int bytesRead;
|
|
426
|
+
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
|
427
|
+
outputStream.write(buffer, 0, bytesRead);
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
};
|
|
431
|
+
|
|
432
|
+
return ResponseEntity.ok()
|
|
433
|
+
.contentType(MediaType.APPLICATION_OCTET_STREAM)
|
|
434
|
+
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + f + "\"")
|
|
435
|
+
.body(responseBody);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
public static MediaType getMimeType(String fileName) {
|
|
439
|
+
Path filePath = Paths.get(fileName);
|
|
440
|
+
try {
|
|
441
|
+
// Probe the content type of the file
|
|
442
|
+
String mimeType = Files.probeContentType(filePath);
|
|
443
|
+
|
|
444
|
+
// If the MIME type couldn't be determined, default to binary
|
|
445
|
+
if (mimeType == null) {
|
|
446
|
+
mimeType = "application/octet-stream";
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
// Parse and return the MediaType
|
|
450
|
+
return MediaType.parseMediaType(mimeType);
|
|
451
|
+
|
|
452
|
+
} catch (IOException e) {
|
|
453
|
+
e.printStackTrace();
|
|
454
|
+
// Return a default MediaType in case of an error
|
|
455
|
+
return MediaType.APPLICATION_OCTET_STREAM;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
@GetMapping("/GetFile")
|
|
460
|
+
public ResponseEntity<byte[]> getFile(@RequestParam("id") String fileid,@RequestParam("filename") String filename) throws IOException {
|
|
461
|
+
|
|
462
|
+
MediaType mimeType = getMimeType(filename);
|
|
463
|
+
|
|
464
|
+
// try {
|
|
465
|
+
// TimeUnit.SECONDS.sleep(3); // simulate network lag
|
|
466
|
+
// } catch (InterruptedException e) {
|
|
467
|
+
// Thread.currentThread().interrupt();
|
|
468
|
+
// }
|
|
469
|
+
Path filePath = Paths.get(Config.getFileCacheDirectory(), fileid.replace('/', '.')+"."+filename);
|
|
470
|
+
byte[] bytes = Files.readAllBytes(filePath);
|
|
471
|
+
return ResponseEntity.ok()
|
|
472
|
+
.contentType(mimeType)
|
|
473
|
+
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=" + filename)
|
|
474
|
+
.body(bytes);
|
|
475
|
+
}
|
|
476
|
+
|
|
477
|
+
|
|
478
|
+
//this is for the way that implment GridCacheForStream
|
|
479
|
+
@GetMapping("/GetFileUseCacheStream")
|
|
480
|
+
public ResponseEntity<InputStreamResource> getFileUseCacheStream(@RequestParam("id") String fileid) throws IOException {
|
|
481
|
+
|
|
482
|
+
MediaType mimeType = getMimeType(fileid);
|
|
483
|
+
String name = fileid.replace('/', '.');
|
|
484
|
+
|
|
485
|
+
|
|
486
|
+
InputStream inputStream = GridJsWorkbook.CacheImp.loadStream(fileid);
|
|
487
|
+
if (inputStream == null) {
|
|
488
|
+
// Handle the case where the file is not found
|
|
489
|
+
return ResponseEntity.notFound().build();
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
HttpHeaders headers = new HttpHeaders();
|
|
493
|
+
headers.setContentType(mimeType);
|
|
494
|
+
headers.setContentDispositionFormData("attachment", name);
|
|
495
|
+
|
|
496
|
+
return ResponseEntity.ok()
|
|
497
|
+
.headers(headers)
|
|
498
|
+
.body(new InputStreamResource(inputStream));
|
|
499
|
+
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
|
|
503
|
+
|
|
504
|
+
private static void InterruptMonitor(GridInterruptMonitor monitor,int milliseconds)
|
|
505
|
+
{
|
|
506
|
+
|
|
507
|
+
try
|
|
508
|
+
{
|
|
509
|
+
Thread.sleep(milliseconds);
|
|
510
|
+
|
|
511
|
+
(monitor).interrupt();
|
|
512
|
+
}
|
|
513
|
+
catch (Exception e)
|
|
514
|
+
{
|
|
515
|
+
System.out.println("Succeeded for load in give time.");
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
@PostMapping("/Download")
|
|
520
|
+
public ResponseEntity<String> download(HttpServletRequest request) {
|
|
521
|
+
String p = request.getParameter("p");
|
|
522
|
+
String uid = request.getParameter("uid");
|
|
523
|
+
String filename = request.getParameter("file");
|
|
524
|
+
|
|
525
|
+
GridJsWorkbook gwb = new GridJsWorkbook();
|
|
526
|
+
try {
|
|
527
|
+
gwb.mergeExcelFileFromJson(uid, p);
|
|
528
|
+
|
|
529
|
+
GridInterruptMonitor m = new GridInterruptMonitor();
|
|
530
|
+
gwb.setInterruptMonitorForSave(m);
|
|
531
|
+
|
|
532
|
+
ExecutorService executor = Executors.newSingleThreadExecutor();
|
|
533
|
+
executor.submit(() -> InterruptMonitor(m, 30 * 1000));
|
|
534
|
+
|
|
535
|
+
try {
|
|
536
|
+
gwb.saveToCacheWithFileName(uid, filename, null);
|
|
537
|
+
} catch (Exception ex) {
|
|
538
|
+
if (ex instanceof GridCellException) {
|
|
539
|
+
return ResponseEntity
|
|
540
|
+
.ok(((GridCellException) ex).getMessage() + ((GridCellException) ex).getCode());
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
String fileUrl = null;
|
|
545
|
+
if (GridJsWorkbook.CacheImp != null) {
|
|
546
|
+
fileUrl = GridJsWorkbook.CacheImp.getFileUrl(uid + "/" + filename);
|
|
547
|
+
} else {
|
|
548
|
+
fileUrl = "/GridJs2/GetFile?id=" + uid + "&filename=" + filename;
|
|
549
|
+
}
|
|
550
|
+
return ResponseEntity.ok("\""+fileUrl+"\"");
|
|
551
|
+
} catch (Exception e) {
|
|
552
|
+
// TODO Auto-generated catch block
|
|
553
|
+
return new ResponseEntity<>(gwb.errorJson(e.getMessage()), HttpStatus.OK);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
|
|
558
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
spring.application.name=gridjsdemo
|
|
2
|
+
spring.servlet.multipart.enabled=true
|
|
3
|
+
spring.servlet.multipart.max-file-size=10MB
|
|
4
|
+
spring.servlet.multipart.max-request-size=10MB
|
|
5
|
+
#for local test
|
|
6
|
+
testconfig.ListDir=D:\\codebase\\customerissue\\wb\\tempfromdownload\\
|
|
7
|
+
testconfig.FileName=excelColumnWordBreak.xlsm
|
|
8
|
+
testconfig.CachePath=F:\\storage\\gridjs_temp
|
|
9
|
+
testconfig.UploadPath=F:\\storage\\upload
|
|
10
|
+
testconfig.AsposeLicensePath=F:\\aspose.lic
|
|
11
|
+
#for docker linux
|
|
12
|
+
#testconfig.ListDir=/app/wb
|
|
13
|
+
#testconfig.FileName=controls.xlsx
|
|
14
|
+
#testconfig.CachePath=/app/grid_cache
|
|
15
|
+
#testconfig.UploadPath=/app/upload
|
|
16
|
+
#testconfig.AsposeLicensePath=/app/aspose.lic
|
|
17
|
+
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<!-- Generator: Adobe Illustrator 25.0.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
|
|
3
|
+
<svg version="1.1" id="图层_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
|
|
4
|
+
viewBox="0 0 22 22" style="enable-background:new 0 0 22 22;" xml:space="preserve">
|
|
5
|
+
<style type="text/css">
|
|
6
|
+
.st0{fill:url(#SVGID_1_);}
|
|
7
|
+
.st1{fill:url(#SVGID_2_);}
|
|
8
|
+
.st2{fill:url(#SVGID_3_);}
|
|
9
|
+
.st3{fill:url(#SVGID_4_);}
|
|
10
|
+
.st4{opacity:0.6;}
|
|
11
|
+
.st5{opacity:0.38;fill:url(#SVGID_5_);enable-background:new ;}
|
|
12
|
+
.st6{opacity:0.38;fill:url(#SVGID_6_);enable-background:new ;}
|
|
13
|
+
.st7{opacity:0.38;fill:url(#SVGID_7_);enable-background:new ;}
|
|
14
|
+
.st8{opacity:0.38;fill:url(#SVGID_8_);enable-background:new ;}
|
|
15
|
+
</style>
|
|
16
|
+
<g>
|
|
17
|
+
|
|
18
|
+
<radialGradient id="SVGID_1_" cx="519.1851" cy="-127.3083" r="8.2454" gradientTransform="matrix(0 1 -0.9943 0 -113.4659 -506.377)" gradientUnits="userSpaceOnUse">
|
|
19
|
+
<stop offset="0.1429" style="stop-color:#D5EFFC"/>
|
|
20
|
+
<stop offset="0.8424" style="stop-color:#3C8EC6"/>
|
|
21
|
+
<stop offset="1" style="stop-color:#3399CC"/>
|
|
22
|
+
</radialGradient>
|
|
23
|
+
<path class="st0" d="M21,13.6c0-0.5,0.5-6.4-4.6-9.1C14.1,3.2,10.9,3.2,9.1,5C6,8.2,8.6,11.5,9.6,11.8c0,0,0,0,0-0.1
|
|
24
|
+
c-1.6-6.3,9.3-7.4,11.2,1.8C20.9,13.9,21,13.9,21,13.6z"/>
|
|
25
|
+
|
|
26
|
+
<radialGradient id="SVGID_2_" cx="446.2906" cy="702.4343" r="5.9862" gradientTransform="matrix(0.9943 0 0 1 -430.3552 -688)" gradientUnits="userSpaceOnUse">
|
|
27
|
+
<stop offset="0.1429" style="stop-color:#FEE588"/>
|
|
28
|
+
<stop offset="0.5636" style="stop-color:#F79B30"/>
|
|
29
|
+
<stop offset="0.6867" style="stop-color:#F58B2D"/>
|
|
30
|
+
<stop offset="0.8883" style="stop-color:#F3752A"/>
|
|
31
|
+
<stop offset="1" style="stop-color:#F36C29"/>
|
|
32
|
+
</radialGradient>
|
|
33
|
+
<path class="st1" d="M8.5,21.2c0.5,0,6.4,0.5,9.1-4.6c1.3-2.4,1.2-5.6-0.5-7.4c-3.1-3.1-6.4-0.5-6.8,0.5c0,0,0,0,0.1,0
|
|
34
|
+
c6.2-1.6,7.3,9.3-1.8,11.3C8.3,21,8.3,21.1,8.5,21.2z"/>
|
|
35
|
+
|
|
36
|
+
<radialGradient id="SVGID_3_" cx="-378.6884" cy="623.4329" r="8.246" gradientTransform="matrix(0 -1 0.9943 0 -610.95 -369.3066)" gradientUnits="userSpaceOnUse">
|
|
37
|
+
<stop offset="0" style="stop-color:#FCB116"/>
|
|
38
|
+
<stop offset="0.193" style="stop-color:#FBB318"/>
|
|
39
|
+
<stop offset="0.3352" style="stop-color:#F9B91C"/>
|
|
40
|
+
<stop offset="0.461" style="stop-color:#F6C323"/>
|
|
41
|
+
<stop offset="0.5767" style="stop-color:#F4D12D"/>
|
|
42
|
+
<stop offset="0.6727" style="stop-color:#F0E03A"/>
|
|
43
|
+
<stop offset="0.7439" style="stop-color:#E5D534"/>
|
|
44
|
+
<stop offset="0.8645" style="stop-color:#CFBD24"/>
|
|
45
|
+
<stop offset="1" style="stop-color:#B19E11"/>
|
|
46
|
+
</radialGradient>
|
|
47
|
+
<path class="st2" d="M1,8.6c0,0.5-0.5,6.4,4.6,9.1C8,19,11.2,18.9,13,17.2c3.1-3.2,0.5-6.5-0.5-6.8c0,0,0,0,0,0.1
|
|
48
|
+
c1.6,6.3-9.3,7.4-11.2-1.8C1.2,8.3,1.1,8.3,1,8.6z"/>
|
|
49
|
+
|
|
50
|
+
<radialGradient id="SVGID_4_" cx="445.619" cy="696.9989" r="8.2461" gradientTransform="matrix(0.9943 0 0 1 -430.3552 -688)" gradientUnits="userSpaceOnUse">
|
|
51
|
+
<stop offset="0" style="stop-color:#A1C43A"/>
|
|
52
|
+
<stop offset="0.4545" style="stop-color:#A0CC3A"/>
|
|
53
|
+
<stop offset="1" style="stop-color:#3C943A"/>
|
|
54
|
+
</radialGradient>
|
|
55
|
+
<path class="st3" d="M13.5,1C13,1,7.1,0.6,4.5,5.7C3.2,8.1,3.2,11.3,5,13c3.1,3.1,6.4,0.5,6.8-0.5c0,0,0,0-0.1,0
|
|
56
|
+
c-6.2,1.6-7.3-9.3,1.8-11.3C13.8,1.2,13.8,1.1,13.5,1z"/>
|
|
57
|
+
<g class="st4">
|
|
58
|
+
|
|
59
|
+
<radialGradient id="SVGID_5_" cx="413.168" cy="345.1736" r="9.5277" gradientTransform="matrix(1.0925 0 0 1.6216 -440.2973 -540.7683)" gradientUnits="userSpaceOnUse">
|
|
60
|
+
<stop offset="0" style="stop-color:#F9E788"/>
|
|
61
|
+
<stop offset="1" style="stop-color:#FFFFFF"/>
|
|
62
|
+
</radialGradient>
|
|
63
|
+
<path class="st5" d="M11,5.2c-0.9,0-1.7,0.2-2.4,0.5c-2.3,3,0.1,5.9,1,6.2c0,0,0,0,0-0.1C8.7,8,12.4,6,15.8,7.2
|
|
64
|
+
C14.7,6,12.9,5.2,11,5.2z"/>
|
|
65
|
+
|
|
66
|
+
<radialGradient id="SVGID_6_" cx="413.1686" cy="345.1745" r="9.5274" gradientTransform="matrix(1.0925 0 0 1.6216 -440.2973 -540.7683)" gradientUnits="userSpaceOnUse">
|
|
67
|
+
<stop offset="0" style="stop-color:#F9E788"/>
|
|
68
|
+
<stop offset="1" style="stop-color:#FFFFFF"/>
|
|
69
|
+
</radialGradient>
|
|
70
|
+
<path class="st6" d="M10.3,9.7C10.3,9.7,10.3,9.7,10.3,9.7c3.8-0.9,5.7,2.7,4.6,6.1c1.5-1.1,2.4-2.8,2.4-4.7
|
|
71
|
+
c0-0.7-0.1-1.4-0.4-2.1C13.8,6.1,10.6,8.7,10.3,9.7z"/>
|
|
72
|
+
|
|
73
|
+
<radialGradient id="SVGID_7_" cx="413.1689" cy="345.1732" r="9.526" gradientTransform="matrix(1.0925 0 0 1.6216 -440.2973 -540.7683)" gradientUnits="userSpaceOnUse">
|
|
74
|
+
<stop offset="0" style="stop-color:#F9E788"/>
|
|
75
|
+
<stop offset="1" style="stop-color:#FFFFFF"/>
|
|
76
|
+
</radialGradient>
|
|
77
|
+
<path class="st7" d="M12.5,10.4C12.4,10.3,12.4,10.4,12.5,10.4c0.9,3.9-2.7,5.8-6.2,4.6C7.4,16.2,9.1,17,11,17
|
|
78
|
+
c0.9,0,1.7-0.2,2.4-0.5C15.7,13.6,13.4,10.7,12.5,10.4z"/>
|
|
79
|
+
|
|
80
|
+
<radialGradient id="SVGID_8_" cx="413.168" cy="345.1736" r="9.5275" gradientTransform="matrix(1.0925 0 0 1.6216 -440.2973 -540.7683)" gradientUnits="userSpaceOnUse">
|
|
81
|
+
<stop offset="0" style="stop-color:#F9E788"/>
|
|
82
|
+
<stop offset="1" style="stop-color:#FFFFFF"/>
|
|
83
|
+
</radialGradient>
|
|
84
|
+
<path class="st8" d="M11.8,12.5C11.8,12.5,11.8,12.5,11.8,12.5C8,13.5,6.1,9.9,7.2,6.4c-1.5,1.1-2.4,2.8-2.4,4.7
|
|
85
|
+
c0,0.7,0.1,1.4,0.4,2.1C8.3,16.1,11.4,13.5,11.8,12.5z"/>
|
|
86
|
+
</g>
|
|
87
|
+
</g>
|
|
88
|
+
</svg>
|