01: package com.technoetic.xplanner.importer.spreadsheet;
02:
03: import java.io.IOException;
04: import java.io.OutputStream;
05: import java.util.Date;
06: import java.util.List;
07:
08: import com.technoetic.xplanner.importer.SpreadsheetStory;
09: import org.apache.poi.hssf.usermodel.*;
10:
11: /*
12: * $Header$
13: * $Revision: 540 $
14: * $Date: 2005-06-07 07:03:50 -0500 (Tue, 07 Jun 2005) $
15: *
16: * Copyright (c) 1999-2002 Jacques Morel. All rights reserved.
17: * Released under the Apache Software License, Version 1.1
18: */
19:
20: public class SpreadsheetStoryWriter implements CookbookFields {
21: OutputStream output;
22: public static final String END_DATE_HEADER = "Iteration End Date";
23: public static final String TITLE_HEADER = "Feature/Story Title";
24: public static final String STATUS_HEADER = "Status";
25: public static final String PRIORITY_HEADER = "Priority (1 thru n)";
26: public static final String ESTIMATE_HEADER = "Work Unit Estimate";
27:
28: public SpreadsheetStoryWriter(OutputStream stream) {
29: output = stream;
30: }
31:
32: public void writeStories(List stories) throws IOException {
33: //assert stories != null;
34:
35: HSSFWorkbook wb = new HSSFWorkbook();
36: HSSFSheet sheet = wb.createSheet("Features");
37: writeHeader(sheet);
38: for (int i = 0; i < stories.size(); i++) {
39: SpreadsheetStory spreadsheetStory = (SpreadsheetStory) stories
40: .get(i);
41: writeStory(sheet, spreadsheetStory, i + 1);
42: }
43: wb.write(output);
44: output.close();
45: }
46:
47: private void writeStory(HSSFSheet sheet,
48: SpreadsheetStory spreadsheetStory, int i) {
49: HSSFRow row = sheet.createRow(i);
50: setCellValue(row, STORY_END_DATE_COL, spreadsheetStory
51: .getEndDate());
52: setCellValue(row, TITLE_COL, spreadsheetStory.getTitle());
53: setCellValue(row, STATUS_COL, spreadsheetStory.getStatus());
54: setCellValue(row, STORY_PRIORITY_COL, spreadsheetStory
55: .getPriority());
56: setCellValue(row, ESTIMATE_NUMBER_COL, spreadsheetStory
57: .getEstimate());
58: }
59:
60: private void writeHeader(HSSFSheet sheet) {
61: HSSFRow row = sheet.createRow(0);
62: setCellValue(row, STORY_END_DATE_COL, END_DATE_HEADER);
63: setCellValue(row, TITLE_COL, TITLE_HEADER);
64: setCellValue(row, STATUS_COL, STATUS_HEADER);
65: setCellValue(row, STORY_PRIORITY_COL, PRIORITY_HEADER);
66: setCellValue(row, ESTIMATE_NUMBER_COL, ESTIMATE_HEADER);
67: }
68:
69: private void setCellValue(HSSFRow row, int col, Date date) {
70: HSSFCell cell = row.createCell((short) col);
71: cell.setCellValue(date);
72: }
73:
74: private void setCellValue(HSSFRow row, int col, int value) {
75: HSSFCell cell = row.createCell((short) col);
76: cell.setCellValue(value);
77: }
78:
79: private void setCellValue(HSSFRow row, int col, double value) {
80: HSSFCell cell = row.createCell((short) col);
81: cell.setCellValue(value);
82: }
83:
84: private void setCellValue(HSSFRow row, int col, String value) {
85: HSSFCell cell = row.createCell((short) col);
86: cell.setCellValue(value);
87: }
88: }
|