上代码

using Excel;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.IO;
using UnityEngine;public class ExcelLogicManager : MonoBehaviour
{public static string ExcelName = "UserLevel.xlsx";public static string LogicExcelName = "逻辑表.xls";public static string[] sheetNames = { "sheet1", "sheet2", "sheet3" };public static List<DeviceData> DeviceDataList = new List<DeviceData>();void Start () {XLS("");//XLS("/逻辑表.xls");// SelectDeviceDataTableXLS("/逻辑表.xls");
    }/// <summary>/// 解析Excel表/// </summary>void XLSX(){FileStream stream = File.Open(Application.dataPath + "/Excel" + "/UserLevel.xlsx", FileMode.Open, FileAccess.Read);IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);DataSet result = excelReader.AsDataSet();int columns = result.Tables[0].Columns.Count;int rows = result.Tables[0].Rows.Count;for (int i = 0; i < rows; i++){//for (int j = 0; j < columns; j++)//{//    string nvalue = result.Tables[0].Rows[i][j].ToString();//    Debug.Log(nvalue);//}
        }}void XLS(string XlsPath){FileStream stream = File.Open(Application.dataPath + "/Excel" + "/逻辑表.xls", FileMode.Open, FileAccess.Read);// FileStream stream = File.Open(Application.dataPath + "/Excel" + XlsPath, FileMode.Open, FileAccess.Read);IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);DataSet result = excelReader.AsDataSet();int columns = result.Tables[0].Columns.Count;int rows = result.Tables[0].Rows.Count;for (int i = 1; i < rows; i++){DeviceData deviceData = new DeviceData();deviceData.ID = Int32.Parse(result.Tables[0].Rows[i][0].ToString());deviceData.DevName = result.Tables[0].Rows[i][1].ToString();deviceData.OutLogic = result.Tables[0].Rows[i][2].ToString();deviceData.RecvDelay = result.Tables[0].Rows[i][3].ToString();deviceData.LoseDelay = result.Tables[0].Rows[i][4].ToString();deviceData.InValue = result.Tables[0].Rows[i][5].ToString();deviceData.Notes = result.Tables[0].Rows[i][6].ToString();deviceData.NoteDescription = result.Tables[0].Rows[i][8].ToString();DeviceDataList.Add(deviceData);}Debug.Log(DeviceDataList.Count);//for (int i = 0; i < rows; i++)//{//    for (int j = 0; j < columns; j++)//    {//        string nvalue = result.Tables[0].Rows[i][j].ToString();//        Debug.Log(nvalue);//    }//}
    }public static List<DeviceData> SelectDeviceDataTable(string xmlPath, int tableIndex){List<DeviceData> DeviceDataList = new List<DeviceData>();FileStream stream = File.Open(xmlPath, FileMode.Open, FileAccess.ReadWrite);IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);DataSet result = excelReader.AsDataSet();int rows = result.Tables[tableIndex].Rows.Count;for (int i = 0; i < rows; i++){DeviceData deviceData = new DeviceData();deviceData.ID = Int32.Parse(result.Tables[0].Rows[i][0].ToString());deviceData.DevName = result.Tables[0].Rows[i][1].ToString();deviceData.OutLogic = result.Tables[0].Rows[i][2].ToString();deviceData.RecvDelay = result.Tables[0].Rows[i][3].ToString();deviceData.LoseDelay = result.Tables[0].Rows[i][4].ToString();deviceData.InValue = result.Tables[0].Rows[i][5].ToString();deviceData.Notes= result.Tables[0].Rows[i][6].ToString();deviceData.NoteDescription = result.Tables[0].Rows[i][8].ToString();DeviceDataList.Add(deviceData);}return DeviceDataList;}public static List<DeviceData> SelectDeviceDataTableXLS(string XlsPath){List<DeviceData> DeviceDataList = new List<DeviceData>();FileStream stream = File.Open(Application.dataPath + "/Excel" + XlsPath, FileMode.Open, FileAccess.Read);IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);DataSet result = excelReader.AsDataSet();int rows = result.Tables[0].Rows.Count;for (int i = 1; i < rows; i++){DeviceData deviceData = new DeviceData();deviceData.ID = Int32.Parse(result.Tables[0].Rows[i][0].ToString());deviceData.DevName = result.Tables[0].Rows[i][1].ToString();deviceData.OutLogic = result.Tables[0].Rows[i][2].ToString();deviceData.RecvDelay = result.Tables[0].Rows[i][3].ToString();deviceData.LoseDelay = result.Tables[0].Rows[i][4].ToString();deviceData.InValue = result.Tables[0].Rows[i][5].ToString();deviceData.Notes = result.Tables[0].Rows[i][6].ToString();deviceData.NoteDescription = result.Tables[0].Rows[i][8].ToString();DeviceDataList.Add(deviceData);}Debug.Log(DeviceDataList.Count);return DeviceDataList;}}public class DeviceData
{private int m_ID;public int ID{get { return m_ID; }set { m_ID = value; }}private string m_DevName;public string DevName{get { return m_DevName; }set { m_DevName = value; }}private string m_OutLogic;public string OutLogic{get { return m_OutLogic; }set { m_OutLogic = value; }}private string m_RecvDelay;public string RecvDelay{get { return m_RecvDelay; }set { m_RecvDelay = value; }}private string m_LoseDelay;public string LoseDelay{get { return m_LoseDelay; }set { m_LoseDelay = value; }}private string m_InValue;public string InValue{get { return m_InValue; }set { m_InValue = value; }}private string m_Notes;public string Notes{get { return m_Notes; }set { m_Notes = value; }}private string m_NoteDescription;public string NoteDescription{get { return m_NoteDescription; }set { m_NoteDescription = value; }}
}

打包后,发现Excel没有被读取,原因如下:在Asste文件下Excel发布时没有打包到发布文件中(也就是.EXE),修改方法如下
在Project视图中--创建StreamingAssets文件夹,将Excel文件放在该文件夹下,(具体关于StreamingAssets文件夹的一些内容网上可以搜)---修改读取Excel的路径方法,将

File.Open(Application.dataPath + "/Excel" + XlsPath, FileMode.Open, FileAccess.Read);

改成

File.Open(Application.streamingAssetsPath+ "/Excel" + XlsPath, FileMode.Open, FileAccess.Read); 即可

转载于:https://www.cnblogs.com/nanyang0310/p/9068189.html

unity中解析excel表相关推荐

  1. 在Unity中使用Excel表开发单选题和多选题

    前言: 去年还是小菜鸡的我写过在Unity中单选题和多选题的开发.现在进步一点点,这次可以直接编辑表格,在表格中增删改查数据即可,无需再对代码进行更改! 下载链接在文章末尾,需要的可以直接划到最后! ...

  2. 【Unity】解析Excel数据,并自动创建对应的C#类

    升级版传送门: [Unity]升级版·Excel数据解析,自动创建对应C#类,自动创建ScriptableObject生成类,自动序列化Asset文件_萧然CS的博客-CSDN博客Excel注释操作: ...

  3. python 解析excel表并排重输出到txt

    需求 解析excel表中每个单元格的元素,并且排重后输出到txt文件中,保存格式为UTF-8 程序 pip install xlrd import xlrd# 保存唯一字符的列表 convert_li ...

  4. 【springboot】上传并解析excel表,使用postman测试上传文件,解决excel版本报错问题

    声明:博客代码只是实际项目的一部分,项目是前后端分离的,这篇博客中将记录如何使用工具类中提供的解析excel表格数据,并使用postman测试上传excel表的接口. 在项目pom.xml文件中添加依 ...

  5. vba mysql·教程_Excel VBA ADO SQL入门教程004:SQL中的Excel表

    1. 上期我们聊了SQL常用查询语句中的字段查询,其简化版语法如下: SELECT 字段名 FROM 表名 当时我们说,FROM关键词指明了要获取字段信息的表的名称.倘若数据源是Excel表格,则需要 ...

  6. [Java中实现Excel表导入导出]基于easy-poi和EasyExcel两种方式实现

    第一种:基于easy-poi实现Excel导入导出 1.导出Excel表格 第一步:在pom文件中导入依赖 <!--基于easy-poi实现Excel导入导出--><dependen ...

  7. jsp后台批量导入excel表格数据到mysql中_运用java解析excel表,拿到表中的数据并批量插入数据库...

    首先,本文是运用jxl进行excel表的解析,所以我们需要先下载一个jxl.jar的jar包: 并且需要一个与excel表对应的实体类,用于接收excel的数据: 然后就是代码部分,我们先编写一个函数 ...

  8. django项目中实现excel表数据导入

    依赖模块: xlrd模块安装:pip install xlrd 安装好xlrd模块之后基本的准备工作就已经完成. 实现: views.py: def import_excel(self, reques ...

  9. XX健康:预约管理-预约设置日历插件文件简单下载Excel文件解析Excel表数据批量导入

    1. 需求分析 前面我们已经完成了检查项管理.检查组管理.套餐管理等.接下来我们需要进行预约设置,其实就是设置每一天的体检预约最大数量.客户可以通过微信端在线预约,在线预约时需要选择体检的时间,如果客 ...

最新文章

  1. java linkedlist底层_手写Java LinkedList核心源码
  2. pdf百度云下载 python编程 从数据分析到数据科学_python零基础入门教程,不同方向的,这很重要...
  3. Java操作Hbase进行建表、删表以及对数据进行增删改查,条件查询
  4. Java 将中缀表达式转换成后缀表达式
  5. 思科路由器与windows建立L2L ipsec×××
  6. 开源社交系统ThinkSNS——社交与电商的结合
  7. 一个服务器启动2套mysql_一个服务器启动两个mysql实例
  8. Java hibernate假外键_浅谈hibernate急迫加载问题(多重外键关联)
  9. windows bat脚本实现快速配置JDK 环境变量
  10. lpx寒假作业案例7
  11. 怎样找计算机物理地址,怎么查询电脑物理地址
  12. Nature报道诺奖得主:给研究生的四条箴言 Four golden lessons。颜宁:写的真好!
  13. java ctor_vue-test-utils设置获取TypeError:无法在字符串上创建属性'_Ctor'
  14. 基于知识图谱的智能问答机器人
  15. SaaS的中国版图,SaaS的中国问题
  16. 饼图指北(Pie Chart)
  17. 火车头采集细节(一)
  18. iOS系统字体如何使用
  19. 案例:京东登录页面css创建
  20. 考研英语词汇文章4-Freshman Year

热门文章

  1. ASP.NET 2.0 中的资源与本地化
  2. 解决@vue/cli 创建项目是安装chromedriver时失败的问题
  3. 原 layer父子页面交互
  4. ckeditor的使用实例
  5. 多进程Socket_Client
  6. 采用个hook技术对writefile函数进行拦截(2)
  7. maven web项目不能创建src/main/java等文件夹的问题
  8. java 随机数 【指定范围】
  9. Open suse下 vi 语法加亮设置 显示
  10. 不可多得的Javascript(AJAX)开发工具 - Aptana