• Asp.net 导入Excel(服务器不带Office)


    #region 把excel文件转换为DataSet.
    /// <summary>  
    /// 把excel文件转换为DataSet.  
    /// </summary>  
    /// <param name="filepath">文件路径</param>  
    /// <param name="firstRow">第一行初始值</param>
    /// <param name="firstColumn">第一列初始值</param>
    /// <param name="moreSheet">是否取多余1个Sheet</param>
    /// <returns></returns>  
    public static DataSet ExcelToDataSet(string filepath, int firstRow, int firstColumn, bool moreSheet = false)
    {
        DataSet ds = new DataSet();
        try
        {
            Workbook workbook = new Workbook(filepath);
            foreach (Worksheet worksheet in workbook.Worksheets)
            {
                if (worksheet.Cells.Rows.Count > 0)
                {
                    ds.Tables.Add(worksheet.Cells.ExportDataTable(firstRow, firstColumn, worksheet.Cells.MaxDataRow + 1, worksheet.Cells.MaxDataColumn + 1, true));
                    if (!moreSheet)
                        break;
                }
            }
        }
        catch (Exception ex)
        {
            Logging.Error(string.Format("把excel文件转换为DataSet时,读取Excel文件异常,描述:{0}", ex.Message));
        }
        return ds;
    }
    #endregion

    用这个方法是要注意,需要下载一个Aspose.Cells.dll文件,引用到项目中

    并且引用明明空间 using Aspose.Cells;

  • 相关阅读:
    UnityEngine中Animator相关类的说明
    MecanimControl插件随笔
    Mecanim Control
    Unity3D
    Unity Mecanim在大型mmo中的应用
    Unity3D 性能优化
    Unity3D 图形优化
    U3D开发性能优化笔记(待增加版本.x)
    通过JS语句判断WEB网站的访问端是电脑还是手机
    jquery 鼠标事件汇总
  • 原文地址:https://www.cnblogs.com/houzuofeng/p/3411128.html
Copyright © 2020-2023  润新知