如何正确的把简体中文翻译到繁体中文(C#)

程沛
2023-12-01

  /// <summary>
  /// 必需的设计器变量。
  /// </summary>
  private Word.ApplicationClass app=new Word.ApplicationClass();

  /// <summary>
  /// 初始化Word 的Application 和Documents
/// </summary>
  /// <returns></returns>

private void InitWordApp()

{

   object optional=Missing.Value;
   object template=Missing.Value;
   object newTemplate=Missing.Value;
   object documentType=Missing.Value;
   object visible=false;
   doc = app.Documents.Add(ref template, ref newTemplate, ref documentType, ref visible);

}

  /// <summary>
  /// 将繁体中文转换成简体中文
  /// </summary>
  /// <param name="s"></param>
  /// <returns></returns>
  private string ConvertToTCSC(string s)
  {
   if(s=="") return s;
   object first=0;
   object last=doc.Characters.Count;
   doc.Range(ref first, ref last).Select();
   doc.Range(ref first,ref last).Text=s;
   last=doc.Characters.Count;
   doc.Range(ref first,ref last).TCSCConverter(Word.WdTCSCConverterDirection.wdTCSCConverterDirectionTCSC,true,true);
   last=doc.Characters.Count;
   return doc.Range(ref first,ref last).Text.TrimEnd('/r');
  }
  /// <summary>
  /// 将简体中文转换成繁体中文
  /// </summary>
  /// <param name="s"></param>
  /// <returns></returns>
  private string ConvertToSCTC(string s)
  {
   if(s=="") return "";
   object first=0;
   object last=doc.Characters.Count;
   doc.Range(ref first, ref last).Select();
   doc.Range(ref first,ref last).Text=s;
   last=doc.Characters.Count;
   doc.Range(ref first,ref last).TCSCConverter(Word.WdTCSCConverterDirection.wdTCSCConverterDirectionSCTC,true,true);
   last=doc.Characters.Count;
   return doc.Range(ref first,ref last).Text.TrimEnd('/r');
  }
 

 类似资料: