POI Generate Excel based on multidimensional array

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xc="http://www.ibm.com/xsp/custom"
	xmlns:wgpoi="http://www.webgate.biz/xsp/poi">

	<xp:button value="Print cars" id="button1" style="margin-left:50.0px">
		<xp:eventHandler event="onclick" submit="true"
			refreshMode="complete">
			<xp:this.action>
				<wgpoi:generateWorkbook workbookId="listCars"></wgpoi:generateWorkbook>
			</xp:this.action>
		</xp:eventHandler>
	</xp:button>

	<xp:br></xp:br>


	<wgpoi:spreadsheet id="listCars" downloadFileName="listCars.xlsx">

		<wgpoi:this.spreadsheets>
			<wgpoi:table name="Cars">
				<wgpoi:this.exportDefinitions>
					<wgpoi:data2rowExport index="i" startRow="5"
						stepSize="1">
						<wgpoi:this.dataSource>
							<wgpoi:ListObjectDataSource>
								<wgpoi:this.buildValues><![CDATA[#{javascript:var mycars = [["BMW","Z4","2012"],["Mercedes","SLK","2010"],["VW","Passat","2008"]];
return mycars;}]]></wgpoi:this.buildValues>
							</wgpoi:ListObjectDataSource>
						</wgpoi:this.dataSource>
						<wgpoi:this.columns>
							<wgpoi:columnDefinition columnNumber="0"
								rowShift="0">
								<wgpoi:this.computeValue><![CDATA[#{javascript:mycars[i-1][0]}]]></wgpoi:this.computeValue>
							</wgpoi:columnDefinition>
						</wgpoi:this.columns>
						<wgpoi:this.columns>
							<wgpoi:columnDefinition columnNumber="1"
								rowShift="0">
								<wgpoi:this.computeValue><![CDATA[#{javascript:mycars[i-1][1]}]]></wgpoi:this.computeValue>
							</wgpoi:columnDefinition>
						</wgpoi:this.columns>
						<wgpoi:this.columns>
							<wgpoi:columnDefinition columnNumber="2"
								rowShift="0">
								<wgpoi:this.computeValue><![CDATA[#{javascript:mycars[i-1][2]}]]></wgpoi:this.computeValue>
							</wgpoi:columnDefinition>
						</wgpoi:this.columns>
					</wgpoi:data2rowExport>
				</wgpoi:this.exportDefinitions>
			</wgpoi:table>
		</wgpoi:this.spreadsheets>
		<wgpoi:this.templateSource>
			<wgpoi:resourcetemplate fileName="lijst_cars.xlsx"></wgpoi:resourcetemplate>
		</wgpoi:this.templateSource>
	</wgpoi:spreadsheet>

</xp:view>





This is a basic example. The datasource can be build dynamically. In my project i looped through a NotesViewEntryCollection and build the array with SSJS. LOOP { var cars = new Array(); cars.push([Toyota,Landcruser,2011]);   }. If you want to use a view as datasource, see documentation at "POI4Xpages".

XPages
Bram van Iterson
March 3, 2014 5:44 AM
Rating
53

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.



No comments yetLogin first to comment...