首页 > 代码库 > C#读写EXCEL的简单封装
C#读写EXCEL的简单封装
用法简单,类似于ado.net
ExcelTools.Open()
//读写
ExcelTools.SaveAndClose()
using System;using System.Collections.Generic;using System.Linq;using System.Text;using Microsoft.Office.Interop.Excel;using System.IO;using System.Windows.Forms;using System.Reflection;namespace AutoReportDeal{ class ExcelTools { public static Microsoft.Office.Interop.Excel.Application xlsApp = null; public static Microsoft.Office.Interop.Excel.Workbook workbook = null; public static Microsoft.Office.Interop.Excel.Worksheet worksheet = null; public static string str_this_path = null; #region 打开某EXCEL文件的某个页 /// <param name="str_path">EXCEL文件路径</param> /// <param name="str_sheet">要操作的页</param> public static void Open(string str_path, string str_sheet) { str_this_path = str_path; //Excel Application xlsApp = new Microsoft.Office.Interop.Excel.Application(); //Excel Workbook workbook = xlsApp.Workbooks.Open(str_path, 0, true, 5, System.Reflection.Missing.Value, System.Reflection.Missing.Value, false, System.Reflection.Missing.Value, System.Reflection.Missing.Value, true, false, System.Reflection.Missing.Value, false, false, false); //Excel Worksheet worksheet = (Worksheet)workbook.Worksheets[str_sheet]; } #endregion #region 筛选日期列获得在EXCEL中的行号 /// <param name="col_name">要进行筛选的列明</param> /// <param name="str_date_value">要筛选的值</param> /// <param name="isHasTitle">是否存在表头</param> /// <returns>成功返回行号,出错返回-1</returns> public static int GetExcelRowsIndexByDate(string col_name, string str_date_value, bool isHasTitle) { if (str_date_value =http://www.mamicode.com/= null)>
C#读写EXCEL的简单封装
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。