40 likes | 53 Views
Learn how to display a data table in the browser as an Excel spreadsheet programmatically using EGL server-side logic. Follow simple steps to provide users with the Excel data they want easily and effectively.
E N D
Display contents of a Data Table in Excel right from the browser – No POI needed This section describes how to display the contents of a data table in the browser as an Excel spreadsheet programmatically, using EGL server-side logic.
Display Data Table as Excel in the Browser • How many times have you heard, “The data on the web page is just what I asked for! But, now what I really want is use the data in an Excel spreadsheet”. • Fortunately, your efforts have not gone to waste. You are just a few simple steps – and literally minutes – away from providing exactly what the user wants. • Here’s how: • Take an ordinary EGL generated web page having a dataTable. • Add a commandButton to the page • Use an Excel image (.gif) for the button instead of text • Add an Excel-specific page with the data table only • Drag-drop the array onto an empty page – that’s all! • Keep the Excel page simple • Simple page and cell formatting will likely be rendered as desired • Complex JSF properties and actions will likely be troublesome • Besides, the excel user will likely re-size, re-sort and re-render the spreadsheet in more ways than you can imagine. • Let’s see how it works
Data Table in Excel Browser Lab 1 of 2 – Create the Page and JSFHandler • Create a new page, named: allcustomersExcel.jsp– no need for a page template • Copy/Paste the EGL code from the Notes section of the slide, and replace the default JSFHandler with this code • From Page Data: • Drag customersArray onto the page • Remove Pager: From properties, select dataTable – uncheck: Show footer • NOTE: • Keep the page simple
Data Table in Excel Browser Lab 1 of 2 – Add command button • Set the ContentType on page • Click the Source tab • Add <% response.setContentType("application/vnd.ms-excel"); %> prior to the <html> tag • Open allcustomers2.jsp: • Add Excel image to project • Download an Excel image from the web (or copy from this slide) • Copy Excel image and paste into WebContent\images folder • Drag and drop a Command Button from the Enhanced Faces pallet • From properties view – Display options: • Set the Type property by clicking the Image radio button • insert - images/ExcelButton.gif – into Normal image • Copy/Paste the EGL function – ShowInExcel – from the notes section into the JSPHandler • Bind the function to the command button • From the Page Data view – Actions: drag/drop ShowInExcel() onto the command button • Run the page on the server • Click the Excel button • depending on your security settings, you may get a File Download dialog – click open to continueand see Excel in the browser.