本帖最后由 浅梦在枫叶间 于 2023-5-12 13:23 编辑
- package com.admin.test;/**
- * 描述:
- *
- * @author admin
- * @date 2023/5/12 11:17
- */
- import com.grapecity.documents.excel.Workbook;
- import java.io.ByteArrayInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.Reader;
- import java.util.Locale;
- import org.junit.Test;
- /**
- * @author wangdezhi
- * @data
- */
- public class TimeScopeTest {
- @Test
- public void test() throws Exception {
- String ssJson = readJsonFile("D:\\chrome\\download\\c.ssjson");
- ByteArrayInputStream stream = new ByteArrayInputStream(ssJson.getBytes());
- Workbook workbook = new Workbook();
- Workbook.SetLicenseKey(
- "your_key");
- workbook.setCulture(Locale.CHINESE);
- workbook.fromJson(stream);
- writeJsonFile("D:\\chrome\\download\\b.ssjson", workbook.toJson());
- }
- public void writeJsonFile(String fileName, String json) {
- try {
- FileWriter writer = new FileWriter(fileName);
- writer.write(json);
- writer.close();
- } catch (IOException ignore) {
- }
- }
- public String readJsonFile(String fileName) throws IOException {
- String jsonStr = "";
- try {
- File jsonFile = new File(fileName);
- FileReader fileReader = new FileReader(jsonFile);
- Reader reader = new InputStreamReader(new FileInputStream(jsonFile), "utf-8");
- int ch = 0;
- StringBuffer sb = new StringBuffer();
- while ((ch = reader.read()) != -1) {
- sb.append((char) ch);
- }
- fileReader.close();
- reader.close();
- jsonStr = sb.toString();
- return jsonStr;
- } catch (IOException e) {
- return null;
- }
- }
- }
复制代码 |
-
-
c.zip
148.59 KB, 下载次数: 239
|