Created
July 16, 2010 04:44
-
-
Save masanobuimai/477931 to your computer and use it in GitHub Desktop.
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
import org.codehaus.groovy.scriptom.* | |
import org.codehaus.groovy.scriptom.tlb.office.* | |
import org.codehaus.groovy.scriptom.tlb.office.excel.* | |
import org.codehaus.groovy.scriptom.tlb.office.word.WdSaveOptions | |
def waitTime = 10000 | |
Scriptom.inApartment { | |
def dir = new File("c:/temp") | |
def xlApp = new ActiveXObject('Excel.Application') | |
def wdApp = new ActiveXObject('Word.Application') | |
def pdfApp = new ActiveXObject('Bullzip.PDFPrinterSettings') | |
if (!(xlApp.ActivePrinter ==~ /Bullzip PDF Printer.*/)) return | |
println xlApp.ActivePrinter | |
dir.eachFile { file -> | |
def filename = file.name.replaceAll(/(.*)(\..+$)/) { full, m1, m2 -> m1 } | |
pdfApp.with { | |
setValue("output", "${dir.path}\\${filename}.pdf") | |
setValue("confirmoverwrite", "no") | |
setValue("showpdF", "no") | |
setValue("showsettings", "never") | |
writeSettings(true) | |
} | |
def document | |
switch (file.canonicalPath) { | |
case ~/.*\.xls$/ : // Excel | |
println " >> ${file.canonicalPath}" | |
def workbook = xlApp.workbooks.Open(file.canonicalPath) | |
workbook.printOut() | |
sleep(waitTime) | |
workbook.close(false, false) | |
break; | |
case ~/.*\.doc$/ : // Word | |
println " >> ${file.canonicalPath}" | |
def doc = wdApp.documents.Open(file.canonicalPath) | |
doc.printOut() | |
sleep(waitTime) | |
doc.close(WdSaveOptions.wdDoNotSaveChanges, false) | |
break; | |
} | |
} | |
xlApp.quit() | |
wdApp.quit() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment