Unity-超级方便的Excel 读写插件

发布于:2024-04-14 ⋅ 阅读:(179) ⋅ 点赞:(0)

🌭功能介绍

💡.Excel 行数据转对象:把导入的Excel 每一行数据进行自动映射,最终获得数据集合。
💡. 对象转 Excel 行数据:把集合中的每个对象转换成Excel中的行数据,每个字段对应一个单元格。
💡.支持读取基础数据类型:int、float、string、bool,其他的类型可以扩展。
💡.传送门👈

🍕 Demo

🌳准备一个数据类

[System.Serializable]
public class TestRowClass {
    [ExcelColumn(1)]
    public string stringField;
    [ExcelColumn(2)]
    public int intField;

    [SerializeField]
    private float _floatProperty;
    [ExcelColumn(3)]
    public float FloatProperty {
        get { 
            return _floatProperty;
        }
        set
        {
            _floatProperty = value;
        }
    }

    [SerializeField]
    private bool _boolProperty;
    [ExcelColumn(4)]
    public bool BoolProperty {
        get {
            return _boolProperty;
        }
        set
        {
            _boolProperty = value;
        }
    }
}

💡.该类用来映射Excel表格,[ExcelColumn(1)] 表示字段或属性对应的Excel列数

🌳准备一个Excel

在这里插入图片描述
在这里插入图片描述

🌳导入Excel

this.ImportExcel(callback: excel => {

});

🌳行数据自动转换

this.rowDatas=excel.ExcelRowData2Obj<TestRowClass>(beginRow:2);

从第二行开始进行转换

🌳导出到Excel

this.rowDatas.Export2Excel();

🍱新增映射字段类型

当被标记的字段或属性类型没有对应的转换器时会有报错提示:
在这里插入图片描述

在文件夹:Assets/ZYF/Tools/Excel/RowData2Obj/FieldConverters 内新增转换类即可。


网站公告

今日签到

点亮在社区的每一天
去签到