信息发布→ 登录 注册 退出

unity3d:windows读写excel,打包exe可用

发布时间:2025-07-09

点击量:

首先要注意的点: 1.你的unity版本是多少,去对应的安装目录中取dll 2.system.data.dll 在d:\program files\unity2017.2\editor\data\mono\lib\mono\2.0 3.i18n开头的dll 在 d:\program files\unity2017.2\editor\data\mono\lib\mono\unity

4.2017.2版本demo工程(包含其他所需要的excel相关dll) 下载 https://pan.baidu.com/s/1equ8Mdzwu9ztsPJMUWp1Sw

读excel

代码语言:javascript代码运行次数:0运行复制
using System.Collections;using System.Collections.Generic;using UnityEngine;using System.Data;using System.IO;using Excel;public class DoExcel {    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();        excelReader.Close();        return result;    }    public static List Load(string path)    {        List _data = new List();        DataSet resultds = ReadExcel(path);        int column = resultds.Tables[0].Columns.Count;        int row = resultds.Tables[0].Rows.Count;        Debug.LogWarning(column + "  " + row);        for(int i=1;i

写excel

代码语言:javascript代码运行次数:0运行复制
public static void WriteExcel(string outputDir)    {        //string outputDir = EditorUtility.SaveFilePanel("Save Excel", "", "New Resource", "xlsx");        FileInfo newFile = new FileInfo(outputDir);        if (newFile.Exists)        {            newFile.Delete();  // ensures we create a new workbook            newFile = new FileInfo(outputDir);        }        using (ExcelPackage package = new ExcelPackage(newFile))        {            // add a new worksheet to the empty workbook            ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet1");            //Add the headers            worksheet.Cells[1, 1].Value = "ID";            worksheet.Cells[1, 2].Value = "Product";            worksheet.Cells[1, 3].Value = "Quantity";            worksheet.Cells[1, 4].Value = "Price";            worksheet.Cells[1, 5].Value = "Value";            //Add some items...            worksheet.Cells["A2"].Value = 12001;            worksheet.Cells["B2"].Value = "Nails";            worksheet.Cells["C2"].Value = 37;            worksheet.Cells["D2"].Value = 3.99;            worksheet.Cells["A3"].Value = 12002;            worksheet.Cells["B3"].Value = "Hammer";            worksheet.Cells["C3"].Value = 5;            worksheet.Cells["D3"].Value = 12.10;            worksheet.Cells["A4"].Value = 12003;            worksheet.Cells["B4"].Value = "Saw";            worksheet.Cells["C4"].Value = 12;            worksheet.Cells["D4"].Value = 15.37;            //save our new workbook and we are done!            package.Save();        }    }

excel写入的表格 row,rol都是 从1 开始

标签:# 要注意  # pre  # line  # token  # prism  # currentcolor  # 中取  # 安装目录  # 所需要  # windows  # 都是  # unity  # excel  # https  # JavaScript  # ai  # access  
在线客服
服务热线

服务热线

4008888355

微信咨询
二维码
返回顶部
×二维码

截屏,微信识别二维码

打开微信

微信号已复制,请打开微信添加咨询详情!