Asp.net 导入Excel(服务器不带Office)
生活随笔
收集整理的這篇文章主要介紹了
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;
轉載于:https://www.cnblogs.com/houzuofeng/p/3411128.html
總結
以上是生活随笔為你收集整理的Asp.net 导入Excel(服务器不带Office)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: main函数的参数问题 (转载)
- 下一篇: JavaScript 同源策略