Last active
September 11, 2023 07:04
-
-
Save ksasao/4a89960735be8cbc8b2c9bd15c466ce1 to your computer and use it in GitHub Desktop.
C#による漢字→かな変換。参照>COMで、Microsoft Excel XX.X Object Library を参照に追加する。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.IO; | |
using System.Runtime.InteropServices; | |
using ExcelApplication = Microsoft.Office.Interop.Excel.Application; | |
using Microsoft.VisualBasic; | |
namespace Kanji2Yomi | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
if (args.Length == 0) | |
{ | |
Console.WriteLine("usage: kanji2yomi target_file"); | |
return; | |
} | |
ExcelApplication objExcel = new ExcelApplication(); | |
try | |
{ | |
string path = args[0]; | |
string[] src = File.ReadAllLines(path); | |
string[] dest = new string[src.Length]; | |
for(int i = 0; i < src.Length; i++) | |
{ | |
if (src[i].Trim() == "") | |
{ | |
dest[i]=""; | |
continue; | |
} | |
string katakana = objExcel.GetPhonetic(src[i]); | |
string hiragana = Strings.StrConv(katakana, VbStrConv.Hiragana); | |
dest[i] = katakana; | |
} | |
File.WriteAllLines(path+".yomi.txt", dest); | |
} | |
catch (COMException ex) | |
{ | |
Console.WriteLine(ex.Message); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment