實現代碼如下:
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
// 引入OFFICE EXCEL命名空間
using Excel = Microsoft.Office.Interop.Excel;
using System.Reflection;
using System.Data;
using System.IO;
using System.Diagnostics;
using System.Collections;
using System.Runtime.InteropServices;
namespace TestLib
{
public class ExcelOperation
{
private DateTime beforeTime; //Excel啟動之前時間
private DateTime afterTime; //Excel啟動之後時間
Excel.Application myExcel = new Excel.Application();
Excel.Workbook myBook;
Excel.Worksheet mySheet1;
Excel.Range range;
Excel.Range range1;
Excel.Range range2;
Excel.TextBox textBox;
public int sheetCount = 1; //WorkSheet數量
private string sheetPrefixName = "頁";
#region 公共屬性
/// <summary>
/// WorkSheet前綴名,比如:前綴名為“頁”,那麼WorkSheet名稱依次為“頁-1,頁-2”
/// </summary>
public string SheetPrefixName
{
set { this.sheetPrefixName = value; }
}
/// <summary>
/// WorkSheet數量
/// </summary>
public int WorkSheetCount
{
get { return myBook.Sheets.Count; }
}
#endregion
public