Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
2
Help us understand the problem. What is going on with this article?
@itasnasal

WSHとExcelでふりがなの生成

More than 3 years have passed since last update.

Excelの機能を使ってふりがなを生成します。
完全ではありませんが、自分でやるより全然楽です。

cscript //nologo genPhonetic.js [読みを付けたい感じのリスト]

みたいな感じで実行します。

genPhonetic.js
// magic spell for WSH ///////////////////////////////////////////////////////
if(typeof console==="undefined")  console={log: function(s){WScript.Echo(s)}};
if(typeof process==="undefined"){ process={exit:function(e){WScript.Quit(e)}};
var v=process.argv=[];v.push(WScript.FullName);v.push(WScript.ScriptFullName);
var n=WScript.Arguments.Unnamed;for(var i=0;i<n.length;i++)v.push(n.item(i))};
//////////////////////////////////////////////////////////////////////////////
//
// ExcelのApplication.GetPhonetic メソッドを使ってふりがなを生成する
//
// Application.GetPhonetic メソッド (Excel)
// https://msdn.microsoft.com/ja-jp/vba/excel-vba/articles/application-getphonetic-method-excel

var fso = new ActiveXObject("Scripting.FileSystemObject");
var ExcelApp = new ActiveXObject( "Excel.Application" );

try {
    var book = ExcelApp.Workbooks.Add();
    var sheet = book.Worksheets( 1 );

    var argv = process.argv.slice(2);
    if( argv.length > 0 ) {
        for( var i=0; i<argv.length; i++ ) {
            main( argv[i] );
        }
    } else {
        main( WScript.StdIn );  // フィルター動作
    }
    function main( file ) {     // 主処理
        var result=[];
        if( typeof file==="string" ) {
            var f = fso.OpenTextFile( file, 1); // 1:ForReading
        } else {
            f = file;
        }
        while ( !f.AtEndOfStream) {
            var phrase = f.ReadLine();
            var yomi = ExcelApp.GetPhonetic(phrase);
            result.push( [ phrase, yomi ].join("\t") );
        }
        f.Close();
        console.log( result.join("\n") );
    }
}
finally {   // 後処理
    ExcelApp.Quit();
    ExcelApp = null;
}   // エラー時もExcelを終わらせるため、try~catch~finallyを使う。

2
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
2
Help us understand the problem. What is going on with this article?