您好,我这边测试了一下,是可以正常显示的:
- public static void main(String[] args) throws Exception {
- Workbook workbook = new Workbook();
- workbook.open("D:\\Code\\GcExcel_demo_maven\\src\\main\\resources\\json.ssjson");
- String jsonText = "";
- try {
- InputStream stream = getResourceStream("ds.txt");
- ByteArrayOutputStream result = new ByteArrayOutputStream();
- byte[] buffer = new byte[1024];
- int length;
- while ((length = stream.read(buffer)) != -1) {
- result.write(buffer, 0, length);
- }
- jsonText = result.toString("UTF-8");
- } catch (IOException e) {
- e.printStackTrace();
- }
- JSONObject jsonObject = new JSONObject(jsonText);
- for (int i = 0; i < workbook.getWorksheets().getCount(); i++) {
- String data = jsonObject.get(workbook.getWorksheets().get(i).getName()).toString();
- workbook.getWorksheets().get(i).setDataSource(new JsonDataSource(data));
- }
- workbook.save("xlsx.xlsx");
- }
- private static InputStream getResourceStream(String resource) throws Exception {
- return Test.class.getClassLoader().getResourceAsStream(resource);
- }
复制代码 |