|
| 1 | + |
| 2 | +import java.io.BufferedWriter; |
| 3 | +import java.io.File; |
| 4 | +import java.io.FileInputStream; |
| 5 | +import java.io.FileWriter; |
| 6 | +import org.json.JSONArray; |
| 7 | +import org.json.JSONObject; |
| 8 | + |
| 9 | +public class test { |
| 10 | + static File outPath=new File("sdcard/out"); |
| 11 | + public static void main(String[] args) throws Exception { |
| 12 | + outPath.mkdirs(); |
| 13 | + outfromdata(); |
| 14 | + System.out.println(); |
| 15 | + } |
| 16 | + /* |
| 17 | + https://products.aspose.app/cells/zh/conversion/xlsx-to-json |
| 18 | + NDT-1.15.json xlxs2json |
| 19 | + */ |
| 20 | + public static void outfromdata() throws Exception { |
| 21 | + JSONObject js=pare(new File("sdcard/a")); |
| 22 | + BufferedWriter index=new BufferedWriter(new FileWriter(new File(outPath, "index.md"))); |
| 23 | + index.write("# index"); |
| 24 | + JSONArray list= js.getJSONArray("单位代码"); |
| 25 | + BufferedWriter buff=null; |
| 26 | + for (int i=0;i < list.length();++i) { |
| 27 | + JSONObject obj=list.optJSONObject(i); |
| 28 | + if (obj == null) { |
| 29 | + if (buff != null) { |
| 30 | + buff.close(); |
| 31 | + buff = null; |
| 32 | + } |
| 33 | + continue; |
| 34 | + } |
| 35 | + String str=obj.optString("key翻译"); |
| 36 | + if (str == null)continue; |
| 37 | + String key=obj.optString("key描述解释"); |
| 38 | + boolean isSection=key == null ?false: key.startsWith("[") && key.endsWith("]"); |
| 39 | + if (isSection || str.matches("[a-zA-Z]{2,}")) { |
| 40 | + if (buff != null)buff.close(); |
| 41 | + if (isSection) { |
| 42 | + int j=key.indexOf('_'); |
| 43 | + if (j < 0)j = key.length() - 1; |
| 44 | + str = key.substring(1, j); |
| 45 | + } |
| 46 | + if ("comment".equals(str)) { |
| 47 | + continue; |
| 48 | + } |
| 49 | + index.write("\n## ["); |
| 50 | + char c=str.charAt(0); |
| 51 | + if (c >= 'A' && c <= 'Z') { |
| 52 | + char[] crr=str.toCharArray(); |
| 53 | + crr[0]=Character.toLowerCase(c); |
| 54 | + str = new String(crr); |
| 55 | + } |
| 56 | + index.write(str.equals("leg") ?"leg/arm": str.equals("global") ?"global_resource": str); |
| 57 | + index.write("]("); |
| 58 | + index.write(str); |
| 59 | + index.write(".md"); |
| 60 | + index.write(")\n"); |
| 61 | + index.write(obj.optString("key代码")); |
| 62 | + buff = new BufferedWriter(new FileWriter(new File(outPath, str + ".md"))); |
| 63 | + buff.write("# "); |
| 64 | + buff.write(str); |
| 65 | + buff.write("\n"); |
| 66 | + } else if (buff != null) { |
| 67 | + key = obj.optString("key代码"); |
| 68 | + if (key == null || key.length() == 0)continue; |
| 69 | + char c=key.charAt(0); |
| 70 | + if (Character.isLowerCase(c) || Character.isUpperCase(c) || c == '@') { |
| 71 | + buff.write("## "); |
| 72 | + buff.write(key); |
| 73 | + buff.write("\ntranslation:"); |
| 74 | + buff.write(str.replaceFirst(":$", "")); |
| 75 | + buff.write("\n<br>type:"); |
| 76 | + String type=obj.optString("key值类型", "string"); |
| 77 | + buff.write(type); |
| 78 | + String type2=obj.optString("Column8"); |
| 79 | + if (type2 != null && type2.length() > 0) { |
| 80 | + if (!type.equals(type2)) { |
| 81 | + buff.write('/'); |
| 82 | + buff.write(type2); |
| 83 | + } |
| 84 | + } |
| 85 | + str = obj.optString("key描述解释"); |
| 86 | + if (str != null) { |
| 87 | + buff.write("\n<br>"); |
| 88 | + buff.write(str); |
| 89 | + } |
| 90 | + buff.write('\n'); |
| 91 | + } |
| 92 | + } |
| 93 | + } |
| 94 | + if (buff != null) |
| 95 | + buff.close(); |
| 96 | + index.close(); |
| 97 | + } |
| 98 | + public static JSONObject pare(File f) throws Exception { |
| 99 | + FileInputStream fi=new FileInputStream(f); |
| 100 | + byte[] by=new byte[fi.available()]; |
| 101 | + fi.read(by); |
| 102 | + return new JSONObject(new String(by)); |
| 103 | + } |
| 104 | +} |
| 105 | + |
0 commit comments