unity3d 导出 Excel
我在unity里需要导出成Excel格式,试了一些方法,其中用c#的com组件的我还没成功不知道该怎么在unity里调用,(如果哪位大哥用别的方法在unity里成功了,可以交流下,最好给我一个小demo(849288321@qq.com),谢谢啦.),不过后来找到了这个org.in2bits.MyXls ,需要导入这个dll(网上有很多),然后用着还挺好用,我这写的一个小例子仅供参考,
using UnityEngine;
using System.Collections;
using org.in2bits.MyXls;
using System.Collections.Generic;
public class TestInfo
{
public string name;
public string id;
public string num;
};
public class ExcelMakerManager { public static ExcelMakerManager eInstance;
public static ExcelMakerManager CreateExcelMakerManager()
{
if(eInstance==null)
{
eInstance = new ExcelMakerManager();
}
return eInstance;
}
//链表为 物体信息 .
public void ExcelMaker(string name, List<TestInfo> listInfo)
{
XlsDocument xls = new XlsDocument();//新建一个xls文档
xls.FileName = name;// @"D:\tests.xls";//设定文件名 //Add some metadata (visible from Excel under File -> Properties)
xls.SummaryInformation.Author = "xyy"; //填加xls文件作者信息
xls.SummaryInformation.Subject = "test";//填加文件主题信息 string sheetName = "Sheet0";
Worksheet sheet = xls.Workbook.Worksheets.AddNamed(sheetName);//填加名为"chc 实例"的sheet页
Cells cells = sheet.Cells;//Cells实例是sheet页中单元格(cell)集合 int rowNum = listInfo.Count;
int rowMin = 1;
int row = 0; for (int x = 0; x < rowNum + 1; x++)
{
if (x == 0)
{
//根据具体的物体信息 .需要重新写
cells.Add(1, 1, "名字");
cells.Add(1, 2, "ID");
cells.Add(1, 3, "数量");
}
else
{
cells.Add(rowMin + x, 1, listInfo[row].id);
cells.Add(rowMin + x, 2, listInfo[row].name);
cells.Add(rowMin + x, 3, listInfo[row].num);
row++;
}
}
xls.Save();
}
}
然后下面是调用上面的这个方法
using UnityEngine;
using System.Collections;
using System.IO;
using org.in2bits.MyXls;
using System;
using System.Collections.Generic; public class test : MonoBehaviour
{ string path;
TestInfo test1;
TestInfo test2;
TestInfo test3;
List<TestInfo> listInfos;
// Use this for initialization
void Start()
{
ExcelMakerManager.CreateExcelMakerManager(); // --测试数据
test1 = new TestInfo();
test1.id = "one";
test1.name = "test1";
test1.num = "x"; test2 = new TestInfo();
test2.id = "two";
test2.name = "test2";
test2.num = "22"; test3 = new TestInfo();
test3.id = "tree";
test3.name = "test3";
test3.num = "333"; listInfos = new List<TestInfo>();
listInfos.Add(test1);
listInfos.Add(test2);
listInfos.Add(test3);
// --测试数据
// ManagerExcel.CreateE();
} // Update is called once per frame
void Update()
{ }
void OnGUI()
{
if (GUI.Button(new Rect(100, 0, 100, 100), "aa"))
{
PrintExcel();
Debug.Log("aaaa");
}
}
public void PrintExcel()
{
if (!Directory.Exists(Application.dataPath + "/Prints"))
{
Directory.CreateDirectory(Application.dataPath + "/Prints");
}
path = Application.dataPath + "/Prints/Excel_"
+ System.DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + ".xls";
ExcelMakerManager.eInstance.ExcelMaker(path, listInfos);
}
}
至于改字体啥的网上都有相应的例子.可以自己去看看...这里就不多说了.
结果如图:
unity3d 导出 Excel的更多相关文章
- C#使用Aspose.Cells导出Excel简单实现
首先,需要添加引用Aspose.Cells.dll,官网下载地址:http://downloads.aspose.com/cells/net 将DataTable导出Xlsx格式的文件下载(网页输出) ...
- 利用poi导出Excel
import java.lang.reflect.Field;import java.lang.reflect.InvocationTargetException;import java.lang.r ...
- [django]数据导出excel升级强化版(很强大!)
不多说了,原理采用xlwt导出excel文件,所谓的强化版指的是实现在网页上选择一定条件导出对应的数据 之前我的博文出过这类文章,但只是实现导出数据,这次左思右想,再加上网上的搜索,终于找出方法实现条 ...
- NPOI导出Excel
using System;using System.Collections.Generic;using System.Linq;using System.Text;#region NPOIusing ...
- ASP.NET Core 导入导出Excel xlsx 文件
ASP.NET Core 使用EPPlus.Core导入导出Excel xlsx 文件,EPPlus.Core支持Excel 2007/2010 xlsx文件导入导出,可以运行在Windows, Li ...
- asp.net DataTable导出Excel 自定义列名
1.添加引用NPOI.dll 2.cs文件头部添加 using NPOI.HSSF.UserModel; using NPOI.SS.UserModel; using System.IO; 3.代码如 ...
- Aspose.Cells导出Excel(1)
利用Aspose.Cells导出excel 注意的问题 1.DataTable的处理 2.进行编码,便于中文名文件下载 3.别忘了Aspose.Cells.dll(可以自己在网上搜索) public ...
- 前端导出Excel兼容写法
今天整理出在Web前端导出Excel的写法,写了一个工具类,对各个浏览器进行了兼容. 首先,导出的数据来源可能有两种: 1. 页面的HTML内容(一般是table) 2. 纯数据 PS:不同的数据源, ...
- JS导出excel 兼容ie、chrome、firefox
运用js实现将页面中的table导出为excel文件,页面显示如下: 导出的excel文件显示如下: 实现代码: <!DOCTYPE html> <html> <head ...
随机推荐
- Uva 1342 - That Nice Euler Circuit
Little Joey invented a scrabble machine that he called Euler, after the great mathematician. In his ...
- JQuery轻量级网页编辑器 选中即可编辑
目前流行的可视化网页编辑器非常多,像ckeditor.kindeditor.tinyeditor等,虽然功能都非常强大,但是体积都比 较庞大,使用起来也不是很方便.今天我们分享一款基于jQuery的轻 ...
- Android应用开发学习之启动另外一个Activity
作者:刘昊昱 博客:http://blog.csdn.net/liuhaoyutz 一个Activity可以启动另外一个Activity,以实现比较复杂的功能,我们来看一个例子,其运行效果如下图所示: ...
- vs2010 正式版官方下载地址
北京时间2010年4月12日12:00,微软Visual Studio 2010 正式版提供官方下载,眼下有三个版本号,Professional/Premium/Ultimate. 注意原页面的链接R ...
- visual studio 2015离线版msdn下载和安装
2014年11月13日,微软发布了Visual Studio 2015 Preview,但是Visual Studio 2015 的msdn该如何安装呢?下面脚本之家就为大家分享一篇visual st ...
- Ubuntu的防火墙UFW
这是个简单的防火墙,可以直接在命令行启停,也可安装提图形端gufw *安装 sudo apt-get install ufw gufw *常用命令 sudo ufw enable //启动 ufw d ...
- java获取文件大小
1.使用File的length()方法获取.这个方法获取的字节数,由于返回的是Long类型所以能返回的最大值是Long.MAX_VALUE File file = new File( "D: ...
- Oracle字符集查看
Oracle字符集是一个字节数据的解释的符号集合,有大小之分,有相互的包容关系.ORACLE 支持国家语言的体系结构允许你使用本地化语言来存储,处理,检索数据.它使数据库工具,错误消息,排序次序,日期 ...
- [跟我学spring学习笔记][DI循环依赖]
循环依赖 什么是循环依赖? 循环依赖就是循环引用,就是两个或多个Bean相互之间的持有对方. Spring容器循环依赖包括构造器循环依赖和setter循环依赖,那Spring容器如何解决循环依赖呢? ...
- [core java学习笔记][第十一章异常断言日志调试]
第11章 异常,断言,日志,调试 处理错误 捕获异常 使用异常机制的技巧 使用断言 日志 测试技巧 GUI程序排错技巧 使用调试器 11.1 处理错误 11.1.1异常分类 都继承自Throwable ...