ExCella Reports1.4のライブラリを使用し帳票・Excelのファイルで行方向にブロック単位で繰り返し出力します。
※ブロック単位がネストされた場合。
【手順】
1.「Javaプロジェクトの作成方法」の手順で、「ExCellaSample037-BlockRowRepeatNestedBlockRowRepeat」といプロジェクトを作成。
2.「excella-reports-1.4.jarとそれに依存ライブラリを設定する方法」の手順で、プロジェクトにExCella Reports1.4とそれに依存するライブラリを追加。
3.「BlockRowRepeatNestedBlockRowRepeatNestedBlockRowRepeat.xls」という名前の、以下の様なテンプレートファイルを作成し、「ExCellaSample037-BlockRowRepeatNestedBlockRowRepeat」直下に配置。
4.「Javaクラスファイルの作成方法」の手順で、「Main」というクラスを作成。
5.「Main.java」を以下の様に入力。
import java.util.ArrayList;
import java.util.List;
import org.bbreak.excella.reports.exporter.ExcelExporter;
import org.bbreak.excella.reports.model.ParamInfo;
import org.bbreak.excella.reports.model.ReportBook;
import org.bbreak.excella.reports.model.ReportSheet;
import org.bbreak.excella.reports.processor.ReportProcessor;
import org.bbreak.excella.reports.tag.BlockColRepeatParamParser;
import org.bbreak.excella.reports.tag.BlockRowRepeatParamParser;
import org.bbreak.excella.reports.tag.SingleParamParser;
public class Main {
public static void main(String[] args) throws Exception {
String templateFilePath = "BlockRowRepeatNestedBlockRowRepeatTemplate.xls";
String outputFileName = "BlockRowRepeatNestedBlockRowRepeat";
String outputFileDir = "";
String outputFilePath = outputFileDir.concat(outputFileName);
ReportBook outputBook = new ReportBook(templateFilePath,
outputFilePath, ExcelExporter.FORMAT_TYPE);
ReportSheet outputSheet = new ReportSheet("TemplateSheet", "Sheet1");
outputBook.addReportSheet(outputSheet);
List<ParamInfo> personList = new ArrayList<ParamInfo>();
personList.add(createNameData("あいうえお", "男", "21"));
personList.add(createNameData("かきくけこ", "女", "28"));
personList.add(createNameData("さしすせそ", "男", "32"));
outputSheet.addParam(BlockRowRepeatParamParser.DEFAULT_TAG, "参加者", personList.toArray(new ParamInfo[personList.size()]));
ReportProcessor reportProcessor = new ReportProcessor();
reportProcessor.process(outputBook);
}
private static ParamInfo createNameData(String name, String gendar, String age) {
ParamInfo nameData = new ParamInfo();
nameData.addParam(SingleParamParser.DEFAULT_TAG, "名前", name);
nameData.addParam(SingleParamParser.DEFAULT_TAG, "性別", gendar);
nameData.addParam(SingleParamParser.DEFAULT_TAG, "年齢", age);
List<ParamInfo> attributeList = new ArrayList<ParamInfo>();
attributeList.add(createAttributeData("A", "B"));
attributeList.add(createAttributeData("M", "N"));
attributeList.add(createAttributeData("Y", "Z"));
nameData.addParam(BlockColRepeatParamParser.DEFAULT_TAG, "属性", attributeList.toArray(new ParamInfo[attributeList.size()]));
return nameData;
}
private static ParamInfo createAttributeData(String attribute1, String attribute2) {
ParamInfo attributeData = new ParamInfo();
attributeData.addParam(SingleParamParser.DEFAULT_TAG, "属性1", attribute1);
attributeData.addParam(SingleParamParser.DEFAULT_TAG, "属性2", attribute2);
return attributeData;
}
}
6.「Ctrl+Shift+O」を押し、パッケージのインポート文を補完。7.「Ctrl+Shift+F」を押し、ソースコードをフォーマッティング。
8.「Javaプロジェクトの実行方法」の手順で、「Main.java」を実行。
9.コンソールにエラーが出力されていないか確認。
(※コンソールが表示されていない場合は、「コンソール・ビューの表示方法」を確認)
10.「リフレッシュ(ローカルファイルとの同期)の方法」の手順で、プロジェクトをリフレッシュ。
11.「ExCellaSample037-BlockRowRepeatNestedBlockRowRepeat/BlockRowRepeatNestedBlockRowRepeat.xls」が作成されています。
12.「ExCellaSample037-BlockRowRepeatNestedBlockRowRepeat/BlockRowRepeatNestedBlockRowRepeat.xls」をダブルクリック。
13.「BlockRowRepeatNestedBlockRowRepeat.xls」が以下の様に開けば成功です。
以上です。
-01.png)
-02.png)
0 件のコメント:
コメントを投稿
注: コメントを投稿できるのは、このブログのメンバーだけです。