• Aspose.Cells读取Excel获取DataTable方法


    /// <summary>
            /// 转DataTable
            /// </summary>
            /// <param name="ExcelPath">Excel文件地址</param>
            /// <param name="SheetName">Sheet名称</param>
            /// <param name="StartRow">开始行数</param>
            /// <param name="StartColumn">开始列数</param>
            /// <returns></returns>
            public static DataTable GetDataTable(string ExcelPath, string SheetName, int StartRowIndex, int StartColumnIndex)
            {
                DataTable dt = new DataTable();
                try
                {
                    Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(ExcelPath);
                    Aspose.Cells.Worksheet sheet = workbook.Worksheets[SheetName];
    
                    dt = sheet.Cells.ExportDataTable(StartRowIndex, StartColumnIndex, sheet.Cells.MaxDataRow + 1, sheet.Cells.MaxDataColumn + 1, true);
                }
                catch (Exception ex)
                {
                    dt = null;
                }
    
                return dt;
    }

    删除行方法:

    /// <summary>
            /// 删除Excel多行
            /// </summary>
            /// <param name="ExcelPath">Excel路径</param>
            /// <param name="SheetName">Sheet表名</param>
            /// <param name="RowNumber">删除多行,注意删除的顺序必须为倒序(RowNumber="4,3,2,1,0")</param>
            /// <returns></returns>
            public static bool DeleteRow(string ExcelPath, string SheetName, string RowNumber)
            {
                bool IsDelete = false;
    
                try
                {
                    Aspose.Cells.Workbook workbook = new Aspose.Cells.Workbook(ExcelPath);
                    Aspose.Cells.Worksheet sheet = workbook.Worksheets[SheetName];
    
                    string[] InputStr = RowNumber.Split(',');
    
                    foreach (string item in InputStr)
                    {
                        sheet.Cells.DeleteRow(int.Parse(item));
                    }
    
                    workbook.Save(ExcelPath);
    
                    IsDelete = true;
                }
                catch (Exception)
                {
                    IsDelete = false;
                }
    
                return IsDelete;
    }
    

      

  • 相关阅读:
    MATLAB 之 App designer 小白学习(四)
    MATLAB 之 APP DESIGNER 学习(三)
    MATLAB 之 App designer 小白学习(二)
    MATLAB 之 App designer 小白学习(一)
    激光烧蚀 @有机聚合物
    激光驱动巨量转移工艺
    基于神经网络的函数逼近
    单片机复位电路仿真分析
    基于Python的3R机器人运动仿真
    基于MATLAB的单级倒立摆仿真
  • 原文地址:https://www.cnblogs.com/61007257Steven/p/13820910.html
Copyright © 2020-2023  润新知