Skip to content

Instantly share code, notes, and snippets.

@xnrghzjh
xnrghzjh / DisableExcelVersionCheck
Created June 28, 2011 03:56
Excel2007,2010でxlsファイルを保存する時に出る互換性チェクを無効にする。
import org.codehaus.groovy.scriptom.*
Scriptom.inApartment
{
excel = new ActiveXObject('Excel.Application')
fileList = ["Book1.xls"] // TODO:カレントからxlsファイルを取得する処理
fileList.each() {
book = excel.workbooks.open(new File(it).canonicalPath)
book.CheckCompatibility = false
@xnrghzjh
xnrghzjh / StepMonth.groovy
Created June 21, 2011 08:11
Dateをstep()
/**
Calendarのメタクラスにできてない
*/
def toDate = { Date.parse('yyyy/MM/dd', it) }
def toStr = { it.format('yy/MM') }
GregorianCalendar.metaClass.getThenStep = {
cur = delegate.getTime()
// delegate.add(Calendar.MONTH, it)
// cur
@xnrghzjh
xnrghzjh / GenocideExcel.groovy
Created June 20, 2011 08:03
Excelプロセスを強制終了(wsfから移植)
/**
 Excel.exeが残ってしまった時用
*/
import org.codehaus.groovy.scriptom.*
def name = "EXCEL.EXE"
Scriptom.inApartment
{
@xnrghzjh
xnrghzjh / StepMethod.groovy
Created June 18, 2011 06:48
stepメソッドの展開
import org.codehaus.groovy.runtime.*
println "オリジナル"
1.step(5,1) {print "$it "}
println ""
println "AST Browser 上"
1.step(5, 1, {this.print("$it ")})
println ""
@xnrghzjh
xnrghzjh / createFiscalInfo.groovy
Created June 17, 2011 09:26
決算開始月から1年間のデータを作成
/**
課題:ループが多い、なんか違う
*/
def toDate = { Date.parse('yyyy/MM/dd', it) }
Date.metaClass.createMonthRange = {
cal = Calendar.getInstance()
range = []
(delegate..it).each() {
@xnrghzjh
xnrghzjh / MoveToDateFolder.groovy
Created June 17, 2011 02:41
指定した拡張子のファイルを生成日のフォルダに移動(wsfから移植)
/**
課題 拡張子を取得する処理を簡略化、
クロージャ内でクロージャが呼べない
なんか遅い
*/
import javax.swing.*
// 移動対象
def folderPath = "."
@xnrghzjh
xnrghzjh / getSelectedButtonCaption.groovy
Created June 16, 2011 01:24
ボタングループから選択されているラジオボタンのキャプションを取得(Groovy)
import javax.swing.*
ButtonGroup.metaClass.getSelectedButtonCaption() {
caption = ""
delegate.getElements().each { if (it.isSelected()) caption = it.getText() }
caption
}
// 実行
buttonGroup = new ButtonGroup()
buttonGroup.add(new JRadioButton("Button1"))
@xnrghzjh
xnrghzjh / getSelectedButtonCaption.java
Created June 16, 2011 01:01
ボタングループから選択されているラジオボタンのキャプションを取得
private buttonGroup = new javax.swing.ButtonGroup();
private button1 = new javax.swing.JRadioButton();
private button2 = new javax.swing.JRadioButton();
private button3 = new javax.swing.JRadioButton();
buttonGroup.add(button1);
buttonGroup.add(button2);
buttonGroup.add(button3);
public String getSelectedButtonCaption() {
@xnrghzjh
xnrghzjh / VirtualBoxControl
Created June 15, 2011 00:34
VirtualBoxの仮想マシンを非表示で管理(wsfから移植)
import javax.swing.*;
// VirtualBoxのパス
path = "C:\\Program Files\\Oracle\\VirtualBox\\"
// 仮想マシンのリスト
list = ['RedMine', 'DokuWiki']
// 引数チェック
if (args.size() == 0) {
@xnrghzjh
xnrghzjh / StopWatch.groovy
Created June 14, 2011 09:23
ストップウォッチ
class StopWatch {
def lapTimes = []
def startTime
def stopTime
def cur = { System.currentTimeMillis() }
def start = { startTime = cur() }
def stop = { stopTime = cur() }
def elapsedTime = { stopTime - startTime }
def elapsedLapTime = { lapTimes[it].time - startTime }