12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- 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;
- }
- /// <summary>
- /// 链表为 excel信息 .
- /// </summary>
- /// <param name="name"> 文件夹名称</param>
- /// <param name="listInfo">存储的excel信息</param>
- public void ExcelMaker(string name, List<TestInfo> listInfo)
- {
- XlsDocument xls = new XlsDocument(); //新建一个xls文档
- xls.FileName = name; //设定文件名
- xls.SummaryInformation.Author = "xyy"; //填加xls文件作者信息(excel->属性->详细信息)
- xls.SummaryInformation.Subject = "test"; //填加文件主题信息(excel->属性->详细信息)
- string sheetName = "L1";
- Worksheet sheet = xls.Workbook.Worksheets.Add(sheetName); //excel中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)
- {
- //excel 中表单头部信息,可自动变更过
- 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();
- }
- }
|