日期:2014-05-17 浏览次数:20487 次
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Office.Interop.Excel;
using System.IO;
using System.Collections;
using System.Data;
using System.Text.RegularExpressions;
namespace PeopleBank
{
public class CreateExcel
{
private static void toExcel(string FileName, string SheetName, System.Data.DataTable dt)
{
ApplicationClass myExcel = new ApplicationClass();
Worksheet worksheet = null;
string curPath = Directory.GetParent(FileName).FullName;
if (!Directory.Exists(curPath))
{
Directory.CreateDirectory(curPath);
}
if (File.Exists(FileName))
{
try
{
File.Delete(FileName);
}
catch
{
throw new Exception("文件操作出错,可能正在运行当前的EXCEL文件!");
}
}
try
{
object missing = System.Reflection.Missing.Value;
myExcel.Workbooks.Add(missing);
worksheet = (Worksheet)myExcel.ActiveSheet;
worksheet.Name = SheetName;
myExcel.Visible = false;
&nbs