2008年4月14日 星期一

瓶水相逢:C# 利用 Word 作簡繁轉換 - 樂多日誌

瓶水相逢:C# 利用 Word 作簡繁轉換 - 樂多日誌
public string TC2SC(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 SC2TC(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;
}

沒有留言: