Excelの「縮小して全体を表示する」をPOIで指定できるようにするパッチ

元ねたはここ
パッチ自体はアスペクトで当てるほうがエレガント(だと個人的に思う)なので、
AspectJで記述。

package jp.gr.java_conf.e_yamane.apache.poi;

import org.apache.commons.beanutils.BeanUtils;
import org.apache.poi.hssf.record.ExtendedFormatRecord;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;

public privileged aspect HSSFCellStyleAspect{
    public ExtendedFormatRecord HSSFCellStyle.getFormat() {
        return format;
    }
    public void HSSFCellStyle.setFormat(ExtendedFormatRecord record) {
        try {
            BeanUtils.copyProperties(format, record);
        } catch(Exception e) {
            throw new RuntimeException(e);
        }
    }
}

別にsetは無くても良いんだけど、有ると以下のような処理を行うときに便利。
1.テンプレートのExcelを読込む
2.テンプレートのセルをコピーする
3.コピーしたセルだけ色を変える(とか、とにかく個別にスタイルを変更するようなケース)
こういう場合は、
HSSFCellStyle style = HSSFWorkbook.createCellStyle();
BeanUtils.copyProperties(style, originalStyle);
のように一気にいける。

でも、フォントの変更はこの方法では無理。

POIはAPI的には非常に使いにくい。
バージョンアップしてほしいんだけど、1年以上停滞中(T_T)
生産性悪過ぎ!!