-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexcel.groovy
43 lines (32 loc) · 1.18 KB
/
excel.groovy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
* This Example show the usage the .deps and the capacity to work with excel workbook
*
* The .deps file should contains this dependencies :
* org.apache.poi:poi:4.1.1
* org.apache.poi:poi-ooxml:4.1.1
*/
package examples
import org.apache.poi.ss.usermodel.*
import org.apache.poi.xssf.usermodel.*
def workbook = new XSSFWorkbook()
def sheet = workbook.createSheet("Persons")
sheet.setColumnWidth(0, 6000)
sheet.setColumnWidth(1, 4000)
def header = sheet.createRow(0)
def headerStyle = workbook.createCellStyle()
headerStyle.setFillForegroundColor(IndexedColors.LIGHT_BLUE.getIndex())
headerStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND)
def font = ((XSSFWorkbook) workbook).createFont()
font.setFontName("Arial")
font.setFontHeightInPoints((short) 16)
font.setBold(true)
headerStyle.setFont(font)
def headerCell = header.createCell(0)
headerCell.setCellValue("Name")
headerCell.setCellStyle(headerStyle)
headerCell = header.createCell(1)
headerCell.setCellValue("Age")
headerCell.setCellStyle(headerStyle)
def xlsx = promptSaveFile(options = [ title: "Excel Script", filterExtensions: ["*.xlsx"], filename: null ])
workbook.write(new FileOutputStream(xlsx))
workbook.close()