Unity WebGL下读取Excel

使用FlexReader插件,可以在webgl下读取Excel中的数据

using System.Collections;
using FlexFramework.Excel;
using UnityEngine;
using UnityEngine.Networking;

public class ReadXlsx : MonoBehaviour
{
    void Start()
    {
        StartCoroutine(IELoadXlsx());
    }

    IEnumerator IELoadXlsx()
    {
        string path = Application.streamingAssetsPath + "/Data.xlsx";
        yield return null;
        using (UnityWebRequest webRequest = UnityWebRequest.Get(path))
        {
            yield return webRequest.SendWebRequest();
            Debug.Log("Code:" + webRequest.responseCode);
            if (webRequest.responseCode == 200)
            {
                WorkBook book = new WorkBook(webRequest.downloadHandler.data);

                for (int i = 0; i < book[0].Rows.Count; i++)
                {
                    for (int j = 0; j < book[0].Rows[i].Cells.Count; j++)
                    {
                        Debug.Log("数据:" + book[0].Rows[i].Cells[j].Text);
                    }
                }
            }
        }
    }
}

运行结果

在这里插入图片描述

一定要添加这3个dll

在这里插入图片描述
传送门-源码 附带插件有需要的可以看下

猜你喜欢

转载自blog.csdn.net/D_kkkk/article/details/130324841