unity中必须要有Plugins文件夹以及dll文件
官方dll文件下载链接: https://archive.codeplex.com/?p=exceldatareader
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Excel;
using System.IO;
using System.Data;
using OfficeOpenXml; public class Exc_GenXin : MonoBehaviour {
private string DpanMain = "D:/anchor/main.xlsx";//D盘main表格
private string AsstPath;//streaamingAssets文件里面的文件
public static List<DepenceTableDataTwo> DepenceTableDataList = new List<DepenceTableDataTwo>();//创建列表
private void Awake()
{
AsstPath = Application.streamingAssetsPath + "/main.xlsx";
}
private void OnEnable()
{
if (File.Exists(DpanMain))
{
DepenceTableDataList = ReadLoad(DpanMain);
WriteExcel(AsstPath);
Debug.Log("更新成功");
}
} // Use this for initialization
void Start () { }
public void AANniu()
{ }
public struct DepenceTableDataTwo
{
public string itemNumber;//标号
public string topicType;//类型
public string topic;//题目
public string optionA;//A
public string optionB;//B
public string optionC;//C
public string optionD;//D
public string answer;//答案
}
/// <summary>
/// 读取表格
/// </summary>
/// <param name="path">路径</param>
/// <returns></returns>
public static DataSet ReadExcel(string path)
{
FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet result = excelReader.AsDataSet(); return result; }
public static List <DepenceTableDataTwo> ReadLoad(string path)
{
List<DepenceTableDataTwo> _data = new List<DepenceTableDataTwo>();
DataSet resultds = ReadExcel(path);
int rows = resultds.Tables[].Rows.Count;//行
int colums = resultds.Tables[].Columns.Count;//列
for (int i = ; i < rows; i++)
{
DepenceTableDataTwo dependData;
dependData.itemNumber = resultds.Tables[].Rows[i][].ToString();
dependData.topicType = resultds.Tables[].Rows[i][].ToString();
dependData.topic = resultds.Tables[].Rows[i][].ToString();
if (dependData.topicType =="选择")
{
dependData.optionA = resultds.Tables[].Rows[i][].ToString();
dependData.optionB = resultds.Tables[].Rows[i][].ToString();
dependData.optionC = resultds.Tables[].Rows[i][].ToString();
dependData.optionD = resultds.Tables[].Rows[i][].ToString();
dependData.answer = resultds.Tables[].Rows[i][].ToString();
}
else
{
dependData.optionA = string.Empty;
dependData.optionB = string.Empty;
dependData.optionC = string.Empty;
dependData.optionD = string.Empty;
dependData.answer = resultds.Tables[].Rows[i][].ToString();
}
_data.Add(dependData);
}
return _data;
}
/// <summary>
/// 写入表格
/// </summary>
/// <param name="path">路径</param>
public static void WriteExcel(string outpath)
{
FileInfo newFile = new FileInfo(outpath);
if (newFile .Exists )
{
newFile.Delete();
newFile = new FileInfo(outpath);
}
using (ExcelPackage package=new ExcelPackage(newFile))
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet1");
for (int i = ; i < DepenceTableDataList.Count; i++)
{
worksheet.Cells[i + , ].Value = DepenceTableDataList[i].itemNumber.ToString ();
worksheet.Cells[i + , ].Value = DepenceTableDataList[i].topicType.ToString ();
worksheet.Cells[i + , ].Value = DepenceTableDataList[i].topic.ToString ();
if (DepenceTableDataList[i].topicType == "选择")
{
worksheet.Cells[i + , ].Value = DepenceTableDataList[i].optionA .ToString();
worksheet.Cells[i + , ].Value = DepenceTableDataList[i].optionB .ToString();
worksheet.Cells[i + , ].Value = DepenceTableDataList[i].optionC .ToString();
worksheet.Cells[i + , ].Value = DepenceTableDataList[i].optionD .ToString();
worksheet.Cells[i + , ].Value = DepenceTableDataList[i].answer .ToString();
}
else
{
worksheet.Cells[i + , ].Value = DepenceTableDataList[i].answer.ToString();
}
}
package.Save();
}
}
}

下面附上自己做的Demo地址,不是很完善,但里面也没有错误,大佬们不要介意,感谢!

这是链接:

链接:https://pan.baidu.com/s/1CPLIVsvMzWUknQAi0Ekgjg
提取码:bkod
复制这段内容后打开百度网盘手机App,操作更方便哦

 

从外面更新unity需要用的题库的更多相关文章

  1. 更新 | 2019年9月计算机二级office模拟题库

    随着2019年上半年计算机二级考试的完美落幕,紧接着的便是9月份的考试了. 到目前为止,下半年9月份计算机二级考试报名开通时间在6月前后,现在也基本结束. 2019年9月(56次)全国计算机等级考试( ...

  2. Android实训案例(九)——答题系统的思绪,自己设计一个题库的体验,一个思路清晰的答题软件制作过程

    Android实训案例(九)--答题系统的思绪,自己设计一个题库的体验,一个思路清晰的答题软件制作过程 项目也是偷师的,决心研究一下数据库.所以写的还是很详细的,各位看官,耐着性子看完,实现结果不重要 ...

  3. 猿题库 iOS 客户端架构设计

    原文: http://mp.weixin.qq.com/s?__biz=MjM5NTIyNTUyMQ==&mid=444322139&idx=1&sn=c7bef4d439f4 ...

  4. 猿题库 iOS 客户端架构设计-唐巧

    序 猿题库是一个拥有数千万用户的创业公司,从20013年题库项目起步到2015年,团队保持了极高的生产效率,使我们的产品完成了五个大版本和数十个小版本的高速迭代. 在如此快速的开发过程中,如何保证代码 ...

  5. Hibernate考试试题(部分题库)含答案

    Hibernate考试试题 (题库) 1.  在Hibernate中,下列说法正确的有( ABC ).[选三项] A.Hibernate是一个开放源代码的对象关系映射框架 B.Hibernate对JD ...

  6. Ocr答题辅助神器 OcrAnswerer4.x,通过百度OCR识别手机文字,支持屏幕窗口截图和ADB安卓截图,支持四十个直播App,可保存题库

    http://www.cnblogs.com/Charltsing/p/OcrAnswerer.html 联系qq:564955427 最新版为v4.1版,开放一定概率的八窗口体验功能,请截图体验(多 ...

  7. 小学生噩梦——四则运算题库(python 全功能实现)

    Github: https://github.com/holidaysss 小组:龙天尧(代码实现),林毓植(浮点转分数函数,代码审查) PSP2.1 Personal Software Proces ...

  8. Linux题库练习

    转一个Linux的题库供自己学习使用(滑稽) 转自:http://www.linuxdiyf.com/view_202485.html 选择题1 在终端下输入mount -a命令的作用是:CA 强制进 ...

  9. 猿题库 iOS 客户端架构设计(原文地址:http://gracelancy.com/blog/2016/01/06/ape-ios-arch-design/)

    猿题库 iOS 客户端架构设计 序 猿题库是一个拥有数千万用户的创业公司,从2013年题库项目起步到2015年,团队保持了极高的生产效率,使我们的产品完成了五个大版本和数十个小版本的高速迭代.在如此快 ...

随机推荐

  1. xml转换为json格式时,如何将指定节点转换成数组 Json.NET

    使用Json.NET转换xml成json时,如果xml只有单个节点,但json要求是数组形式[], JsonConvert.SerializeXmlNode 并不能自动识别 示例如下: RecordA ...

  2. JavaScript数据类型检测 数组(Array)检测方式

    前言 对于确定某个对象是不是数组,一直是数组的一个经典问题.本文专门将该问题择出来,介绍什么才是正确的javascript数组检测方式 typeof 首先,使用最常用的类型检测工具--typeof运算 ...

  3. MDK调试无法进入main()函数

    今天在用MDK调试stm32时出现了无法进入main函数,进入startup文件的情况. 在网上查找资料时发现,MDK调试设置断点最多只能设置5个.在减少断点后,调试果然能够正常进入main()函数了 ...

  4. ASP.NET后台调用API方法

    /// <summary> /// 调用API POST请求与获取结果 /// </summary> ///URL 与 JSON串 public static string H ...

  5. BCM芯片FP原理及相关SDK数据结构介绍

    BCM芯片有几个大的模块: VLAN.L2.L3和FP等几个,其中FP的使用也最为灵活,能解析匹配数据包文的前128字节比特级的内容,动作包括转发.丢弃.结合qos修改相应字段.分配vid.流镜像.流 ...

  6. C#decimal四舍五入格式化

    Console.WriteLine(string.Format("{0:####}", 594884.539)); Console.WriteLine(string.Format( ...

  7. 【尚学堂·Hadoop学习】MapReduce案例2--好友推荐

    案例描述 根据好友列表,推荐好友的好友 数据集 tom hello hadoop cat world hadoop hello hive cat tom hive mr hive hello hive ...

  8. 初识Asp.Net WebApi

    using System;using System.Collections.Generic;using System.Linq;using System.Net.Http;using System.T ...

  9. java操作mongodb & springboot整合mongodb

    简单的研究原生API操作MongoDB以及封装的工具类操作,最后也会研究整合spring之后作为dao层的完整的操作. 1.原生的API操作 pom.xml <!-- https://mvnre ...

  10. git本机服务器配置(一):git的安装

    1. 下载git的Windows版本 https://gitforwindows.org/ 2. 安装 点击next 不需要更改,直接点击next 配置git编辑器,我安装了notepad++所以就选 ...