摘要:簡體轉成繁體
使用時須先參考Interop.Microsoft.Office.Interop.Word.dll才能用。
public string ToSimplified(string strSource)
{
//轉成簡體字
string strResult;
_Application objWord = new Microsoft.Office.Interop.Word.Application();
object t = Missing.Value;
object nt = Missing.Value;
object dt = Missing.Value;
object v = true;
Document objDocument = objWord.Documents.Add(ref t, ref nt, ref dt, ref v);
objWord.Selection.TypeText(strSource);
objWord.Selection.Range.TCSCConverter(WdTCSCConverterDirection.wdTCSCConverterDirectionTCSC, true, true);
objWord.ActiveDocument.Select();
strResult = objWord.Selection.Text;
object sc = 0;
object of = Missing.Value;
object rd = Missing.Value;
objWord.Quit(ref sc, ref of, ref rd);
objDocument = null;
objWord = null;
return strResult;
}
public string ToTraditional(string strSource)
{
//轉成繁體字
string strResult;
_Application objWord = new Microsoft.Office.Interop.Word.Application();
object t = Missing.Value;
object nt = Missing.Value;
object dt = Missing.Value;
object v = true;
Document objDocument = objWord.Documents.Add(ref t, ref nt, ref dt, ref v);
objWord.Selection.TypeText(strSource);
objWord.Selection.Range.TCSCConverter(WdTCSCConverterDirection.wdTCSCConverterDirectionSCTC, true, true);
objWord.ActiveDocument.Select();
strResult = objWord.Selection.Text;
object sc = 0;
object of = Missing.Value;
object rd = Missing.Value;
objWord.Quit(ref sc, ref of, ref rd);
objDocument = null;
objWord = null;
return strResult;
}