using System;
using System
using System
using Microsoft
using System
namespace OfficeManager
{
public class WordClass : IDisposable
{
#region 字段
private _Application m_WordApp = null;
private _Document m_Document = null;
private object missing = System
#endregion
#region 構造函數與析構函數
public WordClass()
{
m_WordApp = new ApplicationClass();
}
~WordClass()
{
try
{
if (m_WordApp != null)
m_WordApp
}
catch (Exception ex)
{
Debug
}
}
#endregion
#region 屬性
public _Document Document
{
get
{
return m_Document;
}
}
public _Application WordApplication
{
get
{
return m_WordApp;
}
}
public int WordCount
{
get
{
if (m_Document != null)
{
Range rng = m_Document
rng
return m_Document
}
else
return
}
}
public object Missing
{
get
{
return missing;
}
}
#endregion
#region 基本任務
#region CreateDocument
public void CreateDocument(string template)
{
object obj_template = template;
if (template
m_Document = m_WordApp
}
public void CreateDocument()
{
this
}
#endregion
#region OpenDocument
public void OpenDocument(string fileName
{
object obj_FileName = fileName;
object obj_ReadOnly = readOnly;
m_Document = m_WordApp
ref missing
ref missing
}
public void OpenDocument(string fileName)
{
this
}
#endregion
#region Save & SaveAs
public void Save()
{
if (m_Document != null)
m_Document
}
public void SaveAs(string fileName)
{
object obj_FileName = fileName;
if (m_Document != null)
{
m_Document
ref missing
ref missing
}
}
#endregion
#region Close
public void Close(bool isSaveChanges)
{
object saveChanges = WdSaveOptions
if (isSaveChanges)
saveChanges = WdSaveOptions
if (m_Document != null)
m_Document
}
#endregion
#region 添加數據
/// <summary>
/// 添加圖片
/// </summary>
/// <param name=
public void AddPicture(string picName)
{
if (m_WordApp != null)
m_WordApp
}
/// <summary>
/// 插入頁眉
/// </summary>
/// <param name=
/// <param name=
public void SetHeader(string text
{
this
this
this
this
this
}
/// <summary>
/// 插入頁腳
/// </summary>
/// <param name=
/// <param name=
public void SetFooter(string text
{
this
this
this
this
this
}
#endregion
#region Print
public void PrintOut()
{
object copies =
object pages =
object range = WdPrintOutRange
object items = WdPrintOutItem
object pageType = WdPrintOutPages
object oTrue = true;
object oFalse = false;
this
ref oTrue
ref items
ref missing
}
public void PrintPreview()
{
if (m_Document != null)
m_Document
}
#endregion
public void Paste()
{
try
{
if (m_Document != null)
{
m_Document
}
}
catch (Exception ex)
{
Debug
}
}
#endregion
#region 文檔中的文本和對象
public void AppendText(string text)
{
Selection currentSelection = this
// Store the user
bool userOvertype = this
// Make sure Overtype is turned off
if (this
{
this
}
// Test to see if selection is an insertion point
if (currentSelection
{
currentSelection
currentSelection
}
else
if (currentSelection
{
// Move to start of selection
if (this
{
object direction = WdCollapseDirection
currentSelection
}
currentSelection
currentSelection
}
else
{
// Do nothing
}
// Restore the user
this
}
#endregion
#region 搜索和替換文檔中的文本
public void Replace(string oriText
{
object replaceAll = WdReplace
this
this
this
this
this
ref missing
ref missing
ref replaceAll
}
#endregion
#region 文檔中的Word表格
/// <summary>
/// 向文檔中插入表格
/// </summary>
/// <param name=
/// <param name=
/// <param name=
/// <param name=
/// <returns></returns>
public Table AppendTable(int startIndex
{
object start = startIndex;
object end = endIndex;
Range tableLocation = this
return this
}
/// <summary>
/// 添加行
/// </summary>
/// <param name=
/// <returns></returns>
public Row AppendRow(Table table)
{
object row = table
return table
}
/// <summary>
/// 添加列
/// </summary>
/// <param name=
/// <returns></returns>
public Column AppendColumn(Table table)
{
object column = table
return table
}
/// <summary>
/// 設置單元格的文本和對齊方式
/// </summary>
/// <param name=
/// <param name=
/// <param name=
public void SetCellText(Cell cell
{
cell
cell
}
#endregion
#region IDisposable 成員
public void Dispose()
{
try
{
if (m_WordApp != null)
m_WordApp
}
catch (Exception ex)
{
Debug
}
}
#endregion
}
}
From:http://tw.wingwit.com/Article/program/ASP/201311/21787.html