您当前的位置: 首页 >  unity
  • 5浏览

    0关注

    193博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

Unity使用Excel.dll对Excel读取,使用EPPlus实现对Excel写入

我寄人间雪满头丶 发布时间:2019-12-25 14:49:34 ,浏览量:5

前言

读写excel是游戏开发中经常用到的技术,程序可以使用策划、文案写好的excel对数据进行修改,达到简易配合的目的。今天记录一下对Excel的读写过程。

准备

下图是所需类库。Excel.dll、EPPlus.dll、ICSharpCode.SharpZLib.dll在网上可以搜到。 备注: 1.你的unity版本是多少,去对应的安装目录中取dll 2.System.Data.dll 在D:\Program Files\Unity2017.2\Editor\Data\Mono\lib\mono\2.0 3.I18N开头的dll 在 D:\Program Files\Unity2017.2\Editor\Data\Mono\lib\mono\unity 所需类库

1.读取excel

需要注意读取excel默认第一行第一列是索引0开始,写入是索引1开始。另外要using System.Data使用DataSet储存excel数据。这里0表示第一个sheet, 如果你有多个sheet的话,可以写sheet的名字,例如result.Tables[“mySheet”].Rows.Count

代码示例:

		FileStream stream = File.Open(Application.dataPath + "/Excels/鬼船新攻略文字.xlsx", FileMode.Open, FileAccess.Read); //读取文件流
        IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); //读取Excel
        DataSet result = excelReader.AsDataSet(); //储存数据
        //int columns = result.Tables[0].Columns.Count; //列数 0开始
        int rows = result.Tables[0].Rows.Count; //行数
        //验证数据长度是否匹配 这个根据具体项目取舍
        if(rows != TipsInfoController.instance.allTips.Count)
        {
            Debug.LogError("数据长度不匹配!加载失败!");
            return;
        }
        for (int i = 0; i             
关注
打赏
1648518768
查看更多评论
0.2037s