Project: Seam
Revision: 8843
Author: nickarls
Date: 28 Aug 2008 16:49:59
Changes:Support for worksheet level headers/footers and for column data footers
Files:modified: /trunk/src/excel/org/jboss/seam/excel/ExcelWorkbook.java (
try)
modified: /trunk/src/excel/org/jboss/seam/excel/ui/ExcelComponent.java (
try)
modified: /trunk/src/excel/org/jboss/seam/excel/exporter/ExcelExporter.java (
try)
modified: /trunk/src/excel/org/jboss/seam/excel/csv/CsvExcelWorkbook.java (
try)
modified: /trunk/src/excel/org/jboss/seam/excel/ui/UIWorksheet.java (
try)
modified: /trunk/doc/Seam_Reference_Guide/en-US/Excel.xml (
try)
modified: /trunk/src/excel/org/jboss/seam/excel/ui/UIColumn.java (
try)
modified: /trunk/src/excel/org/jboss/seam/excel/ui/UIWorkbook.java (
try)
modified: /trunk/src/excel/org/jboss/seam/excel/jxl/JXLExcelWorkbook.java (
try)
Diff:
| ... | ...@@ -79,4 +79,18 @@ |
| 79 | 79 | * @param command The command to execute
|
| 80 | 80 | */
|
| 81 | 81 | public abstract void executeCommand(Command command);
|
| 82 |
|
| 83 | /**
|
| 84 | * Places an item in the worksheet header
|
| 85 | *
|
| 86 | * @param item The item to add
|
| 87 | */
|
| 88 | public abstract void addWorksheetHeader(WorksheetItem item);
|
| 89 |
|
| 90 | /**
|
| 91 | * Places an item in the worksheet footer
|
| 92 | *
|
| 93 | * @param item The item to add
|
| 94 | */
|
| 95 | public abstract void addWorksheetFooter(WorksheetItem item);
|
| 82 | 96 | } |
| 83 | 97 | \ No newline at end of file |
| ... | ...@@ -29,7 +29,6 @@ |
| 29 | 29 | */ |
| 30 | 30 | public abstract class ExcelComponent extends UIComponentBase |
| 31 | 31 | { |
| 32 | | public final static String HEADER_FACET = "header"; |
| 33 | 32 | private static final String DEFAULT_CONTENT_TYPE = "text/html"; |
| 34 | 33 | private static final String DEFAULT_CHARACTER_ENCODING = "utf-8"; |
| 35 | 34 | |
| ... | ...@@ -28,6 +28,8 @@ |
| 28 | 28 | import org.jboss.seam.excel.ui.UIColumn;
|
| 29 | 29 | import org.jboss.seam.excel.ui.UIWorkbook;
|
| 30 | 30 | import org.jboss.seam.excel.ui.UIWorksheet;
|
| 31 | import org.jboss.seam.log.Log;
|
| 32 | import org.jboss.seam.log.Logging;
|
| 31 | 33 | import org.jboss.seam.navigation.Pages;
|
| 32 | 34 |
|
| 33 | 35 | /**
|
| ... | ...@@ -150,6 +152,17 @@ |
| 150 | 152 | processOutputs(headerOutputs, "global,header");
|
| 151 | 153 | }
|
| 152 | 154 |
|
| 155 | try
|
| 156 | {
|
| 157 | String rendered = ExcelComponent.cmp2String(FacesContext.getCurrentInstance(), column);
|
| 158 | Log log = Logging.getLog(getClass());
|
| 159 | log.warn("Rendered as #0", rendered);
|
| 160 | }
|
| 161 | catch (IOException e)
|
| 162 | {
|
| 163 | e.printStackTrace();
|
| 164 | }
|
| 165 |
|
| 153 | 166 | // Process data
|
| 154 | 167 | while (iterator.hasNext())
|
| 155 | 168 | {
|
| ... | ...@@ -159,4 +159,16 @@ |
| 159 | 159 | log.trace("executeCommand() is not supported by CSV exporter", new Object[0]);
|
| 160 | 160 | }
|
| 161 | 161 |
|
| 162 | public void addWorksheetFooter(WorksheetItem item)
|
| 163 | {
|
| 164 | // TODO Auto-generated method stub
|
| 165 |
|
| 166 | }
|
| 167 |
|
| 168 | public void addWorksheetHeader(WorksheetItem item)
|
| 169 | {
|
| 170 | // TODO Auto-generated method stub
|
| 171 |
|
| 172 | }
|
| 173 |
|
| 162 | 174 | }
|
| ... | ...@@ -6,6 +6,7 @@ |
| 6 | 6 | import java.util.Iterator;
|
| 7 | 7 | import java.util.List;
|
| 8 | 8 |
|
| 9 | import javax.faces.component.UIComponent;
|
| 9 | 10 | import javax.faces.model.DataModel;
|
| 10 | 11 |
|
| 11 | 12 | import org.jboss.seam.excel.Command;
|
| ... | ...@@ -18,6 +19,9 @@ |
| 18 | 19 | {
|
| 19 | 20 | public static final String COMPONENT_TYPE = "org.jboss.seam.excel.ui.UIWorksheet";
|
| 20 | 21 |
|
| 22 | private static final String HEADER_FACET_NAME = "header";
|
| 23 | private static final String FOOTER_FACET_NAME = "footer";
|
| 24 |
|
| 21 | 25 | private String name;
|
| 22 | 26 | private String var;
|
| 23 | 27 | private Object value;
|
| ... | ...@@ -94,9 +98,7 @@ |
| 94 | 98 | @Override
|
| 95 | 99 | public void encodeBegin(javax.faces.context.FacesContext facesContext) throws java.io.IOException
|
| 96 | 100 | {
|
| 97 | | /**
|
| 98 | | * Get workbook
|
| 99 | | */
|
| 101 | // Get workbook
|
| 100 | 102 | ExcelWorkbook excelWorkbook = getWorkbook(getParent());
|
| 101 | 103 |
|
| 102 | 104 | if (excelWorkbook == null)
|
| ... | ...@@ -104,31 +106,44 @@ |
| 104 | 106 | throw new ExcelWorkbookException("Could not find excel workbook");
|
| 105 | 107 | }
|
| 106 | 108 |
|
| 107 | | /**
|
| 108 | | * Create new worksheet (or select an existing one) and apply settings (if
|
| 109 | | * any)
|
| 110 | | */
|
| 109 | // Create new worksheet (or select an existing one) and apply settings (if any)
|
| 111 | 110 | excelWorkbook.createOrSelectWorksheet(this);
|
| 112 | 111 |
|
| 113 | | /**
|
| 114 | | * Add worksheet level items
|
| 115 | | */
|
| 112 | WorksheetItem headerItem = (WorksheetItem) getFacet(HEADER_FACET_NAME);
|
| 113 | if (headerItem != null) {
|
| 114 | excelWorkbook.addWorksheetHeader(headerItem);
|
| 115 | }
|
| 116 |
|
| 117 | // Add worksheet level items
|
| 116 | 118 | List<WorksheetItem> items = getItems(getChildren());
|
| 117 | 119 | for (WorksheetItem item : items)
|
| 118 | 120 | {
|
| 119 | 121 | excelWorkbook.addItem(item);
|
| 120 | 122 | }
|
| 121 | 123 |
|
| 122 | | /**
|
| 123 | | * Execute worksheet level commands
|
| 124 | | */
|
| 124 | // Execute worksheet level commands
|
| 125 | 125 | List<Command> commands = getCommands(getChildren());
|
| 126 | 126 | for (Command command : commands)
|
| 127 | 127 | {
|
| 128 | 128 | excelWorkbook.executeCommand(command);
|
| 129 | 129 | }
|
| 130 | 130 | }
|
| 131 |
|
| 132 | @Override
|
| 133 | public void encodeEnd(javax.faces.context.FacesContext facesContext) throws java.io.IOException
|
| 134 | {
|
| 135 | ExcelWorkbook excelWorkbook = getWorkbook(getParent());
|
| 136 | if (excelWorkbook == null)
|
| 137 | {
|
| 138 | throw new ExcelWorkbookException("Could not find excel workbook");
|
| 139 | }
|
| 131 | 140 |
|
| 141 | WorksheetItem footerItem = (WorksheetItem) getFacet(FOOTER_FACET_NAME);
|
| 142 | if (footerItem != null) {
|
| 143 | excelWorkbook.addWorksheetFooter(footerItem);
|
| 144 | }
|
| 145 | }
|
| 146 |
|
| 132 | 147 | @SuppressWarnings("unchecked")
|
| 133 | 148 | public static Iterator unwrapIterator(Object value)
|
| 134 | 149 | {
|
| ... | ...@@ -777,7 +777,16 @@ |
| 777 | 777 | <itemizedlist>
|
| 778 | 778 | <listitem>
|
| 779 | 779 | <para>
|
| 780 | | <literal>none</literal>
|
| 780 | <literal>header</literal>—Contents that will
|
| 781 | be placed at the top of the data block, above the
|
| 782 | column headers (if any)
|
| 783 | </para>
|
| 784 | </listitem>
|
| 785 | <listitem>
|
| 786 | <para>
|
| 787 | <literal>footer</literal>—Contents that will
|
| 788 | be placed at the bottom of the data block, below the
|
| 789 | column footers (if any)
|
| 781 | 790 | </para>
|
| 782 | 791 | </listitem>
|
| 783 | 792 | </itemizedlist>
|
| ... | ...@@ -902,6 +911,20 @@ |
| 902 | 911 | that will be used as header for the column.
|
| 903 | 912 | </para>
|
| 904 | 913 | </listitem>
|
| 914 | <listitem>
|
| 915 | <para>
|
| 916 | <literal>footer</literal>
|
| 917 | —This facet can/will contain one
|
| 918 | <literal><e:cell></literal>
|
| 919 | ,
|
| 920 | <literal><e:formula></literal>
|
| 921 | ,
|
| 922 | <literal><e:image></literal>
|
| 923 | or
|
| 924 | <literal><e:hyperLink></literal>
|
| 925 | that will be used as footer for the column.
|
| 926 | </para>
|
| 927 | </listitem>
|
| 905 | 928 | </itemizedlist>
|
| 906 | 929 | </entry>
|
| 907 | 930 | </row>
|
| ... | ...@@ -16,6 +16,9 @@ |
| 16 | 16 | {
|
| 17 | 17 | public static final String COMPONENT_TYPE = "org.jboss.seam.excel.ui.UIColumn";
|
| 18 | 18 |
|
| 19 | private static final String HEADER_FACET_NAME = "header";
|
| 20 | private static final String FOOTER_FACET_NAME = "footer";
|
| 21 |
|
| 19 | 22 | private Boolean autoSize;
|
| 20 | 23 | private Boolean hidden;
|
| 21 | 24 | private Integer width;
|
| ... | ...@@ -74,9 +77,7 @@ |
| 74 | 77 | @Override
|
| 75 | 78 | public void encodeBegin(FacesContext facesContext) throws IOException
|
| 76 | 79 | {
|
| 77 | | /**
|
| 78 | | * Get workbook and worksheet
|
| 79 | | */
|
| 80 | // Get workbook and worksheet
|
| 80 | 81 | ExcelWorkbook excelWorkbook = getWorkbook(getParent());
|
| 81 | 82 |
|
| 82 | 83 | if (excelWorkbook == null)
|
| ... | ...@@ -84,9 +85,7 @@ |
| 84 | 85 | throw new ExcelWorkbookException("Could not find excel workbook");
|
| 85 | 86 | }
|
| 86 | 87 |
|
| 87 | | /**
|
| 88 | | * Column width etc.
|
| 89 | | */
|
| 88 | // Column width etc.
|
| 90 | 89 | excelWorkbook.applyColumnSettings(this);
|
| 91 | 90 |
|
| 92 | 91 | UIWorksheet sheet = (UIWorksheet) getParentByClass(getParent(), UIWorksheet.class);
|
| ... | ...@@ -95,30 +94,21 @@ |
| 95 | 94 | throw new ExcelWorkbookException("Could not find worksheet");
|
| 96 | 95 | }
|
| 97 | 96 |
|
| 98 | | /**
|
| 99 | | * Add header items (if any)
|
| 100 | | */
|
| 101 | | // TODO: multicells
|
| 102 | | UICell headerCell = (UICell) getFacet(HEADER_FACET);
|
| 103 | | if (headerCell != null)
|
| 104 | | {
|
| 105 | | excelWorkbook.addItem(headerCell);
|
| 97 | // Add header items (if any)
|
| 98 | WorksheetItem headerItem = (WorksheetItem) getFacet(HEADER_FACET_NAME);
|
| 99 | if (headerItem != null)
|
| 100 | {
|
| 101 | excelWorkbook.addItem(headerItem);
|
| 106 | 102 | }
|
| 107 | 103 |
|
| 108 | | /**
|
| 109 | | * Execute commands (if any)
|
| 110 | | */
|
| 104 | // Execute commands (if any)
|
| 111 | 105 | List<Command> commands = getCommands(getChildren());
|
| 112 | 106 | for (Command command : commands)
|
| 113 | 107 | {
|
| 114 | 108 | excelWorkbook.executeCommand(command);
|
| 115 | 109 | }
|
| 116 | 110 |
|
| 117 | | /**
|
| 118 | | * Get UiCell template this column's data cells and iterate over sheet
|
| 119 | | * data
|
| 120 | | *
|
| 121 | | */
|
| 111 | // Get UiCell template this column's data cells and iterate over sheet data
|
| 122 | 112 | for (WorksheetItem item : getItems(getChildren()))
|
| 123 | 113 | {
|
| 124 | 114 | Object oldValue = null;
|
| ... | ...@@ -153,9 +143,15 @@ |
| 153 | 143 | }
|
| 154 | 144 | }
|
| 155 | 145 |
|
| 156 | | /**
|
| 157 | | * Move column pointer to next column
|
| 158 | | */
|
| 146 | // Add footer items (if any)
|
| 147 | WorksheetItem footerItem = (WorksheetItem) getFacet(FOOTER_FACET_NAME);
|
| 148 | if (footerItem != null)
|
| 149 | {
|
| 150 | excelWorkbook.addItem(footerItem);
|
| 151 | }
|
| 152 |
|
| 153 |
|
| 154 | // Move column pointer to next column
|
| 159 | 155 | excelWorkbook.nextColumn();
|
| 160 | 156 |
|
| 161 | 157 | }
|
| ... | ...@@ -55,8 +55,6 @@ |
| 55 | 55 | private Boolean useTemporaryFileDuringWrite;
|
| 56 | 56 | private Boolean workbookProtected;
|
| 57 | 57 |
|
| 58 | | private long timing;
|
| 59 | |
|
| 60 | 58 | public CreationType getCreationType()
|
| 61 | 59 | {
|
| 62 | 60 | if (hasSettings())
|
| ... | ...@@ -289,20 +287,13 @@ |
| 289 | 287 | @Override
|
| 290 | 288 | public void encodeBegin(javax.faces.context.FacesContext facesContext) throws IOException
|
| 291 | 289 | {
|
| 292 | | timing = new Date().getTime();
|
| 293 | | /**
|
| 294 | | * Get workbook implementation
|
| 295 | | */
|
| 290 | // Get workbook implementation
|
| 296 | 291 | excelWorkbook = ExcelFactory.instance().getExcelWorkbook(type);
|
| 297 | 292 |
|
| 298 | | /**
|
| 299 | | * Create a new workbook
|
| 300 | | */
|
| 293 | // Create a new workbook
|
| 301 | 294 | excelWorkbook.createWorkbook(this);
|
| 302 | 295 |
|
| 303 | | /**
|
| 304 | | * Find global templates and push them to workbook
|
| 305 | | */
|
| 296 | // Find global templates and push them to workbook
|
| 306 | 297 | for (Template template : getTemplates(getChildren()))
|
| 307 | 298 | {
|
| 308 | 299 | excelWorkbook.addTemplate(template);
|
| ... | ...@@ -314,23 +305,14 @@ |
| 314 | 305 | public void encodeEnd(FacesContext context) throws IOException
|
| 315 | 306 | {
|
| 316 | 307 |
|
| 317 | | /**
|
| 318 | | * Get the bytes from workbook that should be passed on to the user
|
| 319 | | */
|
| 320 | | byte[] bytes = new byte[0];
|
| 321 | | bytes = excelWorkbook.getBytes();
|
| 322 | | if (log.isDebugEnabled())
|
| 323 | | {
|
| 324 | | log.debug("Prosessed for {0}ms", new Date().getTime() - timing);
|
| 325 | | }
|
| 308 | // Get the bytes from workbook that should be passed on to the user
|
| 309 | byte[] bytes = excelWorkbook.getBytes();
|
| 326 | 310 |
|
| 327 | 311 | DocumentType type = excelWorkbook.getDocumentType();
|
| 328 | 312 |
|
| 329 | 313 | /**
|
| 330 | | *
|
| 331 | 314 | * Code below is the same as for PDF generation. With a seam core document
|
| 332 | 315 | * store (or equivalent), this might need modifications
|
| 333 | | *
|
| 334 | 316 | */
|
| 335 | 317 | String viewId = Pages.getViewId(context);
|
| 336 | 318 | String baseName = baseNameForViewId(viewId);
|
| ... | ...@@ -106,6 +106,12 @@ |
| 106 | 106 | * user-defined worksheets in the workbook.
|
| 107 | 107 | */
|
| 108 | 108 | private int currentWorksheetIndex = 0;
|
| 109 |
|
| 110 | /**
|
| 111 | * The maximum row index we have seen. Used for determining where to place the
|
| 112 | * worksheet footer (if any)
|
| 113 | */
|
| 114 | private int maxRowIndex;
|
| 109 | 115 |
|
| 110 | 116 | // Template helper class for cell formats
|
| 111 | 117 | private JXLTemplates templates = new JXLTemplates();
|
| ... | ...@@ -127,7 +133,7 @@ |
| 127 | 133 | throw new ExcelWorkbookException(Interpolator.instance().interpolate("Excel only supports {0} rows", MAX_COLUMNS));
|
| 128 | 134 | }
|
| 129 | 135 | }
|
| 130 | |
|
| 136 |
|
| 131 | 137 | /**
|
| 132 | 138 | * Moves the internal column pointer to the next column, called by the tag to
|
| 133 | 139 | * indicate that a new column has been started. If the pointer exceeds the
|
| ... | ...@@ -147,6 +153,9 @@ |
| 147 | 153 | {
|
| 148 | 154 | throw new ExcelWorkbookException(Interpolator.instance().interpolate("Excel doesn't support more than {0} columns", MAX_COLUMNS));
|
| 149 | 155 | }
|
| 156 | if (currentRowIndex > maxRowIndex) {
|
| 157 | maxRowIndex = currentRowIndex;
|
| 158 | }
|
| 150 | 159 | currentRowIndex = startRowIndex;
|
| 151 | 160 | }
|
| 152 | 161 |
|
| ... | ...@@ -224,6 +233,7 @@ |
| 224 | 233 | currentColumnIndex = startColumnIndex;
|
| 225 | 234 | startRowIndex = uiWorksheet.getStartRow() == null ? 0 : uiWorksheet.getStartRow();
|
| 226 | 235 | currentRowIndex = startRowIndex;
|
| 236 | maxRowIndex = currentRowIndex;
|
| 227 | 237 | }
|
| 228 | 238 |
|
| 229 | 239 | /**
|
| ... | ...@@ -667,4 +677,27 @@ |
| 667 | 677 | }
|
| 668 | 678 | }
|
| 669 | 679 |
|
| 680 | /**
|
| 681 | * Places an item in the worksheet footer
|
| 682 | *
|
| 683 | * @param item The item to add
|
| 684 | */
|
| 685 | public void addWorksheetFooter(WorksheetItem item)
|
| 686 | {
|
| 687 | currentColumnIndex = startColumnIndex;
|
| 688 | currentRowIndex = maxRowIndex;
|
| 689 | addItem(item);
|
| 690 | }
|
| 691 |
|
| 692 | /**
|
| 693 | * Places an item in the worksheet header
|
| 694 | *
|
| 695 | * @param item The item to add
|
| 696 | */
|
| 697 | public void addWorksheetHeader(WorksheetItem item)
|
| 698 | {
|
| 699 | addItem(item);
|
| 700 | startRowIndex++;
|
| 701 | }
|
| 702 |
|
| 670 | 703 | }
|
To list