资源简介

Unity3d动态创建excel并写入数据

资源截图

代码片段和文件信息

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 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();  
    }  
}  

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2013-09-18 14:55  Unity3d动态创建excel并写入数据\
     文件        1960  2013-09-18 14:47  Unity3d动态创建excel并写入数据\ExcelMakerManager.cs
     文件      125952  2010-01-27 12:38  Unity3d动态创建excel并写入数据\org.in2bits.MyXls.dll
     文件        1808  2013-10-24 11:48  Unity3d动态创建excel并写入数据\test.cs

评论

共有 条评论