C
Chris Q
I’m having problems in converting Traditional Chinese to Simplified Chinese
with the TCSCConverter function. If I use it interactively inside Word, it
seems to work pretty well. For instance, if I start with this fragment:
轉æ›æ•ˆæžœå°±è·ŸWord2003一樣, 它ä¸åƒ…åšå—碼轉æ›,é‚„åšç”¨æ³•è½‰æ›,
And then I do Tools::Language::Chinese Translation::TC->SC (w/ common
words), I get this (reasonable) output.
转æ¢æ•ˆæžœå°±è·ŸWord2003ä¸€æ ·, 它ä¸ä»…åšå—ç 转æ¢,还åšç”¨æ³•è½¬æ¢,
However, if I try to do this same conversion using automation, I get an
unchanged result. Basically what I do is create a new Word.Document d, say
d.Content.Text = input, run TCSCConverter, then return d.Content.Text, and I
get the same content back – no change at all. It’s as if I didn’t call
TCSCConverter at all.
Does anybody have an idea what’s going on?
Thanks very much!
--Chris
Here’s my C# code to do the conversion.
using System;
using System.IO;
using Microsoft.Office.Interop.Word;
class Program
{
static void Main(string[] args)
{
using (Converter c = new Converter())
using (StreamReader sr = new StreamReader(args[0]))
using (StreamWriter sw = new StreamWriter(args[1], false,
System.Text.Encoding.Unicode))
{
string sLine;
while (null != (sLine = sr.ReadLine()))
sw.WriteLine(c.Convert(sLine).Trim());
}
}
}
class Converter : IDisposable
{
Document d = null;
public Converter()
{
d = new DocumentClass();
d.Application.Visible = false;
}
~Converter() { Dispose(); }
public string Convert(string sOrig)
{
d.Content.Text = sOrig;
d.Content.TCSCConverter(WdTCSCConverterDirection.wdTCSCConverterDirectionTCSC, true, false);
return d.Content.Text;
}
public void Dispose()
{
if (d != null)
{
object fSaveChanges = false, o1 = null, o2 = null;
d.Close(ref fSaveChanges, ref o1, ref o2);
d = null;
}
}
}
with the TCSCConverter function. If I use it interactively inside Word, it
seems to work pretty well. For instance, if I start with this fragment:
轉æ›æ•ˆæžœå°±è·ŸWord2003一樣, 它ä¸åƒ…åšå—碼轉æ›,é‚„åšç”¨æ³•è½‰æ›,
And then I do Tools::Language::Chinese Translation::TC->SC (w/ common
words), I get this (reasonable) output.
转æ¢æ•ˆæžœå°±è·ŸWord2003ä¸€æ ·, 它ä¸ä»…åšå—ç 转æ¢,还åšç”¨æ³•è½¬æ¢,
However, if I try to do this same conversion using automation, I get an
unchanged result. Basically what I do is create a new Word.Document d, say
d.Content.Text = input, run TCSCConverter, then return d.Content.Text, and I
get the same content back – no change at all. It’s as if I didn’t call
TCSCConverter at all.
Does anybody have an idea what’s going on?
Thanks very much!
--Chris
Here’s my C# code to do the conversion.
using System;
using System.IO;
using Microsoft.Office.Interop.Word;
class Program
{
static void Main(string[] args)
{
using (Converter c = new Converter())
using (StreamReader sr = new StreamReader(args[0]))
using (StreamWriter sw = new StreamWriter(args[1], false,
System.Text.Encoding.Unicode))
{
string sLine;
while (null != (sLine = sr.ReadLine()))
sw.WriteLine(c.Convert(sLine).Trim());
}
}
}
class Converter : IDisposable
{
Document d = null;
public Converter()
{
d = new DocumentClass();
d.Application.Visible = false;
}
~Converter() { Dispose(); }
public string Convert(string sOrig)
{
d.Content.Text = sOrig;
d.Content.TCSCConverter(WdTCSCConverterDirection.wdTCSCConverterDirectionTCSC, true, false);
return d.Content.Text;
}
public void Dispose()
{
if (d != null)
{
object fSaveChanges = false, o1 = null, o2 = null;
d.Close(ref fSaveChanges, ref o1, ref o2);
d = null;
}
}
}