#module
*xlerror
dialog "エラーが発生した為、終了します", 1
xlQuit
end
#deffunc xlInit int hide
onerror *xlerror
newcom xlApp, "Excel.Application"
xlApp("Visible") = (hide = 0)
xlApp("DisplayAlerts") = 0
xlBooks = xlApp("WorkBooks")
return
#deffunc xlOpen str fname, int readonly, int format, local s, local key
s = fname : key = ""
if instr(s, , "|") ! -1 : split s, "|", s, key
xlBooks -> "Open" s, , readonly, (format = 0) * 1 + format, key // フォーマット未指定時はタブ
xlBook = xlBooks("Item", getpath(s, 8))
xlSheet = xlBook("ActiveSheet")
return 1
#deffunc xlClose int save
xlBook -> "Close" save
return
#deffunc xlQuit
if vartype(xlSheet) = vartype("comobj") : delcom xlSheet
if vartype(xlBook) = vartype("comobj") : delcom xlBook
if vartype(xlBooks) = vartype("comobj") : xlBooks -> "Close" : delcom xlBooks
if vartype(xlApp) = vartype("comobj") : xlApp -> "Quit" : delcom xlApp
return
#defcfunc xlGetBookNum
return xlBooks("Count") // ブック総数取得
#defcfunc xlGetBookName
if xlGetBookNum() < 1 : return ""
return xlBook("FullName") // フルパスを返す
#deffunc xlSaveAs str fname, int format, local s, local key
s = fname : key = ""
if instr(s, , "|") ! -1 : split s, "|", s, key
xlBook -> "SaveAs" s, (format = 0) * -4143 + format, key // フォーマット未指定時は通常xls形式
return
#deffunc xlSave local s
s = xlGetBookName()
if instr(s, , ":") = 1 { // 1文字目がコロンのときはファイルパスとして処理
xlBook -> "Save"
} else {
xlSaveAs strf("%s\\%s.xls", dir_cur, s)
}
return
#global
pass = "hspbc"
gsel 0, 2
mes "パスワードが掛かってない通常のxlsファイルを指定してください。"
wait 100
dialog "xls", 16, "読込対象xlsファイル"
if stat = 0 : end
xlInit
xlOpen refstr
wait 100
mes "開いたファイルをパスワード付で保存しますので保存先を指定してください。"
wait 100
dialog "xls", 17, "書込対象xlsファイル"
if stat {
file = strf("%s|%s", refstr, pass)
xlSaveAs file
xlClose
mes strf("%sとして保存しました。パスワードは%sとなります。", refstr, pass)
wait 100
mes "パスワード付ファイルが開けるかを確認します。"
wait 100
xlOpen file
wait 300
mes "開けることを確認できましたので終了します。"
} else {
mes "保存を中止しました。"
}
wait 100
xlQuit
end
|