package com.zbitiOnlineSheet.onlinesheet.controller;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.zbitiOnlineSheet.common.core.domain.entity.SysUser;
import com.zbitiOnlineSheet.common.utils.DateUtils;
import com.zbitiOnlineSheet.common.utils.ShiroUtils;
import com.zbitiOnlineSheet.onlinesheet.domain.OnlineList;
import com.zbitiOnlineSheet.onlinesheet.domain.OnlineSheet;
import com.zbitiOnlineSheet.onlinesheet.service.IOnlineListService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import java.util.UUID;
/**
* @author wangjin
* @title: Test
* @description; 项目
* @date 2021/3/8 18:11
*/
public class Test {
public static void main(String[] args) {
String str = "{\n" +
"\t\"info\": {\n" +
"\t\t\"name\": \"test导入.xlsx\",\n" +
"\t\t\"creator\": \"\",\n" +
"\t\t\"lastmodifiedby\": \"\",\n" +
"\t\t\"createdTime\": \"2015-06-05T18:19:34Z\",\n" +
"\t\t\"modifiedTime\": \"2021-03-08T06:52:57Z\",\n" +
"\t\t\"company\": \"\",\n" +
"\t\t\"appversion\": \"16.0300\"\n" +
"\t},\n" +
"\t\"sheets\": [\n" +
"\t\t{\n" +
"\t\t\t\"name\": \"Sheet1\",\n" +
"\t\t\t\"config\": {},\n" +
"\t\t\t\"index\": \"1\",\n" +
"\t\t\t\"status\": \"0\",\n" +
"\t\t\t\"order\": \"0\",\n" +
"\t\t\t\"luckysheet_select_save\": [\n" +
"\t\t\t\t{\n" +
"\t\t\t\t\t\"row\": [\n" +
"\t\t\t\t\t\t9,\n" +
"\t\t\t\t\t\t9\n" +
"\t\t\t\t\t],\n" +
"\t\t\t\t\t\"column\": [\n" +
"\t\t\t\t\t\t3,\n" +
"\t\t\t\t\t\t3\n" +
"\t\t\t\t\t],\n" +
"\t\t\t\t\t\"sheetIndex\": 1\n" +
"\t\t\t\t}\n" +
"\t\t\t],\n" +
"\t\t\t\"zoomRatio\": 1,\n" +
"\t\t\t\"showGridLines\": \"1\",\n" +
"\t\t\t\"defaultColWidth\": 72,\n" +
"\t\t\t\"defaultRowHeight\": 18,\n" +
"\t\t\t\"celldata\": [\n" +
"\t\t\t\t{\n" +
"\t\t\t\t\t\"r\": 1,\n" +
"\t\t\t\t\t\"c\": 0,\n" +
"\t\t\t\t\t\"v\": {\n" +
"\t\t\t\t\t\t\"tb\": 1,\n" +
"\t\t\t\t\t\t\"v\": \"发个发光飞碟梵蒂冈发的\",\n" +
"\t\t\t\t\t\t\"qp\": 1\n" +
"\t\t\t\t\t}\n" +
"\t\t\t\t},\n" +
"\t\t\t\t{\n" +
"\t\t\t\t\t\"r\": 5,\n" +
"\t\t\t\t\t\"c\": 1,\n" +
"\t\t\t\t\t\"v\": {\n" +
"\t\t\t\t\t\t\"tb\": 1,\n" +
"\t\t\t\t\t\t\"v\": \"发的地方\",\n" +
"\t\t\t\t\t\t\"qp\": 1\n" +
"\t\t\t\t\t}\n" +
"\t\t\t\t},\n" +
"\t\t\t\t{\n" +
"\t\t\t\t\t\"r\": 5,\n" +
"\t\t\t\t\t\"c\": 2,\n" +
"\t\t\t\t\t\"v\": {\n" +
"\t\t\t\t\t\t\"tb\": 1,\n" +
"\t\t\t\t\t\t\"v\": \"热让他让他热热他 \",\n" +
"\t\t\t\t\t\t\"qp\": 1\n" +
"\t\t\t\t\t}\n" +
"\t\t\t\t}\n" +
"\t\t\t],\n" +
"\t\t\t\"calcChain\": []\n" +
"\t\t},\n" +
"\t\t{\n" +
"\t\t\t\"name\": \"Sheet2\",\n" +
"\t\t\t\"config\": {},\n" +
"\t\t\t\"index\": \"2\",\n" +
"\t\t\t\"status\": \"0\",\n" +
"\t\t\t\"order\": \"1\",\n" +
"\t\t\t\"luckysheet_select_save\": [\n" +
"\t\t\t\t{\n" +
"\t\t\t\t\t\"row\": [\n" +
"\t\t\t\t\t\t24,\n" +
"\t\t\t\t\t\t24\n" +
"\t\t\t\t\t],\n" +
"\t\t\t\t\t\"column\": [\n" +
"\t\t\t\t\t\t5,\n" +
"\t\t\t\t\t\t5\n" +
"\t\t\t\t\t],\n" +
"\t\t\t\t\t\"sheetIndex\": 2\n" +
"\t\t\t\t}\n" +
"\t\t\t],\n" +
"\t\t\t\"zoomRatio\": 1,\n" +
"\t\t\t\"showGridLines\": \"1\",\n" +
"\t\t\t\"defaultColWidth\": 72,\n" +
"\t\t\t\"defaultRowHeight\": 18,\n" +
"\t\t\t\"celldata\": [\n" +
"\t\t\t\t{\n" +
"\t\t\t\t\t\"r\": 10,\n" +
"\t\t\t\t\t\"c\": 2,\n" +
"\t\t\t\t\t\"v\": {\n" +
"\t\t\t\t\t\t\"tb\": 1,\n" +
"\t\t\t\t\t\t\"v\": \"44454\"\n" +
"\t\t\t\t\t}\n" +
"\t\t\t\t},\n" +
"\t\t\t\t{\n" +
"\t\t\t\t\t\"r\": 15,\n" +
"\t\t\t\t\t\"c\": 4,\n" +
"\t\t\t\t\t\"v\": {\n" +
"\t\t\t\t\t\t\"tb\": 1,\n" +
"\t\t\t\t\t\t\"v\": \"545\"\n" +
"\t\t\t\t\t}\n" +
"\t\t\t\t}\n" +
"\t\t\t],\n" +
"\t\t\t\"calcChain\": []\n" +
"\t\t},\n" +
"\t\t{\n" +
"\t\t\t\"name\": \"Sheet3\",\n" +
"\t\t\t\"config\": {},\n" +
"\t\t\t\"index\": \"3\",\n" +
"\t\t\t\"status\": \"1\",\n" +
"\t\t\t\"order\": \"2\",\n" +
"\t\t\t\"luckysheet_select_save\": [\n" +
"\t\t\t\t{\n" +
"\t\t\t\t\t\"row\": [\n" +
"\t\t\t\t\t\t18,\n" +
"\t\t\t\t\t\t18\n" +
"\t\t\t\t\t],\n" +
"\t\t\t\t\t\"column\": [\n" +
"\t\t\t\t\t\t6,\n" +
"\t\t\t\t\t\t6\n" +
"\t\t\t\t\t],\n" +
"\t\t\t\t\t\"sheetIndex\": 3\n" +
"\t\t\t\t}\n" +
"\t\t\t],\n" +
"\t\t\t\"zoomRatio\": 1,\n" +
"\t\t\t\"showGridLines\": \"1\",\n" +
"\t\t\t\"defaultColWidth\": 72,\n" +
"\t\t\t\"defaultRowHeight\": 18,\n" +
"\t\t\t\"celldata\": [\n" +
"\t\t\t\t{\n" +
"\t\t\t\t\t\"r\": 20,\n" +
"\t\t\t\t\t\"c\": 3,\n" +
"\t\t\t\t\t\"v\": {\n" +
"\t\t\t\t\t\t\"tb\": 1,\n" +
"\t\t\t\t\t\t\"v\": \"54545\"\n" +
"\t\t\t\t\t}\n" +
"\t\t\t\t}\n" +
"\t\t\t],\n" +
"\t\t\t\"calcChain\": []\n" +
"\t\t}\n" +
"\t]\n" +
"}";
JSONObject json;
json = JSONObject.parseObject(str);
// System.out.println(str);
JSONObject jsonArray = JSONObject.parseObject(json.getString("info"));
//导入excel文件的名称
String list_name = jsonArray.getString("name");
if ((list_name != null) && (list_name.length() > 0)) {
int dot = list_name.lastIndexOf('.');
if ((dot > -1) && (dot < (list_name.length()))) {
list_name = list_name.substring(0, dot);
}
}
//String转ljsonArray,
JSONArray json_Array = JSONArray.parseArray(json.getString("sheets"));
// System.out.println(json_Array);
if (json_Array != null && json_Array.size() > 0) {
for (int j = 0; j < json_Array.size(); j++) {
JSONObject lu_json = (JSONObject) json_Array.get(j);
JSONArray luckysheet_select_save = JSONArray.parseArray(lu_json.getString("luckysheet_select_save"));
JSONObject index_json = luckysheet_select_save.getJSONObject(0);
//单个excel表格文件的index
String index = index_json.getString("sheetIndex");
//excel单元格的状态,默认选第一个状态为1
int status = 0;
if (j == 0) {
status = 1;
}
//给导入的表格一个默认的长度
List<Integer> row_list = new ArrayList<>();
JSONArray celldata_json = JSONArray.parseArray(lu_json.getString("celldata"));
//将解析的json数据保存到数据库
if (celldata_json != null && celldata_json.size() > 0) {
for (int z = 0; z < celldata_json.size(); z++) {
JSONObject cell_json = celldata_json.getJSONObject(z);
//获取excel的横向位置
String r = cell_json.getString("r");
row_list.add(Integer.valueOf(r));
//获取excel的纵向位置
String c = cell_json.getString("c");
//获取excel的值
JSONObject v_json = JSONObject.parseObject(cell_json.getString("v"));
String v = v_json.getString("v");
System.out.println(v);
}
}
}
}
}
网友评论