-1

I would like to do generate an excel file from the database query results(which are shown in an html), and display those in an downloadable excel sheet on the same page.All this needs to be done using jsf and javabeans(no jsp). The basically i would like to do the java ee equivalent of the following:

header("Content-type: application/vnd-ms-excel"); 
header("Content-Disposition: attachment; filename=Export_data.xls"); 

$db_link = db_connect();
$result = odbc_exec($db_link, $query);
?>

<div id="content">

  <table width="900px">
    <tr>
    <th width="10%" align="left"><b>column1</b></th>
    <th width="25%" align="left"><b>column2</b></th>
       </tr>

<?php
  while(odbc_fetch_row($result)){ 
        $col1 = odbc_result($result, 'column1'); 
      $col2 = substr(odbc_result($result, 'column2'),0,30); 
     echo ('<tr>');
      echo ('<td>' . $col1 . '</td>');
      echo ('<td>' . $col2 . '</td>');
 echo ('</tr>');
                         }

                                ?>
  </table>
</div>
<?php

edit: i want to both generate an excel from an html markup on the page, and display a downloadable version on the same page, without using any external plugin/apis.just like shown in the php. So it is not a duplicate of the other post, which doesnt generate excel from the the markup, and doesnt display it on the same page either.

Arnold
  • 181
  • 3
  • 12
  • One thing at a time my friend. – J. Chomel Mar 21 '17 at 07:18
  • Defeats the purpose of the question if i dont do both things together though – Arnold Mar 21 '17 at 09:05
  • You need 2 php pages. If you can do both independently, then you can do the first and have the second one on another page, called by javascript (something like target:blank). So your question becomes "how do I redirect to a page in javascript"... don't mix everything in one question. – J. Chomel Mar 21 '17 at 09:31

1 Answers1

0

Have you looked into POI? It will let you generate Excel documents and do with them as you like.

https://poi.apache.org/

Zach
  • 315
  • 6
  • 15