zoukankan      html  css  js  c++  java
  • 查找Excel的Sheetname的方法

    #region 查找Sheetname
            ///// <summary>
            ///// 找到sheetname
            ///// </summary>
            ///// <param name="filePath"></param>
            ///// <returns></returns>
            //private static string GetSheetName(string filePath)
            //{
            //    string sheetName = "";

            //    System.IO.FileStream tmpStream = File.OpenRead(filePath);
            //    byte[] fileByte = new byte[tmpStream.Length];
            //    tmpStream.Read(fileByte, 0, fileByte.Length);
            //    tmpStream.Close();

            //    byte[] tmpByte = new byte[]{Convert.ToByte(11),Convert.ToByte(0),Convert.ToByte(0),Convert.ToByte(0),Convert.ToByte(0),Convert.ToByte(0),Convert.ToByte(0),Convert.ToByte(0),
            //   Convert.ToByte(11),Convert.ToByte(0),Convert.ToByte(0),Convert.ToByte(0),Convert.ToByte(0),Convert.ToByte(0),Convert.ToByte(0),Convert.ToByte(0),
            //   Convert.ToByte(30),Convert.ToByte(16),Convert.ToByte(0),Convert.ToByte(0)};

            //    int index = GetSheetIndex(fileByte, tmpByte);
            //    if (index > -1)
            //    {

            //        index += 16 + 12;
            //        System.Collections.ArrayList sheetNameList = new System.Collections.ArrayList();

            //        for (int i = index; i < fileByte.Length - 1; i++)
            //        {
            //            byte temp = fileByte[i];
            //            if (temp != Convert.ToByte(0))
            //                sheetNameList.Add(temp);
            //            else
            //                break;
            //        }
            //        byte[] sheetNameByte = new byte[sheetNameList.Count];
            //        for (int i = 0; i < sheetNameList.Count; i++)
            //            sheetNameByte[i] = Convert.ToByte(sheetNameList[i]);

            //        sheetName = System.Text.Encoding.Default.GetString(sheetNameByte);
            //    }
            //    return sheetName;
            //}
            ///// <summary>
            ///// 只供方法GetSheetName()使用
            ///// </summary>
            ///// <returns></returns>
            //private static int GetSheetIndex(byte[] FindTarget, byte[] FindItem)
            //{
            //    int index = -1;

            //    int FindItemLength = FindItem.Length;
            //    if (FindItemLength < 1) return -1;
            //    int FindTargetLength = FindTarget.Length;
            //    if ((FindTargetLength - 1) < FindItemLength) return -1;

            //    for (int i = FindTargetLength - FindItemLength - 1; i > -1; i--)
            //    {
            //        System.Collections.ArrayList tmpList = new System.Collections.ArrayList();
            //        int find = 0;
            //        for (int j = 0; j < FindItemLength; j++)
            //        {
            //            if (FindTarget[i + j] == FindItem[j]) find += 1;
            //        }
            //        if (find == FindItemLength)
            //        {
            //            index = i;
            //            break;
            //        }
            //    }
            //    return index;
            //}

  • 相关阅读:
    JSON.parse解决Unexpected token ' in JSON at position 1报错
    angularjs $scope与this的区别,controller as vm有何含义?
    angularjs link compile与controller的区别详解,了解angular生命周期
    理解Promise.all,Promise.all与Promise.race的区别,如何让Promise.all在rejected失败后依然返回resolved成功结果
    angularjs 一篇文章看懂自定义指令directive
    js 记录几个因惯性思维引发的代码BUG,开发思维方式的自我反省
    js forEach参数详解,forEach与for循环区别,forEach中如何删除数组元素
    angularjs ng-if妙用,ng-if解决父子组件异步传值
    JS 从内存空间谈到垃圾回收机制
    Markdown数学公式语法
  • 原文地址:https://www.cnblogs.com/jasonjiang/p/1787635.html
Copyright © 2011-2022 走看看