既存のxlsファイルを読み込んで、文字列と画像を追加して、新たに保存してみる。まぁ、画像は、pngしか使えないみたい。あと、画像がセルにフィットされるので、何とかしたいな。一応、使えるみたい。
package com.marevol.test; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.util.Locale; import jxl.Workbook; import jxl.WorkbookSettings; import jxl.write.Label; import jxl.write.WritableCell; import jxl.write.WritableCellFormat; import jxl.write.WritableImage; import jxl.write.WritableSheet; import jxl.write.WritableWorkbook; public class App { public static void main(String[] args) { String templateName = args[0]; String outputName = args[1]; String imageName = args[2]; String labelString = args[3]; WritableWorkbook workbook = null; try { // Setup workbook WorkbookSettings ws = new WorkbookSettings(); ws.setLocale(Locale.JAPAN); ws.setEncoding("Windows-31J"); // Load workbook Workbook template = Workbook.getWorkbook(new FileInputStream( templateName)); // Create new workbook workbook = Workbook.createWorkbook( new FileOutputStream(outputName), template, ws); // Create new sheet WritableSheet sheet = workbook.getSheet(0); // Create new label Label label = new Label(1, 0, labelString); sheet.addCell(label); // Create new image WritableImage image = new WritableImage(1, 1, 1, 1, new File( imageName)); sheet.addImage(image); // Write wookbook workbook.write(); } catch (Exception e) { e.printStackTrace(); } finally { if (workbook != null) { try { workbook.close(); } catch (Exception e) { e.printStackTrace(); } } } } }