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

星夢妙者
发布: 2025-07-09 08:04:23
原创
583人浏览过

首先要注意的点: 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

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

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<DepenceTableData> Load(string path)    {        List<DepenceTableData> _data = new List<DepenceTableData>();        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<row;i++)        {            DepenceTableData temp_data;            temp_data.instruct = resultds.Tables[0].Rows[i][0].ToString();            temp_data.word = resultds.Tables[0].Rows[i][1].ToString();            Debug.Log(temp_data.instruct + "  " + temp_data.word);            _data.Add(temp_data);        }        return _data;    }}public struct DepenceTableData{    public string word;    public string instruct;}
登录后复制

写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 开始

以上就是unity3d:windows读写excel,打包exe可用的详细内容,更多请关注php中文网其它相关文章!

Windows激活工具
Windows激活工具

Windows激活工具是正版认证的激活工具,永久激活,一键解决windows许可证即将过期。可激活win7系统、win8.1系统、win10系统、win11系统。下载后先看完视频激活教程,再进行操作,100%激活成功。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 意见反馈 讲师合作 广告合作 最新更新
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习
PHP中文网抖音号
发现有趣的

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号