ExcelMakerManager.cs 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using UnityEngine;
  2. using System.Collections;
  3. using org.in2bits.MyXls;
  4. using System.Collections.Generic;
  5. public class TestInfo
  6. {
  7. public string name;
  8. public string id;
  9. public string num;
  10. };
  11. public class ExcelMakerManager
  12. {
  13. public static ExcelMakerManager eInstance;
  14. public static ExcelMakerManager CreateExcelMakerManager()
  15. {
  16. if (eInstance == null)
  17. {
  18. eInstance = new ExcelMakerManager();
  19. }
  20. return eInstance;
  21. }
  22. /// <summary>
  23. /// 链表为 excel信息 .
  24. /// </summary>
  25. /// <param name="name"> 文件夹名称</param>
  26. /// <param name="listInfo">存储的excel信息</param>
  27. public void ExcelMaker(string name, List<TestInfo> listInfo)
  28. {
  29. XlsDocument xls = new XlsDocument(); //新建一个xls文档
  30. xls.FileName = name; //设定文件名
  31. xls.SummaryInformation.Author = "xyy"; //填加xls文件作者信息(excel->属性->详细信息)
  32. xls.SummaryInformation.Subject = "test"; //填加文件主题信息(excel->属性->详细信息)
  33. string sheetName = "L1";
  34. Worksheet sheet = xls.Workbook.Worksheets.Add(sheetName); //excel中sheet页名称
  35. Cells cells = sheet.Cells; //Cells实例是sheet页中单元格(cell)集合
  36. int rowNum = listInfo.Count;
  37. int rowMin = 1;
  38. int row = 0;
  39. for (int x = 0; x < rowNum + 1; x++)
  40. {
  41. if (x == 0)
  42. {
  43. //excel 中表单头部信息,可自动变更过
  44. cells.Add(1, 1, "名字");
  45. cells.Add(1, 2, "ID");
  46. cells.Add(1, 3, "数量");
  47. }
  48. else
  49. {
  50. cells.Add(rowMin + x, 1, listInfo[row].id);
  51. cells.Add(rowMin + x, 2, listInfo[row].name);
  52. cells.Add(rowMin + x, 3, listInfo[row].num);
  53. row++;
  54. }
  55. }
  56. xls.Save();
  57. }
  58. }