Unity3D中MAC&Windows跨平台解析Excel的代码

Unity3D中,Mac下解析Excel ,这东西在Windows下有N种方法可以解析,但是在MAC上基本上都是不兼容的。。一般 Excel的格式分为两种一种是 .xls 还有一种是.xlsx ,这里我们只说.xlsx 

那么这里我就是在通过代码来解析UserLevel.xlsx了,代码比较简单我就不注释了。 这个例子我在MACWindows下都试验过都能很好的运行。喔对,这里我还引入了System.Data.dll 因为这里我使用了DataSet来遍历数据表。

01using System;

02using System.Collections.Generic;

03using System.Linq;

04using System.Text;

05using System.Text.RegularExpressions;

06using System.IO;

07using Excel;

08using System.Data;

09

10public class NewBehaviourScript : MonoBehaviour

11{

12 void Start ()

13 {

14 XLSX();

15

16 }

17

18 void XLSX()

19 {

20 FileStream stream = File.Open(Application.dataPath + "/UserLevel.xlsx", FileMode.Open, FileAccess.Read);

21 IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);

22

23 DataSet result = excelReader.AsDataSet();

24

25 int columns = result.Tables[0].Columns.Count;

26 int rows = result.Tables[0].Rows.Count;

27

28 for(int i = 0; i< rows; i++)

29 {

30 for(int j =0; j < columns; j++)

31 {

32 string nvalue = result.Tables[0].Rows[i][j].ToString();

33 Debug.Log(nvalue);

34 }

35 }

36 }

37

38}

最好不要在程序运行时去动态解析这个Excel 。我的做法是把利用这个类库把Excel里面的数据读取出来,然后自己用File在去把数据写在别的文件中,方面以后加密拓展等等。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值