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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
<cfobject type="java" class="EasyXLS.Constants.DataType" name="DataType" action="CREATE">
<cfobject type="java" class="EasyXLS.Constants.Styles" name="Styles" action="CREATE">
<cfobject type="java" class="EasyXLS.Constants.DataGroup" name="DataGroup" action="CREATE">
Tutorial 17<br>
----------<br>
<cfobject type="java" class="EasyXLS.ExcelDocument" name="workbook" action="CREATE">
<cfset ret = workbook.easy_addWorksheet("First tab")>
<cfset ret = workbook.easy_addWorksheet("Second tab")>
<cfset xlsFirstTable = workbook.easy_getSheetAt(0).easy_getExcelTable()>
<cfloop from="0" to="4" index="column">
<cfset xlsFirstTable.easy_getCell(0, evaluate(column)).setValue("Column " & evaluate(column + 1))>
<cfset xlsFirstTable.easy_getCell(0, evaluate(column)).setDataType(DataType.STRING)>
</cfloop>
<cfset ret = xlsFirstTable.easy_getRowAt(0).setHeight(30)>
<cfloop from="0" to="24" index="row">
<cfloop from="0" to="4" index="column">
<cfset xlsFirstTable.easy_getCell(evaluate(row + 1), evaluate(column)).setValue(
"Data " & evaluate(row + 1) & ", " & evaluate(column + 1))>
<cfset xlsFirstTable.easy_getCell(evaluate(row + 1), evaluate(column)).setDataType(DataType.STRING)>
</cfloop>
</cfloop>
<cfset xlsFirstTable.setColumnWidth(0, 70)>
<cfset xlsFirstTable.setColumnWidth(1, 100)>
<cfset xlsFirstTable.setColumnWidth(2, 70)>
<cfset xlsFirstTable.setColumnWidth(3, 100)>
<cfset xlsFirstTable.setColumnWidth(4, 70)>
<cfobject type="java" class="EasyXLS.ExcelDataGroup" name="xlsFirstDataGroup" action="CREATE">
<cfset xlsFirstDataGroup.setRange("A1:E26")>
<cfset xlsFirstDataGroup.setGroupType(DataGroup.GROUP_BY_ROWS)>
<cfset xlsFirstDataGroup.setCollapsed(false)>
<cfobject type="java" class="EasyXLS.ExcelAutoFormat" name="xlsAutoFormat" action="CREATE">
<cfset xlsAutoFormat.InitAs(Styles.AUTOFORMAT_EASYXLS1)>
<cfset xlsFirstDataGroup.setAutoFormat(xlsAutoFormat)>
<cfset workbook.easy_getSheetAt(0).easy_addDataGroup(xlsFirstDataGroup)>
<cfobject type="java" class="EasyXLS.ExcelDataGroup" name="xlsSecondDataGroup" action="CREATE">
<cfset xlsSecondDataGroup.setRange("A1:E26")>
<cfset xlsSecondDataGroup.setGroupType(DataGroup.GROUP_BY_ROWS)>
<cfset xlsSecondDataGroup.setCollapsed(false)>
<cfobject type="java" class="EasyXLS.ExcelAutoFormat" name="xlsAutoFormat2" action="CREATE">
<cfset xlsAutoFormat2.InitAs(Styles.AUTOFORMAT_EASYXLS2)>
<cfset xlsSecondDataGroup.setAutoFormat(xlsAutoFormat2)>
<cfset workbook.easy_getSheetAt(0).easy_addDataGroup(xlsSecondDataGroup)>
Writing file C:\Samples\Tutorial17 - group data in Excel.xlsx<br>
<cfset ret = workbook.easy_WriteXLSXFile("C:\Samples\Tutorial17 - group data in Excel.xlsx")>
<cfset sError = workbook.easy_getError()>
<cfif (sError is "")>
<cfoutput>
File successfully created.
</cfoutput>
<cfelse>
<cfoutput>
Error encountered: #sError#
</cfoutput>
</cfif>
<cfset workbook.Dispose()>
|