Last active
August 29, 2015 14:22
-
-
Save aki-lua87/77a48342b8213e7e21f6 to your computer and use it in GitHub Desktop.
ExcelからPHP動かしてみた ref: http://qiita.com/aki_lua87/items/57500cf28fc9f45d5a2c
This file contains 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
<?php | |
//標準入力 | |
$str = trim(fgets(STDIN)); | |
//$str = mb_convert_encoding($strIn, "UTF-8", "SJIS"); | |
//標準出力用ヘッダー | |
$header = " header "; | |
$footer = " footer "; | |
//処理 | |
$strCh = $str."食べたい"; | |
//出力用にSJISに | |
//$strOut = mb_convert_encoding($strCh, 'SJIS', 'UTF-8'); | |
//出力 | |
//確認用 | |
echo "変換前 -> ".$str." 変換後 -> ".$strCh."\n"; | |
//Excelで読みたい値をheader,footerで囲む | |
echo $header; | |
echo $strCh; | |
echo $footer; | |
//確認用 | |
echo "end"; | |
This file contains 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
Sub テスト() | |
Dim path As String | |
Dim before As String | |
Dim WSH, Exec_cmd, Com As String | |
Dim Result As String | |
Dim head, foot() As String | |
'現在のパス | |
path = ThisWorkbook.path | |
'変換元値 | |
before = Range("B3").Value | |
'コマンドプロンプトオブジェクト | |
Set WSH = CreateObject("WScript.Shell") | |
'コマンド生成 | |
Com = "php " & path & "\excel_php_test.php" | |
'コマンド実行 | |
Set Exec_cmd = WSH.Exec("%ComSpec% /c " & Com) | |
'標準入力 | |
Exec_cmd.StdIn.WriteLine (before) | |
'終わるまで待つ | |
Do While Exec_cmd.Status = 0 | |
DoEvents | |
Loop | |
'結果を全部Resultに | |
Result = Exec_cmd.StdOut.ReadAll | |
'頭区切り文字列で分ける | |
head = Split(Result, " header ") | |
'尻区切り文字列で分ける | |
foot = Split(head(1), " footer ") | |
'foot(0)に変換後の値が入る(はず) | |
Range("D3").Value = foot(0) | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment