gridjs-spreadsheet 26.2.0 → 26.3.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.
@@ -1,1441 +0,0 @@
1
- package com.aspose.gridjs.demo;
2
-
3
- import static org.junit.jupiter.api.Assertions.assertEquals;
4
- import static org.junit.jupiter.api.Assertions.assertNotNull;
5
- import static org.junit.jupiter.api.Assertions.assertNull;
6
- import static org.junit.jupiter.api.Assertions.assertTrue;
7
-
8
- import java.io.ByteArrayInputStream;
9
- import java.io.ByteArrayOutputStream;
10
- import java.io.File;
11
- import java.io.FileInputStream;
12
- import java.io.FileOutputStream;
13
- import java.io.IOException;
14
- import java.io.InputStream;
15
- import java.net.URL;
16
- import java.nio.charset.StandardCharsets;
17
- import java.nio.file.Files;
18
- import java.nio.file.Path;
19
- import java.nio.file.Paths;
20
- import java.util.Random;
21
-
22
- import javax.net.ssl.HttpsURLConnection;
23
-
24
- import org.json.JSONArray;
25
- import org.json.JSONObject;
26
- import org.junit.jupiter.api.BeforeAll;
27
- import org.junit.jupiter.api.Test;
28
-
29
- import com.aspose.cells.License;
30
- import com.aspose.cells.SaveFormat;
31
- import com.aspose.cells.Shape;
32
- import com.aspose.cells.Workbook;
33
- import com.aspose.cells.Worksheet;
34
- import com.aspose.gridjs.Config;
35
- import com.aspose.gridjs.GridJsWorkbook;
36
- import com.aspose.gridjs.GridLoadFormat;
37
- import com.aspose.gridjs.demo.test.Util;
38
-
39
- import org.springframework.boot.test.context.SpringBootTest;
40
-
41
- import com.aspose.gridjs.Config;
42
-
43
- @SpringBootTest
44
- public class GridjsdemoApplicationTests {
45
- private static String getTestfile(String file) {
46
- return "D:\\codebase\\local\\gridjstTestdll.Asp.netcore\\files\\"+file;
47
- }
48
- private static String getOutputfile(String file) {
49
- return "D:\\codebase\\local\\gridjstTestdll.Asp.netcore\\outfiles\\"+file;
50
- }
51
- @BeforeAll
52
- public static void init() throws Exception {
53
- Config.setFileCacheDirectory("D:/tmpdel/storage/");
54
- License lic = new License();
55
- lic.setLicense("D:\\release\\licesnse\\Aspose.Cells.lic");
56
-
57
- }
58
- @Test
59
- public void testConfigEmptySheetMaxRowCol() throws Exception {
60
-
61
- GridJsWorkbook gw = new GridJsWorkbook();
62
- Config.setEmptySheetMaxRow(48);
63
- Config.setEmptySheetMaxCol(35);
64
- Workbook wb = new Workbook();
65
- try (java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream()) {
66
- wb.save(baos,SaveFormat.XLSX);
67
- gw.importExcelFile(new java.io.ByteArrayInputStream(baos.toByteArray()), GridLoadFormat.XLSX);
68
- String json = gw.exportToJson();
69
- System.out.println(json);
70
- org.json.JSONObject cpresult = new org.json.JSONObject(json);
71
-
72
- String collen = ((org.json.JSONObject)cpresult.getJSONArray("data").get(0)).getJSONObject("cols").getString("len");
73
- String rowlen = ((org.json.JSONObject)cpresult.getJSONArray("data").get(0)).getJSONObject("rows").getString("len");
74
- assertEquals("36", collen);
75
- assertEquals("49", rowlen);
76
- }
77
- }
78
- @Test
79
- public void testAutoFillDate() throws Exception {
80
- GridJsWorkbook gw = new GridJsWorkbook();
81
- gw.importExcelFile(getTestfile("autofill.xlsx"));
82
- String json = gw.exportToJson();
83
- System.out.println(json);
84
- org.json.JSONObject cpresult = new org.json.JSONObject(json);
85
- String uid = cpresult.getString("uniqueid");
86
- String p = "{\"name\":\"Weekday Schedule\",\"cells\":[],\"src\":{\"sri\":1,\"sci\":2,\"eri\":1,\"eci\":2,\"w\":0,\"h\":0},\"dest\":{\"sri\":2,\"sci\":2,\"eri\":7,\"eci\":2,\"w\":0,\"h\":0},\"fromsheet\":\"Weekday Schedule\",\"what\":\"all\",\"op\":\"batchupdate\"}";
87
- String ret = gw.updateCell(p, uid);
88
- System.out.println(ret);
89
- String expect = "{\"op\":\"update\",\"data\":[{\"name\":\"Weekday Schedule\",\"cells\":[{\"ri\":2,\"ci\":2,\"text\":\"28-Feb\",\"ufv\":\"2021-2-28\",\"dt\":\"20210228 000000\"},{\"ri\":3,\"ci\":2,\"text\":\"1-Mar\",\"ufv\":\"2021-3-1\",\"dt\":\"20210301 000000\"},{\"ri\":4,\"ci\":2,\"text\":\"2-Mar\",\"ufv\":\"2021-3-2\",\"dt\":\"20210302 000000\"},{\"ri\":5,\"ci\":2,\"text\":\"3-Mar\",\"ufv\":\"2021-3-3\",\"dt\":\"20210303 000000\"},{\"ri\":6,\"ci\":2,\"text\":\"4-Mar\",\"ufv\":\"2021-3-4\",\"dt\":\"20210304 000000\"},{\"ri\":7,\"ci\":2,\"text\":\"5-Mar\",\"ufv\":\"2021-3-5\",\"dt\":\"20210305 000000\"}]}]}";
90
- assertEquals(expect, ret);
91
- }
92
-
93
- @Test
94
- public void testAutoFillFormula() throws Exception {
95
- GridJsWorkbook gw = new GridJsWorkbook();
96
- String path = getTestfile("autofill.xlsx");
97
- try (java.io.FileInputStream fs = new java.io.FileInputStream(path)) {
98
- gw.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(java.nio.file.Paths.get(path).getFileName().toString()), null);
99
- }
100
-
101
- String json = gw.exportToJson();
102
- System.out.println(json);
103
- org.json.JSONObject cpresult = new org.json.JSONObject(json);
104
- String uid = cpresult.getString("uniqueid");
105
- String p = "{\"name\":\"Weekday Schedule\",\"cells\":[{\"ri\":18,\"ci\":0,\"text\":\"3\"},{\"ri\":20,\"ci\":0,\"text\":\"3\"},{\"ri\":22,\"ci\":0,\"text\":\"3\"},{\"ri\":24,\"ci\":0,\"text\":\"3\"},{\"ri\":26,\"ci\":0,\"text\":\"3\"},{\"ri\":18,\"ci\":1,\"text\":\"5.6\"},{\"ri\":20,\"ci\":1,\"text\":\"5.6\"},{\"ri\":22,\"ci\":1,\"text\":\"5.6\"},{\"ri\":24,\"ci\":1,\"text\":\"5.6\"},{\"ri\":26,\"ci\":1,\"text\":\"5.6\"},{\"ri\":19,\"ci\":0,\"text\":\"4\"},{\"ri\":21,\"ci\":0,\"text\":\"4\"},{\"ri\":23,\"ci\":0,\"text\":\"4\"},{\"ri\":25,\"ci\":0,\"text\":\"4\"},{\"ri\":27,\"ci\":0,\"text\":\"4\"},{\"ri\":19,\"ci\":1,\"text\":\"6.6\"},{\"ri\":21,\"ci\":1,\"text\":\"6.6\"},{\"ri\":23,\"ci\":1,\"text\":\"6.6\"},{\"ri\":25,\"ci\":1,\"text\":\"6.6\"},{\"ri\":27,\"ci\":1,\"text\":\"6.6\"}],\"src\":{\"sri\":16,\"sci\":0,\"eri\":17,\"eci\":2,\"w\":0,\"h\":0},\"dest\":{\"sri\":18,\"sci\":0,\"eri\":27,\"eci\":2,\"w\":0,\"h\":0},\"what\":\"all\",\"op\":\"batchupdate\"}";
106
- String ret = gw.updateCell(p, uid);
107
- System.out.println(ret);
108
- String expect = "{\"op\":\"update\",\"data\":[{\"name\":\"Weekday Schedule\",\"cells\":[{\"ri\":18,\"ci\":0,\"text\":\"3\"},{\"ri\":18,\"ci\":1,\"text\":\"5.6\"},{\"ri\":18,\"ci\":2,\"text\":\"8.6\",\"f\":\"=SUM(A19:B19)\"},{\"ri\":19,\"ci\":0,\"text\":\"4\"},{\"ri\":19,\"ci\":1,\"text\":\"6.6\"},{\"ri\":19,\"ci\":2,\"text\":\"2.841470985\",\"f\":\"=2+SIN(1)\"},{\"ri\":20,\"ci\":0,\"text\":\"3\"},{\"ri\":20,\"ci\":1,\"text\":\"5.6\"},{\"ri\":20,\"ci\":2,\"text\":\"8.6\",\"f\":\"=SUM(A21:B21)\"},{\"ri\":21,\"ci\":0,\"text\":\"4\"},{\"ri\":21,\"ci\":1,\"text\":\"6.6\"},{\"ri\":21,\"ci\":2,\"text\":\"2.841470985\",\"f\":\"=2+SIN(1)\"},{\"ri\":22,\"ci\":0,\"text\":\"3\"},{\"ri\":22,\"ci\":1,\"text\":\"5.6\"},{\"ri\":22,\"ci\":2,\"text\":\"8.6\",\"f\":\"=SUM(A23:B23)\"},{\"ri\":23,\"ci\":0,\"text\":\"4\"},{\"ri\":23,\"ci\":1,\"text\":\"6.6\"},{\"ri\":23,\"ci\":2,\"text\":\"2.841470985\",\"f\":\"=2+SIN(1)\"},{\"ri\":24,\"ci\":0,\"text\":\"3\"},{\"ri\":24,\"ci\":1,\"text\":\"5.6\"},{\"ri\":24,\"ci\":2,\"text\":\"8.6\",\"f\":\"=SUM(A25:B25)\"},{\"ri\":25,\"ci\":0,\"text\":\"4\"},{\"ri\":25,\"ci\":1,\"text\":\"6.6\"},{\"ri\":25,\"ci\":2,\"text\":\"2.841470985\",\"f\":\"=2+SIN(1)\"},{\"ri\":26,\"ci\":0,\"text\":\"3\"},{\"ri\":26,\"ci\":1,\"text\":\"5.6\"},{\"ri\":26,\"ci\":2,\"text\":\"8.6\",\"f\":\"=SUM(A27:B27)\"},{\"ri\":27,\"ci\":0,\"text\":\"4\"},{\"ri\":27,\"ci\":1,\"text\":\"6.6\"},{\"ri\":27,\"ci\":2,\"text\":\"2.841470985\",\"f\":\"=2+SIN(1)\"}]}]}";
109
- assertEquals(expect, ret);
110
- }
111
-
112
- @Test
113
- public void testShapeRotation() throws Exception {
114
- GridJsWorkbook gw = new GridJsWorkbook();
115
-
116
- GridJsWorkbook.CacheImp = new LocalFileCache();
117
- String path = getTestfile("pictest.xls");
118
- // Assuming there's a method to export to JSON
119
- try (FileInputStream fs = new FileInputStream(path)) {
120
- gw.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(path), null);
121
- }
122
- String json = gw.exportToJson();
123
-
124
- // Parse JSON and manipulate the workbook
125
- JSONObject jsonObject = new JSONObject(json);
126
- String uniqueId = jsonObject.getString("uniqueid");
127
-
128
- String p = "{\"sheetname\":\"Sheet2\",\"actrow\":21,\"actcol\":9,\"datas\":[{\"name\":\"Sheet1\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":25},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet2\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"Black\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72},\"16\":{\"width\":72},\"17\":{\"width\":72},\"18\":{\"width\":72},\"19\":{\"width\":72},\"20\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":27},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[{\"left\":735.7283738306762,\"top\":124.21221762187565,\"originAngle\":14,\"angle\":62.255290286440825,\"zorder\":15,\"width\":189,\"height\":46,\"id\":\"6\"}]},{\"name\":\"Sheet3\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":20},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]}";
129
- gw.mergeExcelFileFromJson(uniqueId, p);
130
-
131
- // Save the modified workbook to a MemoryStream equivalent in Java
132
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
133
- gw.saveToExcelFile(outputStream);
134
-
135
- // Reset the position of the output stream to the beginning
136
- ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
137
- Workbook workbook = new Workbook(inputStream);
138
-
139
- // Access the shape and get its rotation angle
140
- Worksheet sheet = workbook.getWorksheets().get("Sheet2");
141
- Shape shape = (Shape) sheet.getShapes().get(6); // Assuming the shape is the first child
142
- double rotation = shape.getRotationAngle();
143
-
144
- // Assert the expected rotation value
145
- assertEquals(62.0, rotation, 0.001);
146
- }
147
-
148
- @Test
149
- public void testImageRotation() throws Exception {
150
- GridJsWorkbook gw = new GridJsWorkbook();
151
-
152
- GridJsWorkbook.CacheImp = new LocalFileCache();
153
- String path = getTestfile("pictest.xls");
154
- // Assuming there's a method to export to JSON
155
- try (FileInputStream fs = new FileInputStream(path)) {
156
- gw.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(path), null);
157
- }
158
- String json = gw.exportToJson();
159
-
160
- // Parse JSON and manipulate the workbook
161
- JSONObject jsonObject = new JSONObject(json);
162
- String uniqueId = jsonObject.getString("uniqueid");
163
-
164
- String p = "{\"sheetname\":\"Sheet2\",\"actrow\":21,\"actcol\":9,\"datas\":[{\"name\":\"Sheet1\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":25},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet2\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"Black\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":true}}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72},\"16\":{\"width\":72},\"17\":{\"width\":72},\"18\":{\"width\":72},\"19\":{\"width\":72},\"20\":{\"width\":72}},\"rows\":{\"21\":{\"height\":21,\"cells\":{\"9\":{\"text\":\"\",\"style\":2}}},\"height\":20,\"len\":27},\"validations\":[],\"autofilter\":{},\"images\":[{\"left\":486,\"top\":428.9999999999997,\"originAngle\":18.2446899414063,\"angle\":229.7013187480324,\"zorder\":15,\"width\":206,\"height\":71,\"id\":\"2\"}],\"shapes\":[]},{\"name\":\"Sheet3\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":20},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]}";
165
- gw.mergeExcelFileFromJson(uniqueId, p);
166
-
167
- // Save the modified workbook to a MemoryStream equivalent in Java
168
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
169
- gw.saveToExcelFile(outputStream);
170
-
171
- // Reset the position of the output stream to the beginning
172
- ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
173
- Workbook workbook = new Workbook(inputStream);
174
-
175
- // Access the shape and get its rotation angle
176
- Worksheet sheet = workbook.getWorksheets().get("Sheet2");
177
- Shape shape = (Shape) sheet.getPictures().get(2); // Assuming the shape is the first child
178
- double rotation = shape.getRotationAngle();
179
-
180
- // Assert the expected rotation value
181
- assertEquals(-130, rotation, 1);
182
- }
183
-
184
- @Test
185
- public void testShapeMove() throws Exception {
186
- GridJsWorkbook gw = new GridJsWorkbook();
187
-
188
- GridJsWorkbook.CacheImp = new LocalFileCache();
189
- String path = getTestfile("pictest.xls");
190
- // Assuming there's a method to export to JSON
191
- try (FileInputStream fs = new FileInputStream(path)) {
192
- gw.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(path), null);
193
- }
194
- String json = gw.exportToJson();
195
-
196
- // Parse JSON and manipulate the workbook
197
- JSONObject jsonObject = new JSONObject(json);
198
- String uniqueId = jsonObject.getString("uniqueid");
199
-
200
- String p = "{\"sheetname\":\"Sheet2\",\"actrow\":21,\"actcol\":9,\"datas\":[{\"name\":\"Sheet1\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":25},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet2\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"Black\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":true}}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72},\"16\":{\"width\":72},\"17\":{\"width\":72},\"18\":{\"width\":72},\"19\":{\"width\":72},\"20\":{\"width\":72}},\"rows\":{\"21\":{\"height\":21,\"cells\":{\"9\":{\"text\":\"\",\"style\":2}}},\"height\":20,\"len\":27},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[{\"left\":86.13666886109286,\"top\":38,\"originAngle\":180,\"angle\":180,\"zorder\":15,\"width\":189,\"height\":46,\"id\":\"7\"}]},{\"name\":\"Sheet3\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":20},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]}";
201
- gw.mergeExcelFileFromJson(uniqueId, p);
202
-
203
- // Save the modified workbook to a MemoryStream equivalent in Java
204
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
205
- gw.saveToExcelFile(outputStream);
206
-
207
- // Reset the position of the output stream to the beginning
208
- ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
209
- Workbook workbook = new Workbook(inputStream);
210
- int shapeid = 7;
211
- // Access the shape and get its rotation angle
212
- Worksheet sheet = workbook.getWorksheets().get("Sheet2");
213
- Shape shape = (Shape) sheet.getShapes().get(shapeid); // Assuming the shape is the first child
214
- int left = shape.getLeftToCorner();
215
- int top = shape.getTopToCorner();
216
-
217
- // Assert the expected rotation value
218
- assertEquals(86, left);
219
- assertEquals(38, top);
220
- }
221
-
222
- @Test
223
- public void testShapeResize() throws Exception {
224
- GridJsWorkbook gw = new GridJsWorkbook();
225
-
226
- GridJsWorkbook.CacheImp = new LocalFileCache();
227
- String path = getTestfile("pictest.xls");
228
- // Assuming there's a method to export to JSON
229
- try (FileInputStream fs = new FileInputStream(path)) {
230
- gw.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(path), null);
231
- }
232
- String json = gw.exportToJson();
233
-
234
- // Parse JSON and manipulate the workbook
235
- JSONObject jsonObject = new JSONObject(json);
236
- String uniqueId = jsonObject.getString("uniqueid");
237
-
238
- String p = "{\"sheetname\":\"Sheet2\",\"actrow\":21,\"actcol\":9,\"datas\":[{\"name\":\"Sheet1\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":25},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet2\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"Black\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":true}}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72},\"16\":{\"width\":72},\"17\":{\"width\":72},\"18\":{\"width\":72},\"19\":{\"width\":72},\"20\":{\"width\":72}},\"rows\":{\"21\":{\"height\":21,\"cells\":{\"9\":{\"text\":\"\",\"style\":2}}},\"height\":20,\"len\":27},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[{\"left\":84.61946061188769,\"top\":223.9999999999995,\"originAngle\":180,\"angle\":155.2060739658465,\"zorder\":18,\"width\":238.96908007635514,\"height\":58.161786685250455,\"id\":\"7\"}]},{\"name\":\"Sheet3\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":20},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]}";
239
- gw.mergeExcelFileFromJson(uniqueId, p);
240
-
241
- // Save the modified workbook to a MemoryStream equivalent in Java
242
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
243
- gw.saveToExcelFile(outputStream);
244
-
245
- // Reset the position of the output stream to the beginning
246
- ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
247
- Workbook workbook = new Workbook(inputStream);
248
- int shapeid = 7;
249
- // Access the shape and get its rotation angle
250
- Worksheet sheet = workbook.getWorksheets().get("Sheet2");
251
- Shape shape = (Shape) sheet.getShapes().get(shapeid); // Assuming the shape is the first child
252
- int w = shape.getWidth();
253
- int h = shape.getHeight();
254
-
255
- // Assert the expected rotation value
256
-
257
- assertEquals(58, h);
258
- //238 or 239 it not very accurate
259
- assertEquals(238, w);
260
- }
261
-
262
- @Test
263
- public void testImageMove() throws Exception {
264
- GridJsWorkbook gw = new GridJsWorkbook();
265
-
266
- GridJsWorkbook.CacheImp = new LocalFileCache();
267
- String path = getTestfile("pictest.xls");
268
- // Assuming there's a method to export to JSON
269
- try (FileInputStream fs = new FileInputStream(path)) {
270
- gw.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(path), null);
271
- }
272
- String json = gw.exportToJson();
273
-
274
- // Parse JSON and manipulate the workbook
275
- JSONObject jsonObject = new JSONObject(json);
276
- String uniqueId = jsonObject.getString("uniqueid");
277
-
278
- String p = "{\"sheetname\":\"Sheet2\",\"actrow\":21,\"actcol\":9,\"datas\":[{\"name\":\"Sheet1\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":25},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet2\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"Black\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":true}}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72},\"16\":{\"width\":72},\"17\":{\"width\":72},\"18\":{\"width\":72},\"19\":{\"width\":72},\"20\":{\"width\":72}},\"rows\":{\"21\":{\"height\":21,\"cells\":{\"9\":{\"text\":\"\",\"style\":2}}},\"height\":20,\"len\":27},\"validations\":[],\"autofilter\":{},\"images\":[{\"left\":296.9292955892031,\"top\":75.13595091372946,\"originAngle\":326.733581542969,\"angle\":8.434664397787628,\"zorder\":24,\"width\":334,\"height\":201,\"id\":\"0\"}],\"shapes\":[{\"left\":84.61946061188769,\"top\":223.9999999999995,\"originAngle\":180,\"angle\":155.2060739658465,\"zorder\":18,\"width\":238.96908007635514,\"height\":58.161786685250455,\"id\":\"7\"},{\"left\":803.0758393680053,\"top\":58,\"originAngle\":0,\"angle\":0,\"zorder\":22,\"width\":375,\"height\":128,\"id\":\"13\"}]},{\"name\":\"Sheet3\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":20},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]}";
279
- gw.mergeExcelFileFromJson(uniqueId, p);
280
-
281
- // Save the modified workbook to a MemoryStream equivalent in Java
282
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
283
- gw.saveToExcelFile(outputStream);
284
-
285
- // Reset the position of the output stream to the beginning
286
- ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
287
- Workbook workbook = new Workbook(inputStream);
288
- int shapeid = 0;
289
- // Access the shape and get its rotation angle
290
- Worksheet sheet = workbook.getWorksheets().get("Sheet2");
291
- Shape shape = (Shape) sheet.getPictures().get(shapeid); // Assuming the shape is the first child
292
- int left = shape.getLeftToCorner();
293
- int top = shape.getTopToCorner();
294
-
295
- // Assert the expected rotation value
296
- //297->296
297
- assertEquals(296, left);
298
- assertEquals(75, top);
299
- }
300
- @Test
301
- public void testImageResize() throws Exception {
302
- GridJsWorkbook gw = new GridJsWorkbook();
303
-
304
- GridJsWorkbook.CacheImp = new LocalFileCache();
305
- String path = getTestfile("pictest.xls");
306
- // Assuming there's a method to export to JSON
307
- try (FileInputStream fs = new FileInputStream(path)) {
308
- gw.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(path), null);
309
- }
310
- String json = gw.exportToJson();
311
-
312
- // Parse JSON and manipulate the workbook
313
- JSONObject jsonObject = new JSONObject(json);
314
- String uniqueId = jsonObject.getString("uniqueid");
315
-
316
- String p = "{\"sheetname\":\"Sheet2\",\"actrow\":21,\"actcol\":9,\"datas\":[{\"name\":\"Sheet1\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":25},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet2\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"Black\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":true}}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72},\"16\":{\"width\":72},\"17\":{\"width\":72},\"18\":{\"width\":72},\"19\":{\"width\":72},\"20\":{\"width\":72}},\"rows\":{\"21\":{\"height\":21,\"cells\":{\"9\":{\"text\":\"\",\"style\":1}}},\"height\":20,\"len\":27},\"validations\":[],\"autofilter\":{},\"images\":[{\"left\":198.22518261373216,\"top\":282.4330962241735,\"originAngle\":326.733581542969,\"angle\":351.3970493213394,\"zorder\":27,\"width\":211.5761326868053,\"height\":127.32575649714929,\"id\":\"0\"}],\"shapes\":[{\"left\":84.61946061188769,\"top\":223.9999999999995,\"originAngle\":180,\"angle\":155.2060739658465,\"zorder\":18,\"width\":238.96908007635514,\"height\":58.161786685250455,\"id\":\"7\"},{\"left\":391.23857801185045,\"top\":209.49026704645462,\"originAngle\":0,\"angle\":0,\"zorder\":30,\"width\":292.1794562603063,\"height\":99.73058773685122,\"id\":\"13\"}]},{\"name\":\"Sheet3\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":20},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]}";
317
- gw.mergeExcelFileFromJson(uniqueId, p);
318
-
319
- // Save the modified workbook to a MemoryStream equivalent in Java
320
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
321
- gw.saveToExcelFile(outputStream);
322
-
323
- // Reset the position of the output stream to the beginning
324
- ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
325
- Workbook workbook = new Workbook(inputStream);
326
- int shapeid = 0;
327
- // Access the shape and get its rotation angle
328
- Worksheet sheet = workbook.getWorksheets().get("Sheet2");
329
- Shape shape = (Shape) sheet.getPictures().get(shapeid); // Assuming the shape is the first child
330
- int w = shape.getWidth();
331
- int h = shape.getHeight();
332
-
333
- // Assert the expected rotation value
334
-
335
- assertEquals(127, h);
336
- //212 ->211 not very accurate
337
- assertEquals(211, w);
338
- }
339
- //now the temp cache file is xlsx format ,so the below test will not raise insert fail again
340
- @Test
341
- public void testInsertRowFail() throws Exception {
342
- GridJsWorkbook gw = new GridJsWorkbook();
343
-
344
- GridJsWorkbook.CacheImp = new LocalFileCache();
345
- String path = getTestfile("addrowfail.xls");
346
- // Assuming there's a method to export to JSON
347
- try (FileInputStream fs = new FileInputStream(path)) {
348
- gw.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(path), null);
349
- }
350
- String json = gw.exportToJson();
351
-
352
- // Parse JSON and manipulate the workbook
353
- JSONObject jsonObject = new JSONObject(json);
354
- String uniqueId = jsonObject.getString("uniqueid");
355
-
356
- String p = "{\"name\":\"Worksheet\",\"ri\":1,\"n\":1,\"h\":12,\"op\":\"insertrow\"}";
357
- String ret=gw.updateCell( p,uniqueId);
358
-
359
- String expect = "{\"op\":\"update\",\"data\":[]}";
360
-
361
- assertEquals(expect, ret);
362
- }
363
- @Test
364
- public void testConfigSkipShapes() throws Exception {
365
- Config.setSkipInvisibleShapes(false);
366
- checkShapeCount(6);
367
- //default
368
- Config.setSkipInvisibleShapes(true);
369
- checkShapeCount(3);
370
- }
371
-
372
- private static void checkShapeCount(int expectedCount) throws Exception {
373
- GridJsWorkbook gw = new GridJsWorkbook();
374
- GridJsWorkbook.CacheImp = new LocalFileCache();
375
- String path = getTestfile("testfileview gridjs.xlsx"); // Assuming util.getTestfile is a static method in this context
376
- gw.importExcelFile(path);
377
-
378
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
379
- gw.jsonToStream(baos, "hello2.xlsx");
380
-
381
- baos.close();
382
-
383
- String json = new String(baos.toByteArray(), StandardCharsets.UTF_8);
384
- JSONObject cpresult = new JSONObject(json);
385
- JSONArray shapesArray = ((JSONArray) ((JSONArray) cpresult.getJSONArray("data")).getJSONObject(0).getJSONArray("shapes"));
386
- int len = shapesArray.length();
387
- assertEquals(expectedCount, len);
388
- }
389
-
390
- @Test
391
- public void testInsertImageWithNoStreamCacheImp() throws Exception {
392
- GridJsWorkbook gw = new GridJsWorkbook();
393
- gw.CacheImp=(null); // Ensure the cache implementation is null for this test
394
-
395
- String path = getTestfile("pictest.xls");
396
- gw.importExcelFile(path);
397
-
398
- String json = gw.exportToJson();
399
- System.out.println(json);
400
- JSONObject cpresult = new JSONObject(json);
401
- String uid = cpresult.getString("uniqueid");
402
- String p = "{\"name\":\"Sheet2\",\"ri\":1,\"ci\":1}";
403
- String picRet = null;
404
-
405
- File imageFile = new File(getTestfile("snap1.png"));
406
- try (FileInputStream s = new FileInputStream(imageFile)) {
407
- picRet = gw.insertImage(uid, p, s, null);
408
- }
409
- System.out.println("insert first image : " + picRet);
410
- JSONObject picRetJson = new JSONObject(picRet);
411
-
412
- int picId = picRetJson.getInt("id");
413
- assertEquals(3, picId);
414
-
415
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
416
- gw.saveToExcelFile(baos);
417
-
418
- baos.close();
419
-
420
- byte[] byteArray = baos.toByteArray();
421
- try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray)) {
422
- Workbook wb = new Workbook(bais);
423
-
424
- Worksheet sheet = wb.getWorksheets().get("Sheet2"); // Assuming "Sheet2" is the second sheet
425
- Shape sp = (Shape) sheet.getPictures().get(picId); // Shapes are typically stored in a list of sheet objects, and the ID might need to be adjusted
426
-
427
- int w = sp.getWidth();
428
- int h = sp.getHeight();
429
-
430
- String expectW = "320";
431
- String expectH = "204";
432
- assertEquals(expectW, Integer.toString(w));
433
- assertEquals(expectH, Integer.toString(h));
434
- assertEquals(expectW, picRetJson.getString("width"));
435
- assertEquals(expectH, picRetJson.getString("height"));
436
- System.out.println("pic count:"+sheet.getPictures().getCount());
437
-
438
- // Add second image with a new GridJsWorkbook instance
439
-
440
- p = "{\"name\":\"Sheet2\",\"ri\":3,\"ci\":3}";
441
- try (FileInputStream s = new FileInputStream(imageFile)) {
442
- picRet = gw.insertImage(uid, p, s, null);
443
- System.out.println("insert second image : " + picRet);
444
- }
445
- picRetJson = new JSONObject(picRet);
446
-
447
- baos = new ByteArrayOutputStream();
448
- gw.saveToExcelFile(baos);
449
-
450
- baos.close();
451
-
452
- byteArray = baos.toByteArray();
453
- try (ByteArrayInputStream bais2 = new ByteArrayInputStream(byteArray)) {
454
- Workbook wb2 = new Workbook(bais2);
455
- picId = picRetJson.getInt("id");
456
- String urlString = picRetJson.getString("url");
457
- assertTrue(urlString.indexOf("uid=") > 0 && urlString.indexOf("&id=") > 0);
458
- assertEquals(4, picId);
459
-
460
- sheet = wb2.getWorksheets().get("Sheet2");
461
-
462
- sp = (Shape) sheet.getPictures().get(picId);
463
- w = sp.getWidth();
464
- h = sp.getHeight();
465
- assertEquals(expectW, Integer.toString(w));
466
- assertEquals(expectH, Integer.toString(h));
467
-
468
- sp = (Shape) sheet.getPictures().get(3);
469
- w = sp.getWidth();
470
- h = sp.getHeight();
471
- assertEquals(expectW, Integer.toString(w));
472
- assertEquals(expectH, Integer.toString(h));
473
- }
474
- }
475
- }
476
-
477
- @Test
478
- public void TestInsertImageWithStreamCacheImp()
479
- {
480
- String[] uid = new String[1];
481
- try {
482
- insertImage(null, uid);
483
- } catch (Exception e) {
484
- // TODO Auto-generated catch block
485
- e.printStackTrace();
486
- }
487
-
488
- }
489
-
490
- @Test
491
- public void testOptimizeForSameImage() throws Exception {
492
- // Do not limit shape or image count
493
- Config.setIslimitShapeOrImage(false);
494
- Config.setSameImageDetecting(true);
495
-
496
-
497
- GridJsWorkbook gw = new GridJsWorkbook();
498
- GridJsWorkbook.CacheImp = new LocalFileCache();
499
- Random rd = new Random();
500
- Workbook wb = new Workbook();
501
-
502
- // Add only one picture to many cells
503
- addPictureToWb(rd, wb, getTestfile("snap1.png"));
504
-
505
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
506
- wb.save(baos,SaveFormat.XLSX);
507
-
508
- baos.close();
509
-
510
- byte[] byteArray = baos.toByteArray();
511
- try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray)) {
512
- gw.importExcelFile(bais, GridLoadFormat.XLSX, null);
513
- }
514
-
515
- String json = gw.exportToJson();
516
-
517
- JSONObject cpresult = new JSONObject(json);
518
- String uid = cpresult.getString("uniqueid");
519
- // Only one picture in zip
520
- testImageZipFiles(uid, 2);
521
-
522
- // Add more pictures
523
- addPictureToWb(rd, wb, getTestfile("pic2.png"));
524
- addPictureToWb(rd, wb, getTestfile("pic3.png"));
525
-
526
- baos = new ByteArrayOutputStream();
527
- wb.save(baos,SaveFormat.XLSX);
528
-
529
- baos.close();
530
-
531
- byteArray = baos.toByteArray();
532
- try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray)) {
533
- gw.importExcelFile(bais, GridLoadFormat.XLSX, null);
534
- }
535
-
536
- long startTime = System.currentTimeMillis();
537
- json = gw.exportToJson();
538
- long endTime = System.currentTimeMillis();
539
-
540
- long costTime1 = endTime - startTime;
541
- cpresult = new JSONObject(json);
542
- uid = cpresult.getString("uniqueid");
543
-
544
- // Only 3 images actually
545
- testImageZipFiles(uid, 4);
546
-
547
- // No same image detection
548
- Config.setSameImageDetecting(false);
549
-
550
- baos = new ByteArrayOutputStream();
551
- wb.save(baos,SaveFormat.XLSX);
552
-
553
- baos.close();
554
-
555
- byteArray = baos.toByteArray();
556
- try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray)) {
557
- gw.importExcelFile(bais, GridLoadFormat.XLSX, null);
558
- }
559
-
560
- startTime = System.currentTimeMillis();
561
- json = gw.exportToJson();
562
- endTime = System.currentTimeMillis();
563
-
564
- long costTime2 = endTime - startTime;
565
- cpresult = new JSONObject(json);
566
- uid = cpresult.getString("uniqueid");
567
-
568
- // Total image is much more
569
- testImageZipFiles(uid, 693);
570
-
571
- // Less I/O, less time
572
- assertEquals(true, costTime2 > costTime1);
573
-
574
- // Restore Config to default value after test
575
- Config.setIslimitShapeOrImage(true);
576
- Config.setSameImageDetecting(true);
577
- }
578
-
579
- @Test
580
- public void testInsertImageAndThenCopyImage() throws Exception {
581
- String[] uidarray = new String[1];
582
- // Insert image and the picid is 3
583
- insertImage(null, uidarray);
584
- String uid=uidarray[0];
585
- // srcid set to 3
586
- String p = "{\"name\":\"Sheet2\",\"srcname\":\"Sheet2\",\"ri\":11,\"ci\":3,\"srcid\":149,\"isshape\":false}";
587
- String expectW = "320";
588
- String expectH = "204";
589
- String expectErrMsg = "{\"Error\":\"wrong picture id \"}";
590
-
591
- GridJsWorkbook gw = new GridJsWorkbook();
592
- GridJsWorkbook.CacheImp = new LocalFileCache();
593
- String picRet = gw.copyImageOrShape(uid, p);
594
-
595
- System.out.println("Copy image : " + picRet);
596
- JSONObject picRetJson = new JSONObject(picRet);
597
-
598
- // Copy image return id shall equal with count
599
- int picId = picRetJson.getInt("id");
600
- assertEquals(5, picId);
601
-
602
- String picUrl = picRetJson.getString("url");
603
-
604
- int idIdx = picUrl.indexOf("id=");
605
- String downloadId = picUrl.substring(idIdx + 3);
606
- System.out.println(downloadId);
607
-
608
- // Image not existed
609
- // InputStream fsReader = gw.getCacheImp().loadStream(downloadId);
610
- // assertEquals(true, fsReader.available() > 0);
611
-
612
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
613
- gw.saveToExcelFile(baos);
614
- baos.close();
615
-
616
- byte[] byteArray = baos.toByteArray();
617
- try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray)) {
618
- Workbook wb = new Workbook(bais);
619
-
620
- Shape sp = wb.getWorksheets().get("Sheet2").getPictures().get(picId);
621
-
622
- int w = sp.getWidth();
623
- int h = sp.getHeight();
624
-
625
- assertEquals(expectW, Integer.toString(w));
626
- assertEquals(expectH, Integer.toString(h));
627
- assertEquals(expectW, picRetJson.getString("width"));
628
- assertEquals(expectH, picRetJson.getString("height"));
629
- assertEquals(11, sp.getUpperLeftRow());
630
- assertEquals(3, sp.getUpperLeftColumn());
631
- }
632
- }
633
- @Test
634
- public void testInsertImageWithStreamCacheImpWithURL()
635
- { String[] uid = new String[1];
636
- try {
637
- insertImage("https://www.baidu.com/img/flexible/logo/pc/result.png", uid);
638
- } catch (Exception e) {
639
- // TODO Auto-generated catch block
640
- e.printStackTrace();
641
- }
642
-
643
- }
644
- @Test
645
- public void testDeleteImageWithStreamCacheImp() throws Exception {
646
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
647
- gridJsWorkbook.CacheImp=(new LocalFileCache());
648
-
649
- // Load the workbook using Aspose.Cells
650
- String testFilePath = getTestfile("pictest.xls");
651
- Workbook workbook = new Workbook(new FileInputStream(testFilePath));
652
- Worksheet sheet = workbook.getWorksheets().get("Sheet2");
653
- int originCount = sheet.getPictures().getCount();
654
-
655
- // Import the Excel file using the custom GridJsWorkbook
656
- try (FileInputStream fs = new FileInputStream(testFilePath)) {
657
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".xls"), "123");
658
- }
659
-
660
- // Export to JSON and manipulate the JSON string
661
- String json = gridJsWorkbook.exportToJson();
662
- System.out.println(json);
663
- JSONObject jsonObject = new JSONObject(json);
664
- String uid = jsonObject.getString("uniqueid");
665
-
666
- // Prepare the JSON string 'p' as per original C# code
667
- String p = "{\"sheetname\":\"Sheet2\",\"actrow\":21,\"actcol\":9,\"datas\":[{\"name\":\"Sheet1\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":25},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet2\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"Black\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":true}}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72},\"16\":{\"width\":72},\"17\":{\"width\":72},\"18\":{\"width\":72},\"19\":{\"width\":72},\"20\":{\"width\":72}},\"rows\":{\"21\":{\"height\":21,\"cells\":{\"9\":{\"text\":\"\",\"style\":2}}},\"height\":20,\"len\":27},\"validations\":[],\"autofilter\":{},\"images\":[{\"left\":118,\"top\":270.0000000000001,\"originAngle\":326.733581542969,\"angle\":353.07958890754185,\"zorder\":23,\"width\":334,\"height\":201,\"id\":\"0\"},{\"op\":\"del\",\"id\":\"1\"},{\"left\":486,\"top\":429,\"originAngle\":18.2446899414063,\"angle\":18.2446899414063,\"zorder\":21,\"width\":206,\"height\":71,\"id\":\"2\"}],\"shapes\":[{\"left\":735.7283738306762,\"top\":124.21221762187571,\"originAngle\":14,\"angle\":316.43181320984263,\"zorder\":18,\"width\":189,\"height\":46,\"id\":\"6\"},{\"left\":676.1465596207154,\"top\":230.79871381498958,\"originAngle\":348,\"angle\":26.971249728296755,\"zorder\":16,\"width\":189,\"height\":46,\"id\":\"9\"}]},{\"name\":\"Sheet3\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":20},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]} "; // You need to construct this JSON string as per your needs
668
-
669
- // Merge changes from JSON
670
- gridJsWorkbook.mergeExcelFileFromJson(uid, p);
671
-
672
- // Save the workbook to a ByteArrayOutputStream
673
- ByteArrayOutputStream ms = new ByteArrayOutputStream();
674
- gridJsWorkbook.saveToExcelFile(ms);
675
- ms.flush();
676
- ByteArrayInputStream inputStream = new ByteArrayInputStream(ms.toByteArray());
677
- workbook = new Workbook(inputStream);
678
-
679
- // Check the count of pictures after merging JSON changes
680
- sheet = workbook.getWorksheets().get("Sheet2");
681
- int count = sheet.getPictures().getCount();
682
- assertEquals(originCount - 1, count);
683
-
684
- // Mock second post delete 2 pictures
685
- // Repeat the process with a new JSON string that includes the delete operations
686
- // for pictures with IDs "1" and "2".
687
- p = "{\"sheetname\":\"Sheet2\",\"actrow\":21,\"actcol\":9,\"datas\":[{\"name\":\"Sheet1\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":25},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet2\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"Black\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":true}}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72},\"16\":{\"width\":72},\"17\":{\"width\":72},\"18\":{\"width\":72},\"19\":{\"width\":72},\"20\":{\"width\":72}},\"rows\":{\"21\":{\"height\":21,\"cells\":{\"9\":{\"text\":\"\",\"style\":2}}},\"height\":20,\"len\":27},\"validations\":[],\"autofilter\":{},\"images\":[{\"left\":118,\"top\":270.0000000000001,\"originAngle\":326.733581542969,\"angle\":353.07958890754185,\"zorder\":23,\"width\":334,\"height\":201,\"id\":\"0\"},{\"op\":\"del\",\"id\":\"1\"},{ \"op\":\"del\",\"id\":\"2\"}],\"shapes\":[{\"left\":735.7283738306762,\"top\":124.21221762187571,\"originAngle\":14,\"angle\":316.43181320984263,\"zorder\":18,\"width\":189,\"height\":46,\"id\":\"6\"},{\"left\":676.1465596207154,\"top\":230.79871381498958,\"originAngle\":348,\"angle\":26.971249728296755,\"zorder\":16,\"width\":189,\"height\":46,\"id\":\"9\"}]},{\"name\":\"Sheet3\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":20},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]}"; // Construct the new JSON string for the second test
688
-
689
- gridJsWorkbook = new GridJsWorkbook();
690
-
691
-
692
- gridJsWorkbook.mergeExcelFileFromJson(uid, p);
693
- ms = new ByteArrayOutputStream();
694
- gridJsWorkbook.saveToExcelFile(ms);
695
- inputStream = new ByteArrayInputStream(ms.toByteArray());
696
- workbook = new Workbook(inputStream);
697
- sheet = workbook.getWorksheets().get("Sheet2");
698
- count = sheet.getPictures().getCount();
699
- assertEquals(originCount - 2, count);
700
- }
701
-
702
- @Test
703
- public void testDeleteShapeWithStreamCacheImp() throws Exception {
704
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
705
- gridJsWorkbook.CacheImp=(new LocalFileCache());
706
-
707
- // Load the workbook using Aspose.Cells
708
- String testFilePath = getTestfile("pictest.xls");
709
- Workbook workbook = new Workbook(new FileInputStream(testFilePath));
710
- Worksheet sheet = workbook.getWorksheets().get("Sheet2");
711
- int originCount = sheet.getShapes().getCount();
712
-
713
- // Import the Excel file using the custom GridJsWorkbook
714
- try (FileInputStream fs = new FileInputStream(testFilePath)) {
715
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".xls"), "123");
716
- }
717
-
718
- // Export to JSON and manipulate the JSON string
719
- String json = gridJsWorkbook.exportToJson();
720
- System.out.println(json);
721
- JSONObject jsonObject = new JSONObject(json);
722
- String uid = jsonObject.getString("uniqueid");
723
-
724
- // Prepare the JSON string 'p' as per original C# code
725
- String p = " {\"sheetname\":\"Sheet2\",\"actrow\":21,\"actcol\":9,\"datas\":[{\"name\":\"Sheet1\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":25},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet2\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"Black\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":true}}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72},\"16\":{\"width\":72},\"17\":{\"width\":72},\"18\":{\"width\":72},\"19\":{\"width\":72},\"20\":{\"width\":72}},\"rows\":{\"21\":{\"height\":21,\"cells\":{\"9\":{\"text\":\"\",\"style\":1}}},\"height\":20,\"len\":27},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[{\"left\":221.15803068140252,\"top\":92.19221273648674,\"originAngle\":80,\"angle\":80,\"zorder\":18,\"width\":134,\"height\":48,\"id\":\"0\"},{\"left\":265.9518104015799,\"top\":229.88239564428312,\"originAngle\":0,\"angle\":0,\"zorder\":16,\"width\":138,\"height\":46,\"id\":\"1\"},{\"left\":281.5786750570451,\"top\":102.38889291739602,\"originAngle\":120,\"angle\":120,\"zorder\":17,\"width\":134,\"height\":48,\"id\":\"3\"}, {\"left\":370.86484887511415,\"top\":212.08212536113388,\"originAngle\":170,\"angle\":170,\"zorder\":20,\"width\":189,\"height\":46,\"id\":\"5\"},{\"op\":\"del\" ,\"id\":\"6\"},{\"left\":495.97472021066494,\"top\":217.8867513611616,\"originAngle\":180,\"angle\":180,\"zorder\":21,\"width\":189,\"height\":46,\"id\":\"7\"},{\"left\":567.1896142619267,\"top\":311.71361159049684,\"originAngle\":348,\"angle\":348,\"zorder\":22,\"width\":189,\"height\":46,\"id\":\"9\"},{\"left\":724.3627247905652,\"top\":338.6218715229195,\"originAngle\":299.491744995117,\"angle\":338.41234009876024,\"zorder\":24,\"width\":182,\"height\":48,\"id\":\"10\"}]},{\"name\":\"Sheet3\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":20},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]}";
726
-
727
- // Merge changes from JSON
728
- gridJsWorkbook.mergeExcelFileFromJson(uid, p);
729
-
730
- // Save the workbook to a ByteArrayOutputStream
731
- ByteArrayOutputStream ms = new ByteArrayOutputStream();
732
- gridJsWorkbook.saveToExcelFile(ms);
733
- ms.flush();
734
- ByteArrayInputStream inputStream = new ByteArrayInputStream(ms.toByteArray());
735
- workbook = new Workbook(inputStream);
736
-
737
- // Check the count of pictures after merging JSON changes
738
- sheet = workbook.getWorksheets().get("Sheet2");
739
- int count = sheet.getShapes().getCount();
740
- assertEquals(originCount - 1, count);
741
-
742
- // Mock second post delete 2 pictures
743
- // Repeat the process with a new JSON string that includes the delete operations
744
- // for pictures with IDs "1" and "2".
745
- p = "{\"sheetname\":\"Sheet2\",\"actrow\":21,\"actcol\":9,\"datas\":[{\"name\":\"Sheet1\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":25},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet2\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"Black\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"Black\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":true}}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72},\"16\":{\"width\":72},\"17\":{\"width\":72},\"18\":{\"width\":72},\"19\":{\"width\":72},\"20\":{\"width\":72}},\"rows\":{\"21\":{\"height\":21,\"cells\":{\"9\":{\"text\":\"\",\"style\":1}}},\"height\":20,\"len\":27},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[{\"left\":221.15803068140252,\"top\":92.19221273648674,\"originAngle\":80,\"angle\":80,\"zorder\":18,\"width\":134,\"height\":48,\"id\":\"0\"},{\"left\":265.9518104015799,\"top\":229.88239564428312,\"originAngle\":0,\"angle\":0,\"zorder\":16,\"width\":138,\"height\":46,\"id\":\"1\"},{\"left\":281.5786750570451,\"top\":102.38889291739602,\"originAngle\":120,\"angle\":120,\"zorder\":17,\"width\":134,\"height\":48,\"id\":\"3\"},{\"op\":\"del\" ,\"id\":\"4\"},{\"left\":370.86484887511415,\"top\":212.08212536113388,\"originAngle\":170,\"angle\":170,\"zorder\":20,\"width\":189,\"height\":46,\"id\":\"5\"},{\"op\":\"del\" ,\"id\":\"6\"},{\"left\":495.97472021066494,\"top\":217.8867513611616,\"originAngle\":180,\"angle\":180,\"zorder\":21,\"width\":189,\"height\":46,\"id\":\"7\"},{\"left\":567.1896142619267,\"top\":311.71361159049684,\"originAngle\":348,\"angle\":348,\"zorder\":22,\"width\":189,\"height\":46,\"id\":\"9\"},{\"left\":724.3627247905652,\"top\":338.6218715229195,\"originAngle\":299.491744995117,\"angle\":338.41234009876024,\"zorder\":24,\"width\":182,\"height\":48,\"id\":\"10\"}]},{\"name\":\"Sheet3\",\"freeze\":\"A1\",\"styles\":[],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{\"0\":{\"width\":72},\"1\":{\"width\":72},\"2\":{\"width\":72},\"3\":{\"width\":72},\"4\":{\"width\":72},\"5\":{\"width\":72},\"6\":{\"width\":72},\"7\":{\"width\":72},\"8\":{\"width\":72},\"9\":{\"width\":72},\"10\":{\"width\":72},\"11\":{\"width\":72},\"12\":{\"width\":72},\"13\":{\"width\":72},\"14\":{\"width\":72},\"15\":{\"width\":72}},\"rows\":{\"height\":20,\"len\":20},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]}";
746
-
747
- gridJsWorkbook = new GridJsWorkbook();
748
-
749
-
750
- gridJsWorkbook.mergeExcelFileFromJson(uid, p);
751
- ms = new ByteArrayOutputStream();
752
- gridJsWorkbook.saveToExcelFile(ms);
753
- inputStream = new ByteArrayInputStream(ms.toByteArray());
754
- workbook = new Workbook(inputStream);
755
- sheet = workbook.getWorksheets().get("Sheet2");
756
- count = sheet.getShapes().getCount();
757
- assertEquals(originCount - 2, count);
758
- }
759
-
760
- @Test
761
- public void testCELLSAPP1039() throws Exception {
762
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
763
- gridJsWorkbook.CacheImp=(new LocalFileCache());
764
-
765
- // Import the Excel file using the custom GridJsWorkbook
766
- String path = getTestfile("CELLSAPP-1039.xlsx");
767
- try (FileInputStream fs = new FileInputStream(path)) {
768
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".xlsx"), null);
769
- }
770
-
771
- // Set configuration limits
772
- Config.setMaxShapeOrImageCount(5);
773
- Config.setMaxTotalShapeOrImageCount(100);
774
- long startTime = System.currentTimeMillis();
775
- System.out.println("TestCELLSAPP1039 " + Config.getIslimitShapeOrImage());
776
-
777
- // Export to JSON
778
- String json = gridJsWorkbook.exportToJson();
779
- JSONObject jsonObject = new JSONObject(json);
780
- JSONObject dataArray = jsonObject.getJSONArray("data").getJSONObject(25);
781
- JSONArray imagesArray = dataArray.getJSONArray("images");
782
- int len = imagesArray.length();
783
-
784
- long endTime = System.currentTimeMillis();
785
- long elapsedMs = endTime - startTime;
786
-
787
- assertEquals(5, len);
788
- assertTrue(elapsedMs<10000, "The export cost time shall not greater than 10s");
789
- }
790
- @Test
791
- public void testCELLSGRIDJS404() throws Exception {
792
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
793
- gridJsWorkbook.CacheImp=(new LocalFileCache());
794
-
795
- // 使用给定的文件名获取测试文件路径
796
- String path = getTestfile("autofill.xlsx");
797
- try (InputStream fs = new FileInputStream(path)) {
798
- // 导入Excel文件
799
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".xlsx"), null);
800
- }
801
-
802
- // 导出为JSON并解析结果
803
- String json = gridJsWorkbook.exportToJson();
804
- JSONObject cpresult = new JSONObject(json);
805
- String filename = cpresult.getString("filename");
806
-
807
- // 断言文件名是否符合预期
808
- assertEquals("book1", filename);
809
-
810
- // 测试包含非ASCII字符的文件名
811
- String nonAsciiFilename = "Информация об объектах, находящихся в муниципальной собственности (ГАСУ) на 01.01.2021.xlsx";
812
- json = gridJsWorkbook.exportToJson(nonAsciiFilename);
813
-
814
- cpresult = new JSONObject(json);
815
- filename = cpresult.getString("filename");
816
-
817
- // 断言非ASCII文件名是否正确设置
818
- assertEquals(nonAsciiFilename, filename);
819
- }
820
- @Test
821
- public void testCELLSGRIDJS680() throws Exception {
822
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
823
- gridJsWorkbook.CacheImp = new LocalFileCache();
824
-
825
- String path = getTestfile("Enron_000008128.xls.xlsx");
826
- try (InputStream fs = new FileInputStream(path)) {
827
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".xlsx"), null);
828
- }
829
-
830
- String json = gridJsWorkbook.exportToJson();
831
- JSONObject cpresult = new JSONObject(json);
832
- String sheetName = ((JSONObject) ((JSONObject) cpresult.getJSONArray("data").get(0))).getString("name");
833
-
834
- assertEquals("w5000", sheetName);
835
- }
836
-
837
- // Test method for CELLSGRIDJS691
838
- @Test
839
- public void testCELLSGRIDJS691() throws Exception {
840
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
841
- gridJsWorkbook.CacheImp = new LocalFileCache();
842
-
843
- String path = getTestfile("Enron_000069227.xls");
844
- try (InputStream fs = new FileInputStream(path)) {
845
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".xls"), null);
846
- }
847
-
848
- String json = gridJsWorkbook.exportToJson();
849
- JSONObject cpresult = new JSONObject(json);
850
- JSONObject sheetData = (JSONObject) cpresult.getJSONArray("data").get(0);
851
- String bgColor = sheetData.getString("bgcolor");
852
-
853
- assertEquals("#339966", bgColor);
854
- }
855
-
856
- // Test method for CELLSGRIDJS690
857
- @Test
858
- public void testCELLSGRIDJS690() throws Exception {
859
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
860
- gridJsWorkbook.CacheImp = new LocalFileCache();
861
-
862
- String path = getTestfile("hightlightwords.xlsx");
863
- try (InputStream fs = new FileInputStream(path)) {
864
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".xlsx"), null);
865
- }
866
-
867
- String json = gridJsWorkbook.exportToJson();
868
- JSONObject cpresult = new JSONObject(json);
869
- JSONObject sheetData = (JSONObject) cpresult.getJSONArray("data").get(0);
870
- String rowCount = sheetData.getJSONObject("rows").getString("len");
871
-
872
- assertEquals("21", rowCount);
873
- }
874
-
875
- @Test
876
- public void testCELLSAPP1057() throws Exception {
877
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
878
- gridJsWorkbook.CacheImp = new LocalFileCache();
879
-
880
- String path = getTestfile("lodki.dp.ua export BACK.csv");
881
- try (InputStream fs = new FileInputStream(path)) {
882
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".csv"), null);
883
- }
884
-
885
- String json = gridJsWorkbook.exportToJson();
886
- System.out.println(json);
887
- // Parse the JSON and get the unique ID for further operations
888
- JSONObject cpresult = new JSONObject(json);
889
- String uid = cpresult.getString("uniqueid");
890
-
891
- // Update operation JSON string (this should be constructed as per actual requirements)
892
- String p = "{\"sheetname\":\"sheet1\",\"actrow\":30,\"actcol\":8,\"datas\":[{\"name\":\"sheet1\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"#000000\",\"valign\":\"middle\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"#000000\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false}},{\"textwrap\":false,\"color\":\"#000000\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"custom\":\"+0\"},{\"textwrap\":false,\"color\":\"#000000\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"custom\":\"0+%\"},{\"textwrap\":false,\"color\":\"#000000\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"custom\":\"0%\"},{\"textwrap\":false,\"color\":\"#000000\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"custom\":\"m/yy\"},{\"textwrap\":false,\"color\":\"#000000\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"custom\":\"yy-m\"}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":true,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{},\"rows\":{\"height\":17,\"len\":12166},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]}";
893
-
894
- // Perform the update operation (assuming a method exists in GridJsWorkbook)
895
- gridJsWorkbook.mergeExcelFileFromJson(uid, p);
896
-
897
- // Set the PDF save timeout configuration
898
- int MAX_PDF_SAVE_SECONDS = 5;
899
- Config.setMaxPdfSaveSeconds(MAX_PDF_SAVE_SECONDS);
900
-
901
- String filename = "lodki.123.pdf";
902
- GridJsWorkbook gwb = new GridJsWorkbook();
903
- // Download operation JSON string (this should be constructed as per actual requirements)
904
- String pdownload = "{\"sheetname\":\"Sheet1\",\"actrow\":4,\"actcol\":5,\"datas\":[{\"name\":\"Sheet1\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"#000000\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false},\"custom\":\"General\"},{\"textwrap\":false,\"color\":\"#000000\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false},\"custom\":\"General\"},{\"align\":\"left\"}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":false,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{},\"rows\":{\"height\":19,\"len\":13},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet2\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"#000000\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false},\"custom\":\"General\"},{\"textwrap\":false,\"color\":\"#000000\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false},\"custom\":\"General\"}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":false,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{},\"rows\":{\"height\":19,\"len\":13},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet3\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"#000000\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false},\"custom\":\"General\"}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":false,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{},\"rows\":{\"height\":19,\"len\":13},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]}"; // Construct the JSON string for download operation
905
-
906
- // Perform the download operation (assuming a method exists in GridJsWorkbook)
907
- gwb.mergeExcelFileFromJson(uid, pdownload);
908
-
909
- // Start the stopwatch to measure the save operation duration
910
- long startTime = System.currentTimeMillis();
911
- gwb.saveToCacheWithFileName(uid, filename, null); // Assuming this method exists and saves the file
912
- long endTime = System.currentTimeMillis();
913
- long elapsedMs = endTime - startTime;
914
- System.out.println("Elapsed: " + elapsedMs);
915
-
916
- // Assert that the elapsed time is within the expected range
917
- assertTrue(elapsedMs >= MAX_PDF_SAVE_SECONDS * 1000,
918
- "The actual time cost for save was less than " + MAX_PDF_SAVE_SECONDS + " seconds");
919
- assertTrue(elapsedMs <= (MAX_PDF_SAVE_SECONDS + 3) * 1000,
920
- "The actual time cost for save was more than " + (MAX_PDF_SAVE_SECONDS + 3) + " seconds");
921
- }
922
-
923
- @Test
924
- public void testGRIDJS359() throws Exception {
925
- Config.setSaveHtmlAsZip(true);
926
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
927
- gridJsWorkbook.CacheImp = new LocalFileCache();
928
-
929
- String path = getTestfile("test.htm");
930
- try (InputStream fs = new FileInputStream(path)) {
931
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".htm"), null);
932
- }
933
-
934
- String json = gridJsWorkbook.exportToJson();
935
- System.out.println(json);
936
- // Do update
937
- JSONObject cpresult = new JSONObject(json);
938
- String uid = cpresult.getString("uniqueid");
939
- String p = "{\"name\":\"Sheet1\",\"ri\":2,\"ci\":1,\"text\":\"cc\",\"op\":\"update\"}";
940
- String ret = gridJsWorkbook.updateCell(p, uid);
941
-
942
- // Do download
943
- String filename = "123.htm";
944
- GridJsWorkbook gwb = new GridJsWorkbook();
945
- String pdownload = "{\"sheetname\":\"Sheet1\",\"actrow\":4,\"actcol\":5,\"datas\":[{\"name\":\"Sheet1\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"#000000\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false},\"custom\":\"General\"},{\"textwrap\":false,\"color\":\"#000000\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false},\"custom\":\"General\"},{\"align\":\"left\"}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":false,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{},\"rows\":{\"height\":19,\"len\":13},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet2\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"#000000\",\"align\":\"right\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false},\"custom\":\"General\"},{\"textwrap\":false,\"color\":\"#000000\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false},\"custom\":\"General\"}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":false,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{},\"rows\":{\"height\":19,\"len\":13},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]},{\"name\":\"Sheet3\",\"freeze\":\"A1\",\"styles\":[{\"textwrap\":false,\"color\":\"#000000\",\"valign\":\"middle\",\"font\":{\"name\":\"宋体\",\"size\":12,\"bold\":false,\"italic\":false},\"custom\":\"General\"}],\"comments\":[],\"canselectlocked\":true,\"sprotected\":false,\"canselectunlocked\":true,\"showGrid\":false,\"merges\":[],\"settings\":{\"mode\":\"edit\",\"updateMode\":\"server\",\"updateUrl\":\"/GridJs2/UpdateCell\",\"folderName\":\"\",\"fileName\":\"\",\"view\":{},\"showToolbar\":true,\"showPartToolbar\":false,\"showContextmenu\":true,\"row\":{\"len\":100,\"height\":25},\"col\":{\"len\":26,\"width\":100,\"indexWidth\":60,\"minWidth\":60},\"style\":{\"align\":\"left\",\"valign\":\"middle\",\"textwrap\":false,\"strike\":false,\"underline\":false,\"color\":\"#0a0a0a\",\"font\":{\"name\":\"Arial\",\"size\":10,\"bold\":false,\"italic\":false},\"format\":\"normal\"}},\"cols\":{},\"rows\":{\"height\":19,\"len\":13},\"validations\":[],\"autofilter\":{},\"images\":[],\"shapes\":[]}]}"; // Construct the JSON string for download operation
946
- gwb.mergeExcelFileFromJson(uid, pdownload);
947
- gwb.saveToCacheWithFileName(uid, filename, null);
948
-
949
- if (filename.endsWith(".html") || filename.endsWith(".htm")) {
950
- filename += ".zip";
951
- }
952
-
953
- String downloadPath = GridJsWorkbook.getImageUrl(uid, filename, "/");
954
- int ididx = downloadPath.indexOf("id=");
955
- String downloadId = downloadPath.substring(ididx + 3);
956
- System.out.println(downloadId);
957
-
958
- InputStream fsReader = (InputStream) gridJsWorkbook.CacheImp.loadStream(downloadId);
959
- byte[] bytes = new byte[fsReader.available()];
960
- fsReader.read(bytes);
961
- String fileOutput = getOutputfile("123htm.zip");
962
- if (new File(fileOutput).exists()) {
963
- new File(fileOutput).delete();
964
- }
965
- try (FileOutputStream fwrite = new FileOutputStream(fileOutput)) {
966
- fwrite.write(bytes);
967
- }
968
-
969
- String zipOutputDir = getOutputfile("123htm");
970
- Util.unZip(fileOutput, zipOutputDir);
971
- Thread.sleep(1000);
972
- Workbook workbook = new Workbook(getOutputfile("123htm/123.htm"));
973
- assertEquals("cc", workbook.getWorksheets().get("Sheet1").getCells().get(2, 1).getStringValue());
974
- // Restore config
975
- Config.setSaveHtmlAsZip(false);
976
- }
977
-
978
- @Test
979
- public void testImageLimit() throws Exception {
980
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
981
- gridJsWorkbook.CacheImp = new LocalFileCache();
982
-
983
- String path = getTestfile("pictest.xls");
984
- try (InputStream fs = new FileInputStream(path)) {
985
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".xls"), null);
986
- }
987
-
988
- Config.setMaxShapeOrImageCount(2);
989
- Config.setMaxTotalShapeOrImageCount(31);
990
- String json = gridJsWorkbook.exportToJson();
991
- System.out.println(json);
992
- JSONObject cpresult = new JSONObject(json);
993
- int len = ((JSONObject) cpresult.getJSONArray("data").get(0)).getJSONArray("shapes").length();
994
- int len2 = ((JSONObject) cpresult.getJSONArray("data").get(1)).getJSONArray("shapes").length();
995
- int len3 = ((JSONObject) cpresult.getJSONArray("data").get(2)).getJSONArray("shapes").length();
996
- assertEquals(29, len);
997
- assertEquals(2, len2);
998
- assertEquals(1, len3);
999
-
1000
- len2 = ((JSONObject) cpresult.getJSONArray("data").get(1)).getJSONArray("images").length();
1001
- len3 = ((JSONObject) cpresult.getJSONArray("data").get(2)).getJSONArray("images").length();
1002
- assertEquals(2, len2);
1003
- assertEquals(4, len3);
1004
-
1005
- // Do not limit the shape or image count
1006
- Config.setIslimitShapeOrImage(false);
1007
- json = gridJsWorkbook.exportToJson();
1008
- cpresult = new JSONObject(json);
1009
- System.out.println(json);
1010
- len = ((JSONObject) cpresult.getJSONArray("data").get(0)).getJSONArray("shapes").length();
1011
- len2 = ((JSONObject) cpresult.getJSONArray("data").get(1)).getJSONArray("shapes").length();
1012
- len3 = ((JSONObject) cpresult.getJSONArray("data").get(2)).getJSONArray("shapes").length();
1013
- assertEquals(29, len);
1014
- assertEquals(11, len2);
1015
- assertEquals(2, len3);
1016
-
1017
- len2 = ((JSONObject) cpresult.getJSONArray("data").get(1)).getJSONArray("images").length();
1018
- len3 = ((JSONObject) cpresult.getJSONArray("data").get(2)).getJSONArray("images").length();
1019
- assertEquals(3, len2);
1020
- assertEquals(4, len3);
1021
-
1022
- // Reset config to default value
1023
- Config.setIslimitShapeOrImage(true);
1024
- }
1025
-
1026
- @Test
1027
- public void testCopyImageToSameSheet() throws Exception {
1028
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
1029
- gridJsWorkbook.CacheImp = new LocalFileCache();
1030
- String path = getTestfile("pictest.xls");
1031
- try (InputStream fs = new FileInputStream(path)) {
1032
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".xls"), "123");
1033
- }
1034
- String json = gridJsWorkbook.exportToJson();
1035
- JSONObject cpresult = new JSONObject(json);
1036
- String uid = cpresult.getString("uniqueid");
1037
-
1038
- String p = "{\"name\":\"Sheet2\",\"srcname\":\"Sheet2\",\"ri\":11,\"ci\":3,\"srcid\":146,\"isshape\":false}";
1039
- String p2 = "{\"name\":\"Sheet2\",\"srcname\":\"Sheet2\",\"ri\":11,\"ci\":1,\"srcid\":100,\"isshape\":false}";
1040
- String expect_w = "206";
1041
- String expect_h = "72";
1042
- String expect_err_msg = "{\"Error\":\"wrong picture id \"}";
1043
-
1044
- Workbook wb1 = new Workbook(path);
1045
- int count = wb1.getWorksheets().get("Sheet2").getPictures().getCount();
1046
- testAddPictureOrShape(gridJsWorkbook, uid, p, p2, expect_w, expect_h, expect_err_msg, count, "Sheet2");
1047
-
1048
- }
1049
-
1050
- @Test
1051
- public void testCopyImageToOtherSheet() throws Exception {
1052
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
1053
- gridJsWorkbook.CacheImp = new LocalFileCache();
1054
- String path = getTestfile("pictest.xls");
1055
-
1056
- try (InputStream fs = new FileInputStream(path)) {
1057
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".xls"), "123");
1058
- }
1059
- String json = gridJsWorkbook.exportToJson();
1060
- System.out.println(json);
1061
- JSONObject cpresult = new JSONObject(json);
1062
- String uid = cpresult.getString("uniqueid");
1063
-
1064
- String p = "{\"name\":\"Sheet3\",\"srcname\":\"Sheet2\",\"ri\":11,\"ci\":3,\"srcid\":146,\"isshape\":false}";
1065
- String p2 = "{\"name\":\"Sheet3\",\"srcname\":\"Sheet2\",\"ri\":11,\"ci\":1,\"srcid\":100,\"isshape\":false}";
1066
- String expect_w = "206";
1067
- String expect_h = "72";
1068
- String expect_err_msg = "{\"Error\":\"wrong picture id \"}";
1069
-
1070
- Workbook wb1 = new Workbook(path); // No try-with-resources
1071
- int count = wb1.getWorksheets().get("Sheet3").getPictures().getCount();
1072
- testAddPictureOrShape(gridJsWorkbook, uid, p, p2, expect_w, expect_h, expect_err_msg, count, "Sheet3");
1073
-
1074
- }
1075
- @Test
1076
- public void testCopyImageWithNoStreamCacheImp() throws Exception {
1077
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
1078
- gridJsWorkbook.CacheImp =null;
1079
- String path = getTestfile("pictest.xls");
1080
- gridJsWorkbook.importExcelFile(path);
1081
-
1082
- String json = gridJsWorkbook.exportToJson();
1083
- System.out.println(json);
1084
- JSONObject cpresult = new JSONObject(json);
1085
- String uid = cpresult.getString("uniqueid");
1086
-
1087
- String p = "{\"name\":\"Sheet3\",\"srcname\":\"Sheet2\",\"ri\":11,\"ci\":3,\"srcid\":146,\"isshape\":false}";
1088
- String p2 = "{\"name\":\"Sheet3\",\"srcname\":\"Sheet2\",\"ri\":11,\"ci\":1,\"srcid\":100,\"isshape\":false}";
1089
- String expect_w = "206";
1090
- String expect_h = "72";
1091
- String expect_err_msg = "{\"Error\":\"wrong picture id \"}";
1092
-
1093
- Workbook wb1 = new Workbook(path); // No try-with-resources
1094
- int count = wb1.getWorksheets().get("Sheet3").getPictures().getCount();
1095
- testAddPictureOrShape(gridJsWorkbook, uid, p, p2, expect_w, expect_h, expect_err_msg, count, "Sheet3");
1096
-
1097
- }
1098
-
1099
- @Test
1100
- public void testCELLSGRIDJS392ReloadByUid() throws Exception {
1101
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
1102
- gridJsWorkbook.CacheImp = new LocalFileCache();
1103
- ByteArrayOutputStream ms = new ByteArrayOutputStream();
1104
- Workbook wb = new Workbook();
1105
- wb.save(ms, SaveFormat.XLSX);
1106
- gridJsWorkbook.importExcelFile(new java.io.ByteArrayInputStream(ms.toByteArray()), GridLoadFormat.XLSX);
1107
-
1108
-
1109
- String json = gridJsWorkbook.exportToJson();
1110
- JSONObject cpresult = new JSONObject(json);
1111
- String uid = cpresult.getString("uniqueid");
1112
- String p = "{\"name\":\"Sheet1\",\"ri\":4,\"ci\":11,\"text\":\"=sin(1)\",\"op\":\"update\"}";
1113
- gridJsWorkbook.updateCell(p, uid);
1114
- StringBuilder ret = gridJsWorkbook.getJsonByUid(uid, "hello1.xlsx");
1115
- System.out.println(ret.toString()); // Use the indented print method if needed
1116
-
1117
- String path = getTestfile("simplejava.json");
1118
- String expected = new String(java.nio.file.Files.readAllBytes(java.nio.file.Paths.get(path)));
1119
- JSONObject cpresult2 = new JSONObject(ret.toString());
1120
- System.out.println(cpresult2.getJSONArray("data").getString(0));
1121
-
1122
- assertEquals(expected, cpresult2.getJSONArray("data").getString(0));
1123
-
1124
- // Test for a wrong uid
1125
- StringBuilder ret3 = null;
1126
- try {
1127
- ret3 = gridJsWorkbook.getJsonByUid(uid + "123", "");
1128
- } catch (IOException e) {
1129
- // If an exception is expected, handle it here
1130
- }
1131
- assertNull(ret3);
1132
- }
1133
-
1134
- @Test
1135
- public void testCELLSGRIDJS433Sort() throws Exception {
1136
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
1137
- gridJsWorkbook.CacheImp = new LocalFileCache();
1138
-
1139
- String path = getTestfile("travel-cccbudget.xlsx");
1140
- InputStream fs = new FileInputStream(path);
1141
- Workbook workbook = new Workbook(fs);
1142
- ByteArrayOutputStream ms = new ByteArrayOutputStream();
1143
- workbook.save(ms, SaveFormat.XLSX);
1144
- gridJsWorkbook.importExcelFile(new java.io.ByteArrayInputStream(ms.toByteArray()),
1145
- GridLoadFormat.XLSX);
1146
-
1147
- String json = gridJsWorkbook.exportToJson();
1148
- System.out.println(json);
1149
- JSONObject cpresult = new JSONObject(json);
1150
- String uid = cpresult.getString("uniqueid");
1151
-
1152
- // Sort with header
1153
- String p = "{\"name\":\"Travel Budget\",\"src\":{\"sri\":13,\"sci\":1,\"eri\":20,\"eci\":6,\"w\":0,\"h\":0},\"ci\":[5],\"order\":[\"asc\"],\"isheader\":true,\"op\":\"sort\"}";
1154
- String ret = gridJsWorkbook.updateCell(p, uid);
1155
- String expected = "{\"op\":\"sort\",\"status\":\"ok\",\"r\":{\"sri\":14,\"eri\":20,\"sci\":1,\"eci\":6},\"rowids\":[17,18,16,20,19,15,14]}";
1156
- assertEquals(expected, ret);
1157
-
1158
- // Sort without header
1159
- p = "{\"name\":\"Travel Budget\",\"src\":{\"sri\":13,\"sci\":3,\"eri\":19,\"eci\":5,\"w\":0,\"h\":0},\"ci\":[2],\"order\":[\"desc\"],\"isheader\":false,\"op\":\"sort\"}";
1160
- expected = "{\"op\":\"sort\",\"status\":\"ok\",\"r\":{\"sri\":13,\"eri\":19,\"sci\":3,\"eci\":5},\"rowids\":[13,18,16,19,17,14,15]}";
1161
- ret = gridJsWorkbook.updateCell(p, uid);
1162
- assertEquals(expected, ret);
1163
- }
1164
-
1165
- @Test
1166
- public void testCopyShape() throws Exception {
1167
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
1168
- gridJsWorkbook.CacheImp = new LocalFileCache();
1169
-
1170
- String path = getTestfile("pictest.xls");
1171
- try (InputStream fs = new FileInputStream(path)) {
1172
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".xls"), "123");
1173
- }
1174
- String json = gridJsWorkbook.exportToJson();
1175
- System.out.println(json);
1176
- JSONObject cpresult = new JSONObject(json);
1177
- String uid = cpresult.getString("uniqueid");
1178
-
1179
- String p = "{\"name\":\"Sheet3\",\"srcname\":\"Sheet2\",\"ri\":11,\"ci\":3,\"srcid\":135,\"isshape\":true}";
1180
- String p2 = "{\"name\":\"Sheet3\",\"srcname\":\"Sheet2\",\"ri\":11,\"ci\":1,\"srcid\":100,\"isshape\":true}";
1181
- String expect_w = "138";
1182
- String expect_h = "46";
1183
- String expect_err_msg = "{\"Error\":\"wrong shape id \"}";
1184
-
1185
- Workbook wb1 = new Workbook(path);
1186
- int count = wb1.getWorksheets().get("Sheet3").getShapes().getCount();
1187
- testAddPictureOrShape(gridJsWorkbook, uid, p, p2, expect_w, expect_h, expect_err_msg, count,
1188
- "Sheet3");
1189
-
1190
- }
1191
-
1192
- @Test
1193
- public void testCopySameShapeMultipleTimes() throws Exception {
1194
- GridJsWorkbook gridJsWorkbook = new GridJsWorkbook();
1195
- gridJsWorkbook.CacheImp = new LocalFileCache();
1196
-
1197
- String path = getTestfile("pictest.xls");
1198
- try (InputStream fs = new FileInputStream(path)) {
1199
- gridJsWorkbook.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat(".xls"), "123");
1200
- }
1201
- String json = gridJsWorkbook.exportToJson();
1202
- System.out.println(json);
1203
- JSONObject cpresult = new JSONObject(json);
1204
- String uid = cpresult.getString("uniqueid");
1205
- int ccc = 0;
1206
-
1207
- for (int ri = 2; ri <= 12; ri++) {
1208
- for (int ci = 3; ci <= 10; ci++) {
1209
- String p = String.format("{\"name\":\"Sheet3\",\"srcname\":\"Sheet2\",\"ri\":%d,\"ci\":%d,\"srcid\":1,\"isshape\":true}", ri, ci);
1210
- String p2 = "{\"name\":\"Sheet3\",\"srcname\":\"Sheet2\",\"ri\":11,\"ci\":1,\"srcid\":100,\"isshape\":true}";
1211
- String expect_w = "141";
1212
- String expect_h = "49";
1213
- String expect_err_msg = "{\"Error\":\"wrong shape id \"}";
1214
-
1215
- // Copy the shape multiple times
1216
- try {
1217
- String picret = gridJsWorkbook.copyImageOrShape(uid, p);
1218
- picret = gridJsWorkbook.copyImageOrShape(uid, p);
1219
- picret = gridJsWorkbook.copyImageOrShape(uid, p);
1220
- ccc += 3;
1221
- } catch (Exception e) {
1222
- System.out.println(e.getMessage());
1223
- }
1224
- }
1225
- System.out.println("execute copy :" + ccc);
1226
- }
1227
- }
1228
-
1229
- //TODO still left 6 cases
1230
-
1231
- private static void testAddPictureOrShape(GridJsWorkbook gw, String uid, String p, String p2, String expect_w, String expect_h, String expect_err_msg, int expectid, String targetsheet) throws Exception {
1232
- String picret = gw.copyImageOrShape(uid, p);
1233
-
1234
- JSONObject paramjson = new JSONObject(p);
1235
- boolean isshape = paramjson.getBoolean("isshape");
1236
-
1237
- System.out.println("copy image :" + picret);
1238
- JSONObject picretjson = new JSONObject(picret);
1239
- int picid = picretjson.getInt("id");
1240
- assertEquals(expectid, picid);
1241
-
1242
- String picurl = picretjson.getString("url");
1243
- if (picurl == null) {
1244
- // Handle the case when picurl is null
1245
- } else {
1246
- int ididx = picurl.indexOf("id=");
1247
- String downloadid = picurl.substring(ididx + 3);
1248
- System.out.println(downloadid);
1249
- // Additional code to test the image stream might go here
1250
- }
1251
-
1252
- ByteArrayOutputStream ms = new ByteArrayOutputStream();
1253
- gw.saveToExcelFile(ms);
1254
- ms.flush();
1255
- ByteArrayInputStream inputStream = new ByteArrayInputStream(ms.toByteArray());
1256
- Workbook wb = new Workbook(inputStream);
1257
- Worksheet sheet = wb.getWorksheets().get(targetsheet);
1258
- Shape sp = isshape ? sheet.getShapes().get(picid) : sheet.getPictures().get(picid);
1259
-
1260
- int w = sp.getWidth();
1261
- int h = sp.getHeight();
1262
-
1263
- assertEquals(expect_w, String.valueOf(w));
1264
- assertEquals(expect_h, String.valueOf(h));
1265
- assertEquals(expect_w, String.valueOf(picretjson.getInt("width")));
1266
- assertEquals(expect_h, String.valueOf(picretjson.getInt("height")));
1267
- assertEquals(11, sp.getUpperLeftRow());
1268
- assertEquals(3, sp.getUpperLeftColumn());
1269
-
1270
- picret = gw.copyImageOrShape(uid, p2);
1271
- assertEquals(expect_err_msg, picret);
1272
- }
1273
-
1274
- public static InputStream getStreamFromUrl(String url) throws Exception {
1275
- HttpsURLConnection connection = (HttpsURLConnection) new URL(url).openConnection();
1276
- connection.setRequestMethod("GET");
1277
- connection.connect();
1278
-
1279
- int responseCode = connection.getResponseCode();
1280
- if (responseCode == HttpsURLConnection.HTTP_OK) {
1281
- return connection.getInputStream();
1282
- } else {
1283
- throw new RuntimeException("Failed to download the image: HTTP error code " + responseCode);
1284
- }
1285
- }
1286
- private void insertImage(String url, String[] uidOut) throws Exception {
1287
- GridJsWorkbook gw = new GridJsWorkbook();
1288
- gw.CacheImp=(new LocalFileCache()); // Use stream cache
1289
-
1290
- String path = getTestfile("pictest.xls");
1291
- try (FileInputStream fs = new FileInputStream(path)) {
1292
- gw.importExcelFile(fs, GridJsWorkbook.getGridLoadFormat("pictest.xls"), "123");
1293
- }
1294
- String json = gw.exportToJson();
1295
- System.out.println(json);
1296
- JSONObject cpresult = new JSONObject(json);
1297
- String uid = cpresult.getString("uniqueid");
1298
- uidOut[0] = uid;
1299
- String p = "{\"name\":\"Sheet2\",\"ri\":1,\"ci\":1}";
1300
- String picRet = null;
1301
- String expectW = null;
1302
- String expectH = null;
1303
-
1304
- InputStream imageStream = null;
1305
- if (url == null) { // Use local image file
1306
- File imageFile = new File(getTestfile("snap1.png"));
1307
- try (FileInputStream s = new FileInputStream(imageFile)) {
1308
- imageStream = s;
1309
- picRet = gw.insertImage(uid, p, imageStream, url);
1310
- expectW = "320";
1311
- expectH = "204";
1312
- }
1313
- } else { // Use URL to get image
1314
- imageStream = getStreamFromUrl(url);
1315
- picRet = gw.insertImage(uid, p, imageStream, url);
1316
- expectW = "202";
1317
- expectH = "66";
1318
- }
1319
- System.out.println("insert first image : " + picRet);
1320
- JSONObject picRetJson = new JSONObject(picRet);
1321
-
1322
- int picId = picRetJson.getInt("id");
1323
- assertEquals(3, picId);
1324
-
1325
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
1326
- gw.saveToExcelFile(baos);
1327
-
1328
- baos.close();
1329
-
1330
- byte[] byteArray = baos.toByteArray();
1331
- try (ByteArrayInputStream bais = new ByteArrayInputStream(byteArray)) {
1332
- Workbook wb = new Workbook(bais);
1333
-
1334
- Worksheet sheet = wb.getWorksheets().get("Sheet2"); // Assuming "Sheet2" is the name of the sheet
1335
- Shape sp = (Shape) sheet.getPictures().get(picId); // Shapes are typically stored in a list of sheet objects, and the ID might need to be adjusted
1336
-
1337
- int w = sp.getWidth();
1338
- int h = sp.getHeight();
1339
-
1340
- assertEquals(expectW, Integer.toString(w));
1341
- assertEquals(expectH, Integer.toString(h));
1342
- assertEquals(expectW, picRetJson.getString("width"));
1343
- assertEquals(expectH, picRetJson.getString("height"));
1344
-
1345
- // Mock another post from controller action
1346
- // Add second image with a new GridJsWorkbook instance
1347
- gw = new GridJsWorkbook();
1348
- gw.CacheImp=(new LocalFileCache()); // Use stream cache
1349
- p = "{\"name\":\"Sheet2\",\"ri\":3,\"ci\":3}";
1350
-
1351
- if (url == null) { // Use local image file
1352
- File imageFile = new File(getTestfile("snap1.png"));
1353
- try (FileInputStream s = new FileInputStream(imageFile)) {
1354
- picRet = gw.insertImage(uid, p, s, url);
1355
- System.out.println("insert second image : " + picRet);
1356
- }
1357
- } else { // Use URL to get image
1358
- imageStream = getStreamFromUrl(url);
1359
- picRet = gw.insertImage(uid, p, imageStream, url);
1360
- }
1361
-
1362
- picRetJson = new JSONObject(picRet);
1363
-
1364
- baos = new ByteArrayOutputStream();
1365
- gw.saveToExcelFile(baos);
1366
-
1367
- baos.close();
1368
-
1369
- byteArray = baos.toByteArray();
1370
- try (ByteArrayInputStream bais2 = new ByteArrayInputStream(byteArray)) {
1371
- Workbook wb2 = new Workbook(bais2);
1372
- picId = picRetJson.getInt("id");
1373
- assertNotNull(picRetJson.get("url"));
1374
- assertEquals(4, picId);
1375
- if (url != null) {
1376
- assertEquals(url, picRetJson.getString("url"));
1377
- }
1378
-
1379
- sheet = wb2.getWorksheets().get("Sheet2");
1380
- sp = (Shape) sheet.getPictures().get(picId);
1381
- w = sp.getWidth();
1382
- h = sp.getHeight();
1383
- assertEquals(expectW, Integer.toString(w));
1384
- assertEquals(expectH, Integer.toString(h));
1385
-
1386
- // The first picture shall still be there
1387
- sp = (Shape) sheet.getPictures().get(3);
1388
- w = sp.getWidth();
1389
- h = sp.getHeight();
1390
- assertEquals(expectW, Integer.toString(w));
1391
- assertEquals(expectH, Integer.toString(h));
1392
- }
1393
- }
1394
- }
1395
-
1396
- private static void testImageZipFiles(String uid, int expectedFileCount) throws IOException {
1397
- GridJsWorkbook gw = new GridJsWorkbook();
1398
- String zipOutDir = getOutputfile("s0_batch");
1399
- String outputFile = getOutputfile("s0_batch.zip");
1400
-
1401
- try {
1402
- Files.deleteIfExists(Paths.get(outputFile));
1403
- Util.clearFolder((zipOutDir));
1404
- } catch (IOException e) {
1405
- System.out.println("Delete failed: " + e.getMessage());
1406
- }
1407
-
1408
- String filename = "s0_batch.zip";
1409
- String downloadPath = GridJsWorkbook.getImageUrl(uid, filename, "/");
1410
- int idIdx = downloadPath.indexOf("id=");
1411
- String downloadId = downloadPath.substring(idIdx + 3);
1412
- System.out.println(downloadId);
1413
-
1414
- try (InputStream fsReader = gw.CacheImp.loadStream(downloadId)) {
1415
-
1416
- try (FileOutputStream fwrite = new FileOutputStream(outputFile)) {
1417
- Util.copyStream(fsReader, fwrite);
1418
- }
1419
- }
1420
-
1421
- Util.unZip(outputFile, zipOutDir);
1422
-
1423
- Path dirPath = Paths.get(zipOutDir);
1424
- File[] files = dirPath.toFile().listFiles();
1425
- assertEquals(expectedFileCount, files.length);
1426
- }
1427
-
1428
- private static void addPictureToWb(Random rd, Workbook wb, String imagePath) throws Exception {
1429
- try (FileInputStream s = new FileInputStream(imagePath)) {
1430
- for (int i = 0; i <= 400; i += 40) {
1431
- for (int j = 0; j <= 100; j += 5) {
1432
- int picId = wb.getWorksheets().get(0).getPictures().add( i, j,s);
1433
- wb.getWorksheets().get(0).getCells().get(i, j).putValue(i + " - " + j);
1434
- if (picId % 10 == 0) {
1435
- wb.getWorksheets().get(0).getPictures().get(picId).setRotationAngle(rd.nextInt(180));
1436
- }
1437
- }
1438
- }
1439
- }
1440
- }
1441
- }