package soft;
import java.io.FileOutputStream;
import java.util.Date;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
import org.apache.poi.ss.usermodel.CreationHelper;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
public class Soft{
public static void main(String[] args) throws Exception {
Workbook wb = new HSSFWorkbook();
Sheet sheet = wb.createSheet("これ");
Row row = sheet.createRow(0);
Cell cell = row.createCell(0);
cell.setCellValue("pp");
sheet.createRow(1).createCell(1).setCellValue(12345);
Cell dateCell = sheet.createRow(2).createCell(2);
CellStyle cellStyle = wb.createCellStyle();
CreationHelper helper = wb.getCreationHelper();
short format = helper.createDataFormat().getFormat("yyyy/mm/dd");
cellStyle.setDataFormat(format);
dateCell.setCellStyle(cellStyle);
dateCell.setCellValue(new Date());
sheet.setColumnWidth(2, 10 * 256);
Cell borderedCell = sheet.createRow(3).createCell(3);
borderedCell.setCellValue("罫線付き");
CellStyle borderStyle = wb.createCellStyle();
borderStyle.setBorderBottom(CellStyle.BORDER_THIN);
borderStyle.setBottomBorderColor(IndexedColors.BLACK.getIndex());
borderStyle.setBorderLeft(CellStyle.BORDER_MEDIUM);
borderStyle.setLeftBorderColor(IndexedColors.RED.getIndex());
borderedCell.setCellStyle(borderStyle);
output(wb);
}
private static void output(Workbook wb) throws Exception {
FileOutputStream fos = new FileOutputStream("sample.xls");
wb.write(fos);
fos.close();
}
}
最終更新:2011年08月20日 21:27