Skip to content

Instantly share code, notes, and snippets.

@moluapple
Created March 22, 2012 08:19
Show Gist options
  • Save moluapple/2157102 to your computer and use it in GitHub Desktop.
Save moluapple/2157102 to your computer and use it in GitHub Desktop.
[Indesign] Word DLL 简繁转换 python 脚本打包测试
'''
抽出WORD中繁简转换的DLL,直接调用.
需要的文件: MSTR2TSC.DLL MSTR2TSC.LEX MSO.DLL
原文见:http://hyry.dip.jp:8000/code.py?id=105
'''
import ctypes
import win32com.client
def translate(s, gb_big):
d = ctypes.windll.LoadLibrary('MSTR2TSC.DLL')
d.TCSCInitialize()
ptr, num = ctypes.c_wchar_p(0), ctypes.c_int(0)
d.TCSCConvertText(s, len(s), ctypes.byref(ptr), ctypes.byref(num), gb_big, False, True)
# 1 or 0 简 -> 繁, False or True 转换常用词、使用港台异体字
out = ptr.value
d.TCSCFreeConvertedText(ptr)
d.TCSCUninitialize()
return out
def transId():
app = win32com.client.Dispatch('Indesign.Application.CS5')
text = app.ActiveDocument.Selection
gb_big = app.DoScript('confirm("是(Enter):繁>简\\n否(Esc):简>繁", 0, "简繁转换")', 1246973031)
try:
text.Contents = translate(text.Contents, gb_big)
except AttributeError:
text[0].Contents = translate(text[0].Contents, gb_big)
if __name__ == '__main__':
transId()
@BrandonStudio
Copy link

链接已失效,另外这个方法现在似乎用不了了,dll导入时会提示找不到模块

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment