Permalink
Browse files

fix column width applied on after css,

it should after workbook finish
  • Loading branch information...
1 parent bdc0633 commit cad46051abbb1f2d6c54e5b555167f9222914458 albert committed Oct 7, 2012
View
@@ -6,4 +6,41 @@ rich set of excel api, but it is painful to use in any project.
GShit is just a small DSL build on top of apache-poi to fulfill my need
of more visable excel report design.
-[![Build Status](https://secure.travis-ci.org/zerg000000/gshit.png)](http://travis-ci.org/zerg000000/gshit)
+[![Build Status](https://secure.travis-ci.org/zerg000000/gshit.png)](http://travis-ci.org/zerg000000/gshit)
+
+Getting Started
+---------------
+
+Building a standard excel report is a piece of cake!
+
+ new ExcelBuilder()
+ .workbook {
+ sheet( 'Daily summary' ) {
+ columns( 7 * 256, 52 * 256, 'auto', 'auto', 'auto' )
+ row { cell( 'Printed', new Date() ) }
+ row { cell( 'No.', 'DateTime', 'From', 'To', 'Amount' ) }
+ transactions.eachWithIndex { tran, i ->
+ marker( 'transaction' ) {
+ row { cell( i, tran.time, tran.from, tran.to, tran.amount ) }
+ }
+ }
+ }
+
+ format( 'date', 'yyyy-MMM-dd' )
+ format( 'money', '#,##0.00' )
+
+ font( name: 'header', bold: true, fontHeight: 24, underline: 'single' )
+ font( name: 'normal', fontHeight: 12)
+
+ style( name: 'header', font: 'header' )
+ style( name: 'normal', font: 'normal' )
+ style( name: 'normal-date', font: 'normal', format: 'date')
+ style( name: 'normal-money', font: 'normal', format: 'money', alignment: 'right')
+
+ css( sheet: 'Daily summary', row: 0, col: 1, style: 'normal-date' )
+ css( sheet: 'Daily summary', row: 1, col: 0..5, style: 'header' )
+ css( marker: 'transaction', sheet: 'Daily summary', row: 0, col: 0..4, style: 'normal' )
+ css( marker: 'transaction', sheet: 'Daily summary', row: 0, col: 1, style: 'normal-date' )
+ css( marker: 'transaction', sheet: 'Daily summary', row: 0, col: 4, style: 'normal-money' )
+
+ }.write(new FileOutputStream('~/daily.summary.xlsx'))
View
@@ -1,5 +1,8 @@
apply plugin: 'groovy'
+group = 'gshit'
+version = '0.0.1'
+
repositories {
mavenCentral()
}
@@ -21,11 +21,6 @@ class CSSFactory extends AbstractFactory {
'css'
}
- @Override
- void onNodeCompleted(FactoryBuilderSupport builder, Object parent, Object node) {
- builder.factories['columns'].adjustColumn()
- }
-
public void select(Object sheet, Object row, Object col, Object marker, Closure closure) {
def sheets = []
if (FactoryBuilderSupport.checkValueIsType(sheet, 'sheet', String)) {
@@ -11,9 +11,9 @@ import org.apache.poi.ss.usermodel.VerticalAlignment
class CellStyleFactory extends AbstractFactory {
ExcelBuilder builder
- boolean leaf = true
+ boolean leaf = false
- boolean handlesNodeChildren = false
+ boolean handlesNodeChildren = true
boolean processNodeChildren = true
@@ -17,4 +17,9 @@ class WorkbookFactory extends AbstractFactory {
public Object newInstance(FactoryBuilderSupport builder, Object name, Object value, Map attributes) {
(value == 'xls') ? new HSSFWorkbook() : new XSSFWorkbook()
}
+
+ @Override
+ void onNodeCompleted(FactoryBuilderSupport builder, Object parent, Object node) {
+ builder.factories['columns'].adjustColumn()
+ }
}

0 comments on commit cad4605

Please sign in to comment.