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
package/example/pom.xml
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
|
3
|
+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
4
|
+
<modelVersion>4.0.0</modelVersion>
|
|
5
|
+
<parent>
|
|
6
|
+
<groupId>org.springframework.boot</groupId>
|
|
7
|
+
<artifactId>spring-boot-starter-parent</artifactId>
|
|
8
|
+
<version>2.5.14</version>
|
|
9
|
+
<relativePath/> <!-- lookup parent from repository -->
|
|
10
|
+
</parent>
|
|
11
|
+
<repositories>
|
|
12
|
+
<repository>
|
|
13
|
+
<id>AsposeJavaAPI</id>
|
|
14
|
+
<name>Aspose Java API</name>
|
|
15
|
+
<url>https://repository.aspose.com/repo/</url>
|
|
16
|
+
</repository>
|
|
17
|
+
</repositories>
|
|
18
|
+
<groupId>com.aspose.gridjs</groupId>
|
|
19
|
+
<artifactId>gridjsdemo</artifactId>
|
|
20
|
+
<version>1.0.0-SNAPSHOT</version>
|
|
21
|
+
<name>gridjsdemo</name>
|
|
22
|
+
<description>GridJs Demo project for Spring Boot</description>
|
|
23
|
+
<properties>
|
|
24
|
+
<java.version>8</java.version>
|
|
25
|
+
</properties>
|
|
26
|
+
<dependencies>
|
|
27
|
+
<dependency>
|
|
28
|
+
<groupId>org.springframework.boot</groupId>
|
|
29
|
+
<artifactId>spring-boot-starter-freemarker</artifactId>
|
|
30
|
+
</dependency>
|
|
31
|
+
<dependency>
|
|
32
|
+
<groupId>org.springframework.boot</groupId>
|
|
33
|
+
<artifactId>spring-boot-starter-thymeleaf</artifactId>
|
|
34
|
+
</dependency>
|
|
35
|
+
<dependency>
|
|
36
|
+
<groupId>org.springframework.boot</groupId>
|
|
37
|
+
<artifactId>spring-boot-starter-web</artifactId>
|
|
38
|
+
</dependency>
|
|
39
|
+
|
|
40
|
+
<dependency>
|
|
41
|
+
<groupId>org.springframework.boot</groupId>
|
|
42
|
+
<artifactId>spring-boot-devtools</artifactId>
|
|
43
|
+
<scope>runtime</scope>
|
|
44
|
+
<optional>true</optional>
|
|
45
|
+
</dependency>
|
|
46
|
+
<dependency>
|
|
47
|
+
<groupId>com.google.code.gson</groupId>
|
|
48
|
+
<artifactId>gson</artifactId>
|
|
49
|
+
<version>2.9.0</version> <!-- 使用你需要的Gson版本 -->
|
|
50
|
+
</dependency>
|
|
51
|
+
<dependency>
|
|
52
|
+
<groupId>com.aspose</groupId>
|
|
53
|
+
<artifactId>aspose-cells</artifactId>
|
|
54
|
+
<version>25.1</version>
|
|
55
|
+
</dependency>
|
|
56
|
+
<dependency>
|
|
57
|
+
<groupId>com.aspose</groupId>
|
|
58
|
+
<artifactId>aspose-cells</artifactId>
|
|
59
|
+
<version>25.1</version>
|
|
60
|
+
<classifier>gridjs</classifier>
|
|
61
|
+
</dependency>
|
|
62
|
+
<!-- <dependency>
|
|
63
|
+
<groupId>org.springframework.boot</groupId>
|
|
64
|
+
<artifactId>spring-boot-docker-compose</artifactId>
|
|
65
|
+
<scope>runtime</scope>
|
|
66
|
+
<optional>true</optional>
|
|
67
|
+
</dependency>-->
|
|
68
|
+
<dependency>
|
|
69
|
+
<groupId>org.projectlombok</groupId>
|
|
70
|
+
<artifactId>lombok</artifactId>
|
|
71
|
+
<optional>true</optional>
|
|
72
|
+
</dependency>
|
|
73
|
+
<dependency>
|
|
74
|
+
<groupId>org.springframework.boot</groupId>
|
|
75
|
+
<artifactId>spring-boot-starter-test</artifactId>
|
|
76
|
+
<scope>test</scope>
|
|
77
|
+
<exclusions>
|
|
78
|
+
<exclusion>
|
|
79
|
+
<groupId>org.junit.vintage</groupId>
|
|
80
|
+
<artifactId>junit-vintage-engine</artifactId>
|
|
81
|
+
</exclusion>
|
|
82
|
+
</exclusions>
|
|
83
|
+
</dependency>
|
|
84
|
+
<!-- JUnit Jupiter for writing tests -->
|
|
85
|
+
<dependency>
|
|
86
|
+
<groupId>org.junit.jupiter</groupId>
|
|
87
|
+
<artifactId>junit-jupiter-api</artifactId>
|
|
88
|
+
<version>5.6.0</version>
|
|
89
|
+
<scope>test</scope>
|
|
90
|
+
</dependency>
|
|
91
|
+
|
|
92
|
+
<!-- JUnit Jupiter Engine for running tests -->
|
|
93
|
+
<dependency>
|
|
94
|
+
<groupId>org.junit.jupiter</groupId>
|
|
95
|
+
<artifactId>junit-jupiter-engine</artifactId>
|
|
96
|
+
<version>5.6.0</version>
|
|
97
|
+
<scope>test</scope>
|
|
98
|
+
</dependency>
|
|
99
|
+
</dependencies>
|
|
100
|
+
|
|
101
|
+
<build>
|
|
102
|
+
<plugins>
|
|
103
|
+
<plugin>
|
|
104
|
+
<groupId>org.springframework.boot</groupId>
|
|
105
|
+
<artifactId>spring-boot-maven-plugin</artifactId>
|
|
106
|
+
<configuration>
|
|
107
|
+
<excludes>
|
|
108
|
+
<exclude>
|
|
109
|
+
<groupId>org.projectlombok</groupId>
|
|
110
|
+
<artifactId>lombok</artifactId>
|
|
111
|
+
</exclude>
|
|
112
|
+
</excludes>
|
|
113
|
+
</configuration>
|
|
114
|
+
</plugin>
|
|
115
|
+
</plugins>
|
|
116
|
+
</build>
|
|
117
|
+
|
|
118
|
+
</project>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
package com.aspose.gridjs.demo;
|
|
2
|
+
|
|
3
|
+
import org.springframework.beans.factory.annotation.Value;
|
|
4
|
+
import org.springframework.boot.SpringApplication;
|
|
5
|
+
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
6
|
+
import org.springframework.stereotype.Component;
|
|
7
|
+
import org.springframework.context.ApplicationContext;
|
|
8
|
+
|
|
9
|
+
import com.aspose.cells.Workbook;
|
|
10
|
+
import com.aspose.gridjs.Config;
|
|
11
|
+
import com.aspose.gridjs.GridJsWorkbook;
|
|
12
|
+
|
|
13
|
+
import javax.annotation.PostConstruct;
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@Component
|
|
17
|
+
class MyConfig {
|
|
18
|
+
|
|
19
|
+
@Value("${testconfig.CachePath}")
|
|
20
|
+
public String cachePath;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@Value("${testconfig.AsposeLicensePath}")
|
|
24
|
+
public String asposeLicensePath;
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@SpringBootApplication
|
|
30
|
+
public class GridjsdemoApplication {
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
//settings for GridJs,implement GridCacheForStream to store cache file
|
|
36
|
+
private static void init(MyConfig myConfig) {
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
Config.setFileCacheDirectory(myConfig.cachePath);
|
|
42
|
+
//lazy loading
|
|
43
|
+
Config.setLazyLoading(true);
|
|
44
|
+
} catch (Exception e) {
|
|
45
|
+
e.printStackTrace();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
// when use GridJsWorkbook.CacheImp,no need to setImageUrlBase
|
|
49
|
+
// GridJsWorkbook.setImageUrlBase("/GridJs2/Image");
|
|
50
|
+
|
|
51
|
+
LocalFileCache mwc = new LocalFileCache();
|
|
52
|
+
GridJsWorkbook.CacheImp = mwc;
|
|
53
|
+
GridJsWorkbook.UpdateMonitor = new ModifyMonitor();
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//settings for GridJs,just set a temp path to store cache file
|
|
57
|
+
//simple way not use GridJsWorkbook.CacheImp ,it shall also ok
|
|
58
|
+
private static void init2(MyConfig myConfig) {
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
Config.setFileCacheDirectory(myConfig.cachePath);
|
|
62
|
+
//lazy loading
|
|
63
|
+
Config.setLazyLoading(true);
|
|
64
|
+
|
|
65
|
+
} catch (Exception e) {
|
|
66
|
+
e.printStackTrace();
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
//need to setImageUrlBase in this case
|
|
70
|
+
GridJsWorkbook.setImageUrlBase("/GridJs2/Image");
|
|
71
|
+
GridJsWorkbook.UpdateMonitor = new ModifyMonitor();
|
|
72
|
+
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
public static void main(String[] args) {
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
ApplicationContext context = SpringApplication.run(GridjsdemoApplication.class, args);
|
|
81
|
+
|
|
82
|
+
MyConfig myConfig = context.getBean(MyConfig.class);
|
|
83
|
+
|
|
84
|
+
//set license for aspose cells
|
|
85
|
+
com.aspose.cells.License lic=new com.aspose.cells.License();
|
|
86
|
+
//lic.setLicense(myConfig.asposeLicensePath);
|
|
87
|
+
init(myConfig);
|
|
88
|
+
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
package com.aspose.gridjs.demo;
|
|
2
|
+
|
|
3
|
+
import java.io.ByteArrayInputStream;
|
|
4
|
+
import java.io.ByteArrayOutputStream;
|
|
5
|
+
import java.io.File;
|
|
6
|
+
import java.io.FileInputStream;
|
|
7
|
+
import java.io.FileNotFoundException;
|
|
8
|
+
import java.io.FileOutputStream;
|
|
9
|
+
import java.io.IOException;
|
|
10
|
+
import java.io.InputStream;
|
|
11
|
+
import java.nio.file.Files;
|
|
12
|
+
import java.nio.file.Paths;
|
|
13
|
+
|
|
14
|
+
import com.aspose.cells.SaveFormat;
|
|
15
|
+
import com.aspose.cells.Workbook;
|
|
16
|
+
import com.aspose.gridjs.Config;
|
|
17
|
+
import com.aspose.gridjs.GridCacheForStream;
|
|
18
|
+
|
|
19
|
+
public class LocalFileCache extends GridCacheForStream {
|
|
20
|
+
|
|
21
|
+
private String streamcacheDir=null;
|
|
22
|
+
//default constructor
|
|
23
|
+
public LocalFileCache() {
|
|
24
|
+
//make sure the cache path existed
|
|
25
|
+
streamcacheDir=Paths.get(Config.getFileCacheDirectory(), "streamcache").toString();
|
|
26
|
+
File dir = new File(streamcacheDir);
|
|
27
|
+
if (!dir.exists()) {
|
|
28
|
+
try {
|
|
29
|
+
Files.createDirectories(Paths.get(streamcacheDir));
|
|
30
|
+
} catch (IOException e) {
|
|
31
|
+
// TODO Auto-generated catch block
|
|
32
|
+
e.printStackTrace();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@Override
|
|
38
|
+
public void saveStream(InputStream s, String uid) {
|
|
39
|
+
// save stream to the cache path with uid
|
|
40
|
+
String filepath = Paths.get(streamcacheDir, uid.replace('/', '.')).toString();
|
|
41
|
+
try (FileOutputStream fos = new FileOutputStream(filepath.toString())) {
|
|
42
|
+
s.reset(); // Equivalent to s.Position = 0 in C#
|
|
43
|
+
byte[] buffer = new byte[1024];
|
|
44
|
+
int length;
|
|
45
|
+
while ((length = s.read(buffer)) > 0) {
|
|
46
|
+
fos.write(buffer, 0, length);
|
|
47
|
+
}
|
|
48
|
+
fos.flush();
|
|
49
|
+
} catch (IOException e) {
|
|
50
|
+
e.printStackTrace();
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Override
|
|
56
|
+
public InputStream loadStream(String uid) {
|
|
57
|
+
//load file from the cache path by uid
|
|
58
|
+
String filepath = Paths.get(streamcacheDir, uid.replace('/', '.')).toString();
|
|
59
|
+
try {
|
|
60
|
+
//here you can update the stream per your business logic if you wish
|
|
61
|
+
//for example below we modify the cell a1 value to hello
|
|
62
|
+
/*
|
|
63
|
+
Workbook wb = new Workbook(filepath);
|
|
64
|
+
wb.getWorksheets().get(0).getCells().get("A1").putValue("hello");
|
|
65
|
+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
|
|
66
|
+
wb.save(bos, SaveFormat.XLSX);
|
|
67
|
+
byte[] byteArray = bos.toByteArray();
|
|
68
|
+
bos.close();
|
|
69
|
+
ByteArrayInputStream bis = new ByteArrayInputStream(byteArray);
|
|
70
|
+
return bis;
|
|
71
|
+
*/
|
|
72
|
+
return new FileInputStream(filepath);
|
|
73
|
+
} catch (FileNotFoundException e) {
|
|
74
|
+
e.printStackTrace();
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
@Override
|
|
80
|
+
public boolean isExisted(String uid) {
|
|
81
|
+
//check if the file with uid existed in the cache path
|
|
82
|
+
String filepath = Paths.get(streamcacheDir, uid.replace('/', '.')).toString();
|
|
83
|
+
return Files.exists(Paths.get(filepath));
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
//return the action Url to get the file from the cache path by uid
|
|
87
|
+
@Override
|
|
88
|
+
public String getFileUrl(String uid) {
|
|
89
|
+
return "/GridJs2/GetFileUseCacheStream?id=" + uid;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
package com.aspose.gridjs.demo;
|
|
2
|
+
|
|
3
|
+
import java.util.ArrayList;
|
|
4
|
+
|
|
5
|
+
import com.aspose.cells.Workbook;
|
|
6
|
+
|
|
7
|
+
public class ModifyMonitor extends com.aspose.gridjs.GridUpdateMonitor{
|
|
8
|
+
|
|
9
|
+
@Override
|
|
10
|
+
public void afterUpdate(String operation, String uid, ArrayList cells) {
|
|
11
|
+
System.out.println("afterUpdate operation is:"+operation+" ,uid is:"+uid+",modified cells count:"+cells.size());
|
|
12
|
+
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
@Override
|
|
16
|
+
public void beforeUpdate(String operation, String uid, Workbook wb) {
|
|
17
|
+
System.out.println("beforeUpdate operation is:"+operation+" ,uid is:"+uid+",workbook sheets count:"+wb.getWorksheets().getActiveSheetName());
|
|
18
|
+
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
package com.aspose.gridjs.demo.controller;
|
|
2
|
+
|
|
3
|
+
import java.io.File;
|
|
4
|
+
import java.io.IOException;
|
|
5
|
+
import java.io.InputStream;
|
|
6
|
+
import java.nio.file.Files;
|
|
7
|
+
import java.nio.file.Path;
|
|
8
|
+
import java.nio.file.Paths;
|
|
9
|
+
import java.util.ArrayList;
|
|
10
|
+
import java.util.List;
|
|
11
|
+
|
|
12
|
+
import org.springframework.beans.factory.annotation.Value;
|
|
13
|
+
import org.springframework.http.ResponseEntity;
|
|
14
|
+
import org.springframework.web.bind.annotation.GetMapping;
|
|
15
|
+
import org.springframework.web.bind.annotation.PostMapping;
|
|
16
|
+
import org.springframework.web.bind.annotation.RequestMapping;
|
|
17
|
+
import org.springframework.web.bind.annotation.RequestParam;
|
|
18
|
+
import org.springframework.web.bind.annotation.RestController;
|
|
19
|
+
import org.springframework.web.multipart.MultipartFile;
|
|
20
|
+
import org.springframework.web.servlet.ModelAndView;
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
import com.aspose.gridjs.GridJsWorkbook;
|
|
24
|
+
|
|
25
|
+
@RestController
|
|
26
|
+
@RequestMapping({"/gridjsdemo"})
|
|
27
|
+
public class DataController {
|
|
28
|
+
@Value("${testconfig.FileName}")
|
|
29
|
+
private String testFileName;//="chart.xlsx";
|
|
30
|
+
|
|
31
|
+
@Value("${testconfig.ListDir}")
|
|
32
|
+
private String listDir;
|
|
33
|
+
|
|
34
|
+
@GetMapping({"/index"})
|
|
35
|
+
public ModelAndView getIndexPage()
|
|
36
|
+
{
|
|
37
|
+
String uid = GridJsWorkbook.getUidForFile(testFileName);
|
|
38
|
+
|
|
39
|
+
ModelAndView mv = new ModelAndView();
|
|
40
|
+
mv.addObject("uid", uid);
|
|
41
|
+
mv.addObject("file", testFileName);
|
|
42
|
+
mv.setViewName("index");
|
|
43
|
+
return mv;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
@GetMapping("/list")
|
|
47
|
+
public ModelAndView listFiles() {
|
|
48
|
+
|
|
49
|
+
List<String[]> filelist = new ArrayList<>();
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
File dir = new File(listDir);
|
|
53
|
+
if (dir.exists() && dir.isDirectory()) {
|
|
54
|
+
File[] files = dir.listFiles();
|
|
55
|
+
if (files != null) {
|
|
56
|
+
for (File file : files) {
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
String filename=file.getName();
|
|
60
|
+
|
|
61
|
+
//get a unique id for the file
|
|
62
|
+
String uid = GridJsWorkbook.getUidForFile(filename);
|
|
63
|
+
String[] ff={filename,uid};
|
|
64
|
+
filelist.add(ff);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
ModelAndView mv = new ModelAndView();
|
|
70
|
+
|
|
71
|
+
mv.addObject("filelist", filelist);
|
|
72
|
+
|
|
73
|
+
mv.setViewName("list");
|
|
74
|
+
return mv;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@GetMapping("/Uidtml")
|
|
78
|
+
public ModelAndView uidtml(@RequestParam String filename,@RequestParam String uid) {
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
ModelAndView mv = new ModelAndView();
|
|
83
|
+
mv.addObject("uid", uid);
|
|
84
|
+
mv.addObject("file", filename);
|
|
85
|
+
mv.setViewName("index");
|
|
86
|
+
return mv;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
@Value("${testconfig.UploadPath}")
|
|
90
|
+
private String uploadDir;
|
|
91
|
+
|
|
92
|
+
@PostMapping("/upload")
|
|
93
|
+
public ModelAndView uploadFile(@RequestParam("file") MultipartFile file) {
|
|
94
|
+
// 检查文件是否为空
|
|
95
|
+
if (file.isEmpty()) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
try {
|
|
100
|
+
File dir = new File(uploadDir);
|
|
101
|
+
if (!dir.exists()) {
|
|
102
|
+
Files.createDirectories(Paths.get(uploadDir));
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
Path filePath = Paths.get(uploadDir, file.getOriginalFilename());
|
|
106
|
+
|
|
107
|
+
file.transferTo(new File(filePath.toString()));
|
|
108
|
+
|
|
109
|
+
String filename=file.getOriginalFilename();
|
|
110
|
+
|
|
111
|
+
//get a unique id for the file
|
|
112
|
+
String uid = GridJsWorkbook.getUidForFile(filename);
|
|
113
|
+
|
|
114
|
+
ModelAndView mv = new ModelAndView();
|
|
115
|
+
mv.addObject("uid", uid);
|
|
116
|
+
mv.addObject("file", filename);
|
|
117
|
+
mv.setViewName("fileFromUpload");
|
|
118
|
+
return mv;
|
|
119
|
+
|
|
120
|
+
} catch (Exception e) {
|
|
121
|
+
e.printStackTrace();
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
|
|
127
|
+
}
|
|
128
|
+
|