Last active
February 2, 2017 12:59
-
-
Save muzudho/4047292c6fcb83addf033c3dd814761a to your computer and use it in GitHub Desktop.
LibreOfficeをインストールしよう ref: http://qiita.com/muzudho1/items/dcd876a26a223045535c
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
REM ***** BASIC ***** | |
Sub Main | |
msgbox "Hello World!!" | |
Dim oSheet as Object ' シート | |
Dim oSheets As Object ' シートのリスト | |
Dim sheetName As String ' シートの名前 | |
Dim oDoc As Object ' 新しいブック | |
Dim Dummy() ' 使わない引数に | |
Dim folder As String ' 信頼のおけるディレクトリ | |
folder = "C:\Users\Takahashi\Documents\muzudho\Unity\KifuwarabeFighter2\KifuwarabeFighter2\" 'どうにかならんのか | |
oDoc = StarDesktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, Dummy()) ' ブックを新規作成 | |
oSheets = oDoc.getSheets() ' シートのリストを取得 | |
'-------------------------------------------------------------------------------- | |
' 最初からあるシートを名前変更 | |
oSheet=oDoc.Sheets(0) | |
oSheet.Name="Rensyu0" | |
'作成したシートへの書込 | |
oSheet.getCellRangeByName("A1").String= "セルへの書き込み0" | |
'-------------------------------------------------------------------------------- | |
' 2つ目のシートを作成 | |
sheetName = "Rensyu1" | |
' シートを追加 | |
if oSheets.hasByName(sheetName) = false then | |
oSheets.insertNewByName(sheetName,1) | |
end if | |
oSheet = oSheets.getByName(sheetName) | |
'作成したシートへの書込 | |
oSheet.getCellRangeByName("A1").String= "セルへの書き込み1" | |
'-------------------------------------------------------------------------------- | |
' 3つ目のシートを作成 | |
' シートの名前 | |
sheetName = "Rensyu2" | |
' シートを追加 | |
if oSheets.hasByName(sheetName) = false then | |
oSheets.insertNewByName(sheetName,2) | |
end if | |
oSheet = oSheets.getByName(sheetName) | |
'作成したシートへの書込 | |
oSheet.getCellRangeByName("A1").String= "セルへの書き込み2" | |
'-------------------------------------------------------------------------------- | |
' 4つ目のシートを作成 | |
' シートの名前 | |
sheetName = "Rensyu3" | |
' シートを追加 | |
if oSheets.hasByName(sheetName) = false then | |
oSheets.insertNewByName(sheetName,3) | |
end if | |
oSheet = oSheets.getByName(sheetName) | |
'作成したシートへの書込 | |
oSheet.getCellRangeByName("A1").String= "セルへの書き込み3" | |
'-------------------------------------------------------------------------------- | |
' 5つ目のシートを作成 | |
' シートの名前 | |
sheetName = "Rensyu4" | |
' シートを追加 | |
if oSheets.hasByName(sheetName) = false then | |
oSheets.insertNewByName(sheetName,4) | |
end if | |
oSheet = oSheets.getByName(sheetName) | |
'作成したシートへの書込 | |
oSheet.getCellRangeByName("A1").String= "セルへの書き込み4" | |
'-------------------------------------------------------------------------------- | |
' 6つ目のシートを作成 | |
' シートの名前 | |
sheetName = "Rensyu5" | |
' シートを追加 | |
if oSheets.hasByName(sheetName) = false then | |
oSheets.insertNewByName(sheetName,5) | |
end if | |
oSheet = oSheets.getByName(sheetName) | |
'作成したシートへの書込 | |
oSheet.getCellRangeByName("A1").String= "セルへの書き込み5" | |
'-------------------------------------------------------------------------------- | |
'C:test.odsとして保存 | |
oDoc.storeAsURL(ConvertToUrl( folder & "sample.ods"), Dummy()) | |
'ファイルを閉じる | |
oDoc.dispose | |
End Sub |
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
REM ***** BASIC ***** | |
Option Explicit | |
Sub Main | |
'msgbox "Hello World!!" | |
Dim oSheet as Object ' シート | |
Dim oSheets As Object ' シートのリスト | |
Dim sheetName As String ' シートの名前 | |
Dim oDoc As Object ' 新しいブック | |
Dim Dummy() ' 使わない引数に | |
Dim folder As String ' 信頼のおけるディレクトリ | |
Dim file1 As String | |
Dim file2 As String | |
Dim file3 As String | |
Dim file4 As String | |
Dim file5 As String | |
Dim file6 As String | |
Dim file7 As String | |
folder = "C:\Users\Takahashi\Documents\muzudho\Unity\KifuwarabeFighter2\KifuwarabeFighter2\" 'どうにかならんのか | |
file1 = "C:\Users\Takahashi\Documents\muzudho\Unity\KifuwarabeFighter2\KifuwarabeFighter2\_log_(AniCon@Char3)parameters.csv" 'どうにかならんのか | |
file2 = "C:\Users\Takahashi\Documents\muzudho\Unity\KifuwarabeFighter2\KifuwarabeFighter2\_log_(AniCon@Char3)layers.csv" 'どうにかならんのか | |
file3 = "C:\Users\Takahashi\Documents\muzudho\Unity\KifuwarabeFighter2\KifuwarabeFighter2\_log_(AniCon@Char3)stateMachines.csv" 'どうにかならんのか | |
file4 = "C:\Users\Takahashi\Documents\muzudho\Unity\KifuwarabeFighter2\KifuwarabeFighter2\_log_(AniCon@Char3)states.csv" 'どうにかならんのか | |
file5 = "C:\Users\Takahashi\Documents\muzudho\Unity\KifuwarabeFighter2\KifuwarabeFighter2\_log_(AniCon@Char3)transitions.csv" 'どうにかならんのか | |
file6 = "C:\Users\Takahashi\Documents\muzudho\Unity\KifuwarabeFighter2\KifuwarabeFighter2\_log_(AniCon@Char3)conditions.csv" 'どうにかならんのか | |
file7 = "C:\Users\Takahashi\Documents\muzudho\Unity\KifuwarabeFighter2\KifuwarabeFighter2\_log_(AniCon@Char3)positions.csv" 'どうにかならんのか | |
oDoc = StarDesktop.loadComponentFromURL("private:factory/scalc", "_blank", 0, Dummy()) ' ブックを新規作成 | |
oSheets = oDoc.getSheets() ' シートのリストを取得 | |
'-------------------------------------------------------------------------------- | |
' 最初からあるシートを名前変更 | |
oSheet=oDoc.Sheets(0) | |
oSheet.Name="parameters" | |
'作成したシートへの書込 | |
'oSheet.getCellRangeByName("A1").String= "セルへの書き込み0" | |
ReadCsv(file1, oSheet) ' CSV読込 | |
'-------------------------------------------------------------------------------- | |
' 2つ目のシートを作成 | |
sheetName = "layers" | |
' シートを追加 | |
if oSheets.hasByName(sheetName) = false then | |
oSheets.insertNewByName(sheetName,1) | |
end if | |
oSheet = oSheets.getByName(sheetName) | |
'作成したシートへの書込 | |
'oSheet.getCellRangeByName("A1").String= "セルへの書き込み1" | |
ReadCsv(file2, oSheet) ' CSV読込 | |
'-------------------------------------------------------------------------------- | |
' 3つ目のシートを作成 | |
' シートの名前 | |
sheetName = "stateMachines" | |
' シートを追加 | |
if oSheets.hasByName(sheetName) = false then | |
oSheets.insertNewByName(sheetName,2) | |
end if | |
oSheet = oSheets.getByName(sheetName) | |
'作成したシートへの書込 | |
'oSheet.getCellRangeByName("A1").String= "セルへの書き込み2" | |
ReadCsv(file3, oSheet) ' CSV読込 | |
'-------------------------------------------------------------------------------- | |
' 4つ目のシートを作成 | |
' シートの名前 | |
sheetName = "states" | |
' シートを追加 | |
if oSheets.hasByName(sheetName) = false then | |
oSheets.insertNewByName(sheetName,3) | |
end if | |
oSheet = oSheets.getByName(sheetName) | |
'作成したシートへの書込 | |
'oSheet.getCellRangeByName("A1").String= "セルへの書き込み3" | |
ReadCsv(file4, oSheet) ' CSV読込 | |
'-------------------------------------------------------------------------------- | |
' 5つ目のシートを作成 | |
' シートの名前 | |
sheetName = "transitions" | |
' シートを追加 | |
if oSheets.hasByName(sheetName) = false then | |
oSheets.insertNewByName(sheetName,4) | |
end if | |
oSheet = oSheets.getByName(sheetName) | |
'作成したシートへの書込 | |
'oSheet.getCellRangeByName("A1").String= "セルへの書き込み4" | |
ReadCsv(file5, oSheet) ' CSV読込 | |
'-------------------------------------------------------------------------------- | |
' 6つ目のシートを作成 | |
' シートの名前 | |
sheetName = "conditions" | |
' シートを追加 | |
if oSheets.hasByName(sheetName) = false then | |
oSheets.insertNewByName(sheetName,5) | |
end if | |
oSheet = oSheets.getByName(sheetName) | |
'作成したシートへの書込 | |
'oSheet.getCellRangeByName("A1").String= "セルへの書き込み5" | |
ReadCsv(file6, oSheet) ' CSV読込 | |
'-------------------------------------------------------------------------------- | |
' 7つ目のシートを作成 | |
' シートの名前 | |
sheetName = "positions" | |
' シートを追加 | |
if oSheets.hasByName(sheetName) = false then | |
oSheets.insertNewByName(sheetName,6) | |
end if | |
oSheet = oSheets.getByName(sheetName) | |
'作成したシートへの書込 | |
'oSheet.getCellRangeByName("A1").String= "セルへの書き込み6" | |
ReadCsv(file7, oSheet) ' CSV読込 | |
'-------------------------------------------------------------------------------- | |
'C:test.odsとして保存 | |
oDoc.storeAsURL(ConvertToUrl( folder & "sample.ods"), Dummy()) | |
'ファイルを閉じる | |
oDoc.dispose | |
End Sub | |
'-------------------------------------------------------------------------------- | |
' CSV読取 | |
Sub ReadCsv(filename As String, oSheet as Object) | |
Dim fileHandle As Integer ' ファイルハンドル番号 | |
fileHandle = Freefile | |
Open filename For Input As fileHandle ' 外部ファイルの内容をシートに読込む | |
Dim row As Integer | |
Dim source As String | |
row = 0 | |
Do While not eof(fileHandle) | |
Line Input #fileHandle, source | |
'oSheet.getCellByPosition( 0, row ).String = source | |
CsvLineParser( source, row, oSheet ) | |
row = row + 1 | |
Loop | |
Close #fileHandle | |
End Sub | |
Sub CsvLineParser(source As String, row As Integer, oSheet as Object) | |
Dim caret As Integer | |
Dim column As Integer | |
Dim cell As String | |
If Len(source) < 1 Then | |
Exit Sub | |
End If ' 空文字列なら終わり | |
caret = 1 ' 文字列の文字目は1スタート | |
column = 0 ' テーブルの列は0スタート | |
'Do While caret < Len(source) | |
' oSheet.getCellByPosition( caret, row ).String = Mid(source,caret,1) | |
' caret = caret + 1 | |
'Loop | |
'Exit Sub | |
cell = "" ' 1セル分の文字列 | |
Do While caret-1 < Len(source) ' このループで1行分に対応 | |
Select Case Mid(source,caret,1) | |
Case ",": ' トークンを出力して次へ。 | |
caret = caret + 1 | |
oSheet.getCellByPosition( column, row ).String = cell | |
column = column + 1 | |
cell = "" | |
Case """": | |
' ここからリテラル文字列処理へ | |
caret = caret + 1 | |
' エスケープしながら、単独「"」が出てくるまでそのまま出力。 | |
Do While caret-1 < Len(source) | |
If """"=Mid(source,caret,1) Then | |
' これが単独の「"」なら終わり、2連続の「"」ならまだ終わらない。 | |
If caret + 1 - 1 = Len(source) Then | |
caret = caret + 1 | |
Exit Do ' 「"」が最後の文字だったのなら、無視してループ抜け。 | |
ElseIf """" = Mid(source,caret+1,1) Then | |
caret = caret + 2 | |
cell = cell & """" ' 2文字目も「"」なら、2つの「""」すっとばして代わりに「"」を入れてループ続行。 | |
Else ' 2連続でない「"」なら、次の「,」の次までの空白等をスキップ。//【改変/】2012年10月30日変更。旧: index++;//【改変/】2017年02月01日変更。次のカンマの次まで飛ばした。旧: index+=2; | |
caret = InStr( caret, source, "," ) | |
caret = caret + 1 | |
Exit Do | |
End If | |
Else | |
cell = cell & Mid(source,caret,1) | |
caret = caret + 1 ' 通常文字なのでループ続行。 | |
End If | |
Loop | |
oSheet.getCellByPosition( column, row ).String = Trim(cell) ' 前後の空白はカット | |
column = column + 1 | |
cell = "" | |
Case Else: ' ダブルクォートされていない文字列か、ダブルクォートの前のスペースだ。 | |
cell = cell & Mid(source,caret,1) | |
caret = caret + 1 | |
End Select | |
Loop | |
End Sub |
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
' アクティブ・シートを取得 | |
oSheet = ThisComponent.GetCurrentController.ActiveSheet | |
' ( column, row ) is 0 start. | |
folder = oSheet.getCellByPosition( 5, 12 ).String ' folder. end is "\" | |
file1 = folder & oSheet.getCellByPosition( 5, 16 ).String ' parameters.csv | |
file2 = folder & oSheet.getCellByPosition( 5, 18 ).String ' layers | |
file3 = folder & oSheet.getCellByPosition( 5, 20 ).String ' stateMachines | |
file4 = folder & oSheet.getCellByPosition( 5, 22 ).String ' states | |
file5 = folder & oSheet.getCellByPosition( 5, 24 ).String ' transitions | |
file6 = folder & oSheet.getCellByPosition( 5, 26 ).String ' conditions | |
file7 = folder & oSheet.getCellByPosition( 5, 28 ).String ' positions |
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
& ADDRESS( ROW(セル番号), COLUMN(セル番号), 1, 1) |
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
ファイル名#シート名.行列番号 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment