日期:2014-05-17 浏览次数:20383 次
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Microsoft.Win32;
using Microsoft.Office.Interop.Word;
using System.Net;
using System.Web;
using System.Data;
using System.Text.RegularExpressions;
namespace OfficeOperate
{
public class WordOperate
{
bool leicai = true;
#region 新建Word文档
/// <summary>
/// 动态生成Word文档并填充内容
/// </summary>
/// <param name="dir">文档目录</param>
/// <param name="fileName">文档名</param>
/// <returns>返回自定义信息</returns>
public static bool CreateWordFile(string dir, string fileName)
{
Object saveOption = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
Object oMissing = System.Reflection.Missing.Value;
if (!Directory.Exists(dir))
{
//创建文件所在目录
Directory.CreateDirectory(dir);
}
//创建Word文档(Microsoft.Office.Interop.Word)
Microsoft.Office.Interop.Word._Application WordApp = new Application();
WordApp.Visible = true;
Microsoft.Office.Interop.Word._Document WordDoc = WordApp.Documents.Add(
ref oMissing, ref oMissing, ref oMissing, ref oMissing);
//保存
object FileFormat = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatDocument;//
object filename = dir + fileName;
WordDoc.SaveAs(ref filename, ref FileFormat, ref oMissing, ref oMissing, ref oMissing,
ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing,