zoukankan      html  css  js  c++  java
  • unity, 读写xls

    可以用npoi:

    http://npoi.codeplex.com/

    把npoi.dll放在unity里即可。

    读取代码:

    using System.IO;
    using NPOI.SS.UserModel;
    using NPOI.HSSF.UserModel;


    using (FileStream stream = File.Open(m_excelPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
    {
      IWorkbook book = new HSSFWorkbook(stream);

      for (int i = 0; i < book.NumberOfSheets; ++i) {
        ISheet s = book.GetSheetAt (i);
        Debug.Log ("sheetName:"+s.SheetName);
        //s.LastRowNum的索引值,不是行总数,从0开始计数
        for (int k = 0; k <= s.LastRowNum; ++k) {
          IRow row = s.GetRow (k);
          if (null == row) {
            continue;
          }

          //print cell[0]

          ICell cell = row.GetCell (0);
          string cellValueStr= getCellValue (cell);
          Debug.Log ("cellValueStr:"+cellValueStr);
        }
      }

    }


    protected string getCellValue(ICell cell)
    {
      if (null == cell) return "";

      if (CellType.NUMERIC == cell.CellType) {
        return cell.NumericCellValue.ToString ();
      } else {
        return cell.StringCellValue;
      }
    }

  • 相关阅读:
    MySQL decimal unsigned 更新负数不报错却为0
    centos 安装jdk
    CentOS7安装docker
    Cron 时间元素
    PHPStorm
    日志习惯
    HTTP幂等性
    navicat for mysql 10.1.7注册码
    localStorage、sessionStorages 使用
    FreePascal
  • 原文地址:https://www.cnblogs.com/wantnon/p/6051419.html
Copyright © 2011-2022 走看看