◄ Unity 『功能总结』►——Excel读取


一、介绍Excel格式


格式版本
xxx.xlsx>=2007以后版本
xxx.xls<=2003以前版本

二、导入DLL

新建一个folder取名Plugins 让后将你的DLL放进去就行了
1.这仨是读取Excel数据
在这里插入图片描述
2.这些是打包后需要的DLL,否则打包后无法读取
在这里插入图片描述

链接:https://pan.baidu.com/s/1viWLwlbGIeFSuC70xIOKlQ
提取码:lala

三、读取Excel


using UnityEngine;
using System.Data;
using System.IO;
using Excel;
using UnityEngine.UI;

public class finsh : MonoBehaviour
{
    private void Start()
    {
        ReadExcel(Path);
    }
    public string Path;
    public Text text;

    void ReadExcel(string Path)
    {
        string path = Application.streamingAssetsPath + Path;

        FileStream stream = File.Open(path, FileMode.Open, FileAccess.Read, FileShare.Read);
        //2003 前版本的 .xls
        //IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);
        //2007 后版本的 .xslx
        IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
        DataSet result = excelReader.AsDataSet();

        int rows = result.Tables[0].Rows.Count;
        int cols = result.Tables[0].Columns.Count;
        for (int i = 0; i < rows; i++)
        {
            for (int j = 0; j < cols; j++)
            {
                text.text += result.Tables[0].Rows[i][j].ToString() + "|";
            }
            text.text += "\n";
        }

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

臭臭~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值