Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- require_once("Java.inc");
- header("Content-type: application/vnd.ms-excel");
- $vFileName = 'MyExcelFile.xls';
- header("Content-Disposition: attachment; filename=$vFileName");
- // create a 50x40 excel sheet and return it to the client
- $workbook = new java("org.apache.poi.hssf.usermodel.HSSFWorkbook");
- $sheet = $workbook->createSheet("datafrommysql");
- $host = "127.0.0.1"; // localhost
- $user = "root";
- $pass = "";
- $database = "dbupm";
- mysql_connect($host, $user, $pass) or die ("Cannot connect to Server!");
- mysql_select_db($database) or die ("Cannot Select Database!");
- $vSQL = "Select * from usermaster";
- $vExcelRowNo = 0;
- $rs = mysql_query($vSQL);
- while($dbrow = mysql_fetch_array($rs)){
- $row = $sheet->createRow($vExcelRowNo++);
- for($x=0; $x<=2; $x++) {
- $cell = $row->createCell($x);
- $cell->setCellValue($dbrow[$x]);
- }
- }
- // create and return the excel sheet to the client
- $memoryStream = new java("java.io.ByteArrayOutputStream");
- $workbook->write($memoryStream);
- $memoryStream->close();
- echo java_values($memoryStream->toByteArray());
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement