我对Groovy还是很陌生,我需要执行一个使用Apache POI创建Excel文件的脚本。
A
脚本失败,并显示:
$content = "<?php" . PHP_EOL;
$content .= "\t" . '$output = [' . PHP_EOL;
foreach($test as $key => $value) {
foreach ($value as $subkey => $subvalue) {
$content .= "\t\t\"{$subkey}\" => \"{$subvalue}\"," . PHP_EOL;
}
}
$content .= "\t];" . PHP_EOL;
$content .= "?>";
我观察到的是〜/ .groovy / grapes / commons-codec / commons-codec的创建具有以下内容:
@Grab( 'org.apache.poi:poi:3.9' )
import static org.apache.poi.ss.usermodel.CellStyle.*
import static org.apache.poi.ss.usermodel.IndexedColors.*
import org.apache.poi.hssf.usermodel.HSSFWorkbook
new HSSFWorkbook().with { workbook ->
def styles = [ LIGHT_BLUE, LIGHT_GREEN, LIGHT_ORANGE ].collect { color ->
createCellStyle().with { style ->
fillForegroundColor = color.index
fillPattern = SOLID_FOREGROUND
style
}
}
createSheet( 'Output' ).with { sheet ->
(0..4).each { rownum ->
createRow( rownum ).with { row ->
(0..4).each { colnum ->
createCell( colnum ).with { cell ->
setCellValue( "[$colnum,$rownum]" )
cellStyle = styles[ ( ( rownum * 5 ) + colnum ) % styles.size() ]
}
}
}
}
new File( '/tmp/test.xls' ).withOutputStream { os ->
write( os )
}
}
}
我根本不是个时髦的专家,但我希望能有一些罐子。我曾尝试删除文件夹“〜/ .groovy / grapes”,但没有帮助。 您能提出任何建议吗?