Excel导表工具(开源)

虚幻大学 xuhss 372℃ 0评论

? 优质资源分享 ?

学习路线指引(点击解锁) 知识定位 人群定位
? Python实战微信订餐小程序 ? 进阶级 本课程是python flask+微信小程序的完美结合,从项目搭建到腾讯云部署上线,打造一个全栈订餐系统。
?Python量化交易实战? 入门级 手把手带你打造一个易扩展、更安全、效率更高的量化交易系统

功能

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-0rt8pgy2-1654017895204)(https://camo.githubusercontent.com/c37d2f366bf5470e234f597e0f0e97ab69c23ccc24c4d98da82485f5ef826ec2/68747470733a2f2f67697465652e636f6d2f736d616c6c2d706572696c6c612f7069632d676f2f7261772f6d61737465722f696d6167652d32303232303533313134343835333433302e706e67)]

  • 支持int、float、bool、string基础类型
  • 支持数组
  • 支持kv
  • 支持枚举
  • 支持unity类型vector3,vector2,color
  • 自动生成csharp类
  • 单个excel中多个sheet,依次导出

使用

  1. 设置config.txt文件,按需求配置;

为注释行必须;结尾

#excel存放路径;
excelPath:./Excel/;
#数据保存路径;
dataPath:./DataTable/;
#c#类保存路径;
classPath:./CSharp/;
#输出类型;
exportType:Json;
isExportServer:False
  1. 双击运行DataTable.exe,等待执行完毕;

配表

  • 第一行注释
  • 第二行字段类型
  • 第三行变量名(属性名)
  • 第一列留空
  • 数组:类型+[] e.g: int[]
  • kv使用

类型:dic

变量名:变量名+:+key值

e.g:

dic dic dic
Attribute:atk Attribute:def Attribute:spd
  • 枚举:自动生成的枚举类型从1开始,Enum类型为:Enum+变量名字段;

Json序列化

使用json库需要对Vector3等Unity字段魔改;

Litjson库魔改:将自定义类型注册进json库;

namespace LitJson.Extensions
{
    public static class JsonExtensions
 {

        public static void WriteProperty(this JsonWriter w, string name, long value)
        {
            w.WritePropertyName(name);
            w.Write(value);
        }

        public static void WriteProperty(this JsonWriter w, string name, string value)
        {
            w.WritePropertyName(name);
            w.Write(value);
        }

        public static void WriteProperty(this JsonWriter w, string name, bool value)
        {
            w.WritePropertyName(name);
            w.Write(value);
        }

        public static void WriteProperty(this JsonWriter w, string name, double value)
        {
            w.WritePropertyName(name);
            w.Write(value);
        }

    }
}

 using UnityEngine;
 using System;
 using System.Collections;

 using LitJson.Extensions;

 namespace LitJson
 {

#if UNITY\_EDITOR
     [UnityEditor.InitializeOnLoad]
#endif
     /// 
     /// Unity内建类型拓展
     /// 
     public static class UnityTypeBindings
 {

         static bool registerd;

         static UnityTypeBindings()
         {
             Register();
         }

         public static void Register()
         {

             if (registerd) return;
             registerd = true;

             // 注册Type类型的Exporter
             JsonMapper.RegisterExporter((v, w) => { w.Write(v.FullName); });

 JsonMapper.RegisterImporter<string, Type>((s) => { return Type.GetType(s); });

 // 注册Vector2类型的Exporter
 Action writeVector2 = (v, w) =>
 {
 w.WriteObjectStart();
 w.WriteProperty("x", v.x);
 w.WriteProperty("y", v.y);
 w.WriteObjectEnd();
 };

 JsonMapper.RegisterExporter((v, w) => { writeVector2(v, w); });

 // 注册Vector3类型的Exporter
 Action writeVector3 = (v, w) =>
 {
 w.WriteObjectStart();
 w.WriteProperty("x", v.x);
 w.WriteProperty("y", v.y);
 w.WriteProperty("z", v.z);
 w.WriteObjectEnd();
 };

 JsonMapper.RegisterExporter((v, w) => { writeVector3(v, w); });

 // 注册Vector4类型的Exporter
 JsonMapper.RegisterExporter((v, w) =>
 {
 w.WriteObjectStart();
 w.WriteProperty("x", v.x);
 w.WriteProperty("y", v.y);
 w.WriteProperty("z", v.z);
 w.WriteProperty("w", v.w);
 w.WriteObjectEnd();
 });

 // 注册Quaternion类型的Exporter
 JsonMapper.RegisterExporter((v, w) =>
 {
 w.WriteObjectStart();
 w.WriteProperty("x", v.x);
 w.WriteProperty("y", v.y);
 w.WriteProperty("z", v.z);
 w.WriteProperty("w", v.w);
 w.WriteObjectEnd();
 });

 // 注册Color类型的Exporter
 JsonMapper.RegisterExporter((v, w) =>
 {
 w.WriteObjectStart();
 w.WriteProperty("r", v.r);
 w.WriteProperty("g", v.g);
 w.WriteProperty("b", v.b);
 w.WriteProperty("a", v.a);
 w.WriteObjectEnd();
 });

 // 注册Color32类型的Exporter
 JsonMapper.RegisterExporter((v, w) =>
 {
 w.WriteObjectStart();
 w.WriteProperty("r", v.r);
 w.WriteProperty("g", v.g);
 w.WriteProperty("b", v.b);
 w.WriteProperty("a", v.a);
 w.WriteObjectEnd();
 });

 // 注册Bounds类型的Exporter
 JsonMapper.RegisterExporter((v, w) =>
 {
 w.WriteObjectStart();

 w.WritePropertyName("center");
 writeVector3(v.center, w);

 w.WritePropertyName("size");
 writeVector3(v.size, w);

 w.WriteObjectEnd();
 });

 // 注册Rect类型的Exporter
 JsonMapper.RegisterExporter((v, w) =>
 {
 w.WriteObjectStart();
 w.WriteProperty("x", v.x);
 w.WriteProperty("y", v.y);
 w.WriteProperty("width", v.width);
 w.WriteProperty("height", v.height);
 w.WriteObjectEnd();
 });

 // 注册RectOffset类型的Exporter
 JsonMapper.RegisterExporter((v, w) =>
 {
 w.WriteObjectStart();
 w.WriteProperty("top", v.top);
 w.WriteProperty("left", v.left);
 w.WriteProperty("bottom", v.bottom);
 w.WriteProperty("right", v.right);
 w.WriteObjectEnd();
 });

 }

 }
 }

后续计划加入protobuf和bytes导出;

计划可导出.go文件;

相比其他导表工具,优势就是简单使用,不用看长长的文档;

有bug或修改建议欢迎交流;

开源地址:https://github.com/Rebort1012/DataTable.git

个人博客:perilla.work

转载请注明:xuhss » Excel导表工具(开源)

喜欢 (0)

您必须 登录 才能发表评论!