ForNext
Only Do What Only You Can Do
Access の Report を 印刷する
VBScript
更新日 : 2012.06.21
Option Explicit Const acOutputReport = 3 Const acViewPreview = 2 Const acFormatXLS = "Microsoft Excel (*.xls)" Const acFormatRTF = "Rich Text Format (*.rtf)" Const acFormatSNP = "Snapshot Format (*.snp)" Const acFormatHTML = "HTML (*.html)" Dim acApp: Set acApp = CreateObject("Access.Application") acApp.OpenCurrentDatabase WScript.Arguments(0) acApp.Visible = True Dim strReportName: strReportName = WScript.Arguments(1) With acApp With .DoCmd Select Case UCase(WScript.Arguments(3)) Case "XLS" .OutputTo acOutputReport, strReportName, acFormatXLS, WScript.Arguments(2) & "autoxls.xls", True Case "RTF" .OutputTo acOutputReport, strReportName, acFormatRTF, WScript.Arguments(2) & "autortf.rtf", True Case "SNAP" .OutputTo acOutputReport, strReportName, acFormatSNP, WScript.Arguments(2) & "autosnap.snp", True Case "HTML" .OutputTo acOutputReport, strReportName, acFormatHTML, WScript.Arguments(2) & "autohtml.htm", True Case Else .OpenReport strReportName, acViewPreview End Select End With End With Select Case UCase(WScript.Arguments(3)) Case "XLS", "RTF", "SNAP", "HTML" acApp.Quit End Select Set acApp = Nothing '実行形式 'cscript //nologo OpenReport.vbs "s:\test.mdb" "test_report" "s:\" "XLS" 'cscript //nologo OpenReport.vbs "s:\test.mdb" "test_report" "s:\" "RTF" 'cscript //nologo OpenReport.vbs "s:\test.mdb" "test_report" "s:\" "SNAP" 'cscript //nologo OpenReport.vbs "s:\test.mdb" "test_report" "s:\" "HTML" 'cscript //nologo OpenReport.vbs "s:\test.mdb" "test_report" "" ""
JScript
更新日 : 2012.06.22
var acOutputReport = 3; var acViewPreview = 2; var acFormatXLS = "Microsoft Excel (*.xls)"; var acFormatRTF = "Rich Text Format (*.rtf)"; var acFormatSNP = "Snapshot Format (*.snp)"; var acFormatHTML = "HTML (*.html)"; var acApp = WScript.CreateObject("Access.Application"); acApp.OpenCurrentDatabase(WScript.Arguments(0)); acApp.Visible = true; var strReportName = WScript.Arguments(1); with (acApp) { with (DoCmd) { switch (WScript.Arguments(3).toUpperCase()) { case "XLS": OutputTo(acOutputReport, strReportName, acFormatXLS, WScript.Arguments(2) + "autoxls.xls", true); break; case "RTF": OutputTo(acOutputReport, strReportName, acFormatRTF, WScript.Arguments(2) + "autortf.rtf", true); break; case "SNAP": OutputTo(acOutputReport, strReportName, acFormatSNP, WScript.Arguments(2) + "autosnap.snp", true); break; case "HTML": OutputTo(acOutputReport, strReportName, acFormatHTML, WScript.Arguments(2) + "autohtml.htm", true); break; default: OpenReport(strReportName, acViewPreview); } } } switch (WScript.Arguments(3).toUpperCase()) { case "XLS": case "RTF": case "SNAP": case "HTML": acApp.Quit(); } //実行形式 //cscript //nologo OpenReport.js "s:\test.mdb" "test_report" "s:\" "XLS" //cscript //nologo OpenReport.js "s:\test.mdb" "test_report" "s:\" "RTF" //cscript //nologo OpenReport.js "s:\test.mdb" "test_report" "s:\" "SNAP" //cscript //nologo OpenReport.js "s:\test.mdb" "test_report" "s:\" "HTML" //cscript //nologo OpenReport.js "s:\test.mdb" "test_report" "" ""
Perl
更新日 : 2012.06.21
use Win32::OLE; use constant AcOutputReport => 3; use constant AcViewPreview => 2; use constant AcFormatXLS => "Microsoft Excel (*.xls)"; use constant AcFormatRTF => "Rich Text Format (*.rtf)"; use constant AcFormatSNP => "Snapshot Format (*.snp)"; use constant AcFormatHTML => "HTML (*.html)"; Win32::OLE::CreateObject("Access.Application", $acApp); $acApp->OpenCurrentDatabase($ARGV[0]); $acApp->{Visible} = 1; $strReportName = $ARGV[1]; if (uc($ARGV[3]) eq "XLS") { $acApp->DoCmd->OutputTo(AcOutputReport, $strReportName, AcFormatXLS, $ARGV[2] . "autoxls.xls", 1); } elsif (uc($ARGV[3]) eq "RTF") { $acApp->DoCmd->OutputTo(AcOutputReport, $strReportName, AcFormatRTF, $ARGV[2] . "autortf.rtf", 1); } elsif (uc($ARGV[3]) eq "SNAP") { $acApp->DoCmd->OutputTo(AcOutputReport, $strReportName, AcFormatSNP, $ARGV[2] . "autosnap.snp", 1); } elsif (uc($ARGV[3]) eq "HTML") { $acApp->DoCmd->OutputTo(AcOutputReport, $strReportName, AcFormatHTML, $ARGV[2] . "autohtml.htm", 1); } else { $acApp->DoCmd->OpenReport($strReportName, AcViewPreview); } if (uc($ARGV[3]) eq "XLS" || uc($ARGV[3]) eq "RTF" || uc($ARGV[3]) eq "SNAP" || uc($ARGV[3]) eq "HTML") { $acApp->Quit(); } #実行形式 #perl OpenReport.pl "s:\test.mdb" "test_report" "s:\" "XLS" #perl OpenReport.pl "s:\test.mdb" "test_report" "s:\" "RTF" #perl OpenReport.pl "s:\test.mdb" "test_report" "s:\" "SNAP" #perl OpenReport.pl "s:\test.mdb" "test_report" "s:\" "HTML" #perl OpenReport.pl "s:\test.mdb" "test_report" "" ""
PHP
更新日 : 2012.06.21
<?php define("AcOutputReport", 3); define("AcViewPreview", 2); define("AcFormatXLS", "Microsoft Excel (*.xls)"); define("AcFormatRTF", "Rich Text Format (*.rtf)"); define("AcFormatSNP", "Snapshot Format (*.snp)"); define("AcFormatHTML", "HTML (*.html)"); $acApp = new COM("Access.Application"); $acApp->OpenCurrentDatabase($argv[1]); $acApp->Visible = true; $strReportName = $argv[2]; if (strtoupper($argv[4]) == "XLS") { $acApp->DoCmd->OutputTo(AcOutputReport, $strReportName, AcFormatXLS, $argv[3] . "autoxls.xls", 1); } elseif (strtoupper($argv[4]) == "RTF") { $acApp->DoCmd->OutputTo(AcOutputReport, $strReportName, AcFormatRTF, $argv[3] . "autortf.rtf", 1); } elseif (strtoupper($argv[4]) == "SNAP") { $acApp->DoCmd->OutputTo(AcOutputReport, $strReportName, AcFormatSNP, $argv[3] . "autosnap.snp", 1); } elseif (strtoupper($argv[4]) == "HTML") { $acApp->DoCmd->OutputTo(AcOutputReport, $strReportName, AcFormatHTML, $argv[3] . "autohtml.htm", 1); } else { $acApp->DoCmd->OpenReport($strReportName, AcViewPreview); } if (strtoupper($argv[4]) == "XLS" || strtoupper($argv[4]) == "RTF" || strtoupper($argv[4]) == "SNAP" || strtoupper($argv[4]) == "HTML") { $acApp->Quit(); } #実行形式 #php OpenReport.php "s:\test.mdb" "test_report" "s:\" "XLS" #php OpenReport.php "s:\test.mdb" "test_report" "s:\" "RTF" #php OpenReport.php "s:\test.mdb" "test_report" "s:\" "SNAP" #php OpenReport.php "s:\test.mdb" "test_report" "s:\" "HTML" #php OpenReport.php "s:\test.mdb" "test_report" "" "" ?>
Python
更新日 : 2012.06.21
# coding: Shift_JIS import win32api, win32con, win32com, win32com.client, os, time, sys acOutputReport = 3 acViewPreview = 2 acFormatXLS = "Microsoft Excel (*.xls)" acFormatRTF = "Rich Text Format (*.rtf)" acFormatSNP = "Snapshot Format (*.snp)" acFormatHTML = "HTML (*.html)" acApp = win32com.client.Dispatch("Access.Application") acApp.OpenCurrentDatabase(sys.argv[1]) acApp.Visible = True strReportName = sys.argv[2] if (sys.argv[4].upper() == "XLS"): acApp.DoCmd.OutputTo(acOutputReport, strReportName, acFormatXLS, sys.argv[3] + "autoxls.xls", true) elif (sys.argv[4].upper() == "RTF"): acApp.DoCmd.OutputTo(acOutputReport, strReportName, acFormatRTF, sys.argv[3] + "autortf.rtf", true) elif (sys.argv[4].upper() == "SNAP"): acApp.DoCmd.OutputTo(acOutputReport, strReportName, acFormatSNP, sys.argv[3] + "autosnap.snp", true) elif (sys.argv[4].upper() == "HTML"): acApp.DoCmd.OutputTo(acOutputReport, strReportName, acFormatHTML, sys.argv[3] + "autohtml.htm", true) else: acApp.DoCmd.OpenReport(strReportName, acViewPreview) if (sys.argv[4].upper() == "XLS") or (sys.argv[4].upper() == "RTF") or (sys.argv[4].upper() == "SNAP") or (sys.argv[4].upper() == "HTML"): acApp.Quit #実行形式 #python OpenReport.py "s:\test.mdb" "test_report" "s:\" "XLS" #python OpenReport.py "s:\test.mdb" "test_report" "s:\" "RTF" #python OpenReport.py "s:\test.mdb" "test_report" "s:\" "SNAP" #python OpenReport.py "s:\test.mdb" "test_report" "s:\" "HTML" #python OpenReport.py "s:\test.mdb" "test_report" "" ""
Ruby
更新日 : 2012.06.20
require 'win32ole' AcOutputReport = 3 AcViewPreview = 2 AcFormatXLS = "Microsoft Excel (*.xls)" AcFormatRTF = "Rich Text Format (*.rtf)" AcFormatSNP = "Snapshot Format (*.snp)" AcFormatHTML = "HTML (*.html)" acApp = WIN32OLE.new('Access.Application') acApp.OpenCurrentDatabase(ARGV[0]) acApp.Visible = true strReportName = ARGV[1] case ARGV[3].upcase when "XLS" acApp.DoCmd.OutputTo(AcOutputReport, strReportName, AcFormatXLS, ARGV[2] + "autoxls.xls", true) when "RTF" acApp.DoCmd.OutputTo(AcOutputReport, strReportName, AcFormatRTF, ARGV[2] + "autortf.rtf", true) when "SNAP" acApp.DoCmd.OutputTo(AcOutputReport, strReportName, AcFormatSNP, ARGV[2] + "autosnap.snp", true) when "HTML" acApp.DoCmd.OutputTo(AcOutputReport, strReportName, AcFormatHTML, ARGV[2] + "autohtml.htm", true) else acApp.DoCmd.OpenReport(strReportName, AcViewPreview) end case ARGV[3].upcase when "XLS", "RTF", "SNAP", "HTML" acApp.Quit end #実行形式 #ruby OpenReport.rb "s:\test.mdb" "test_report" "s:\" "XLS" #ruby OpenReport.rb "s:\test.mdb" "test_report" "s:\" "RTF" #ruby OpenReport.rb "s:\test.mdb" "test_report" "s:\" "SNAP" #ruby OpenReport.rb "s:\test.mdb" "test_report" "s:\" "HTML" #ruby OpenReport.rb "s:\test.mdb" "test_report" "" ""
PowerShell
更新日 : 2012.06.22
$acOutputReport = 3 $acViewPreview = 2 $acFormatXLS = "Microsoft Excel (*.xls)" $acFormatRTF = "Rich Text Format (*.rtf)" $acFormatSNP = "Snapshot Format (*.snp)" $acFormatHTML = "HTML (*.html)" $ac = New-Object -ComObject Access.application $ac.OpenCurrentDatabase($args[0]) $ac.Visible = $true $strReportName = $args[1] if ($args[3] -eq $null) { $ac.DoCmd.OpenReport($strReportName, $acViewPreview) } else { switch ($args[3].ToUpper()) { "XLS" { $ac.DoCmd.OutputTo($acOutputReport, $strReportName, $acFormatXLS, $args[2] + "autoxls.xls", $true) } "RTF" { $ac.DoCmd.OutputTo($acOutputReport, $strReportName, $acFormatRTF, $args[2] + "autortf.rtf", $true) } "SNAP" { $ac.DoCmd.OutputTo($acOutputReport, $strReportName, $acFormatSNP, $args[2] + "autortf.snp", $true) } "HTML" { $ac.DoCmd.OutputTo($acOutputReport, $strReportName, $acFormatHTML, $args[2] + "autortf.html", $true) } default { $ac.DoCmd.OpenReport($strReportName, $acViewPreview) } } if ($args[3].ToUpper() -eq "XLS" -or $args[3].ToUpper() -eq "RTF" -or $args[3].ToUpper() -eq "SNAP" -or $args[3].ToUpper() -eq "HTML") { $ac.Quit() } } #実行形式 #powershell OpenReport.ps1 "s:\test.mdb" "test_report" "s:\" "XLS" #powershell OpenReport.ps1 "s:\test.mdb" "test_report" "s:\" "RTF" #powershell OpenReport.ps1 "s:\test.mdb" "test_report" "s:\" "SNAP" #powershell OpenReport.ps1 "s:\test.mdb" "test_report" "s:\" "HTML" #powershell OpenReport.ps1 "s:\test.mdb" "test_report" "" ""