Welcome Guest, Not a member yet? Register   Sign In
Download excel file with ajax
#1

Hi to all, i'm new there and i have a big problem, i hope find answer here.
So i want to generate xsl file from database and download without reload page.

So this is my controller:

PHP Code:
   public function export()
 
   {
 
       $this->load->library("excel");
 
       $rowscount $this->Public->Count();
 
       $object = new PHPExcel();

 
       $object->setActiveSheetIndex(0);

 
       $table_columns = array("Name");

 
       $column 0;

 
       foreach($table_columns as $field)
 
       {
 
           $object->getActiveSheet()->setCellValueByColumnAndRow($column1$field);
 
           $column++;
 
       }

 
       $users $this->Public->export();

 
       $excel_row 2;

 
       foreach($users as $row)
 
       {
 
           $object->getActiveSheet()->setCellValueByColumnAndRow(0$excel_row$row->username);
 
           $excel_row++;
 
       }

 
       $object_writer PHPExcel_IOFactory::createWriter($object'Excel5');
 
       header("Content-Type: application/vnd.ms-excel");
 
       header("Content-Disposition: attachment;filename=Export.xls");
 
       $object_writer->save('php://output');
 
   
This is form in view:
PHP Code:
<form role="form" action="<?php echo site_url('admin/export')?>" method="post">
<
button class="btn btn-warning">Export</button>
 
   </form

This is work correct, but before download start the current page reloaded. I want with ajax make download form work without reload page.

Any hint how to do that?

Regards.
Reply


Messages In This Thread
Download excel file with ajax - by demo - 09-22-2018, 10:57 AM
RE: Download excel file with ajax - by fenzy - 09-23-2018, 03:30 AM
RE: Download excel file with ajax - by demo - 09-23-2018, 03:35 AM
RE: Download excel file with ajax - by Wouter60 - 09-23-2018, 05:19 AM
RE: Download excel file with ajax - by demo - 09-23-2018, 07:16 AM
RE: Download excel file with ajax - by Wouter60 - 09-23-2018, 09:43 AM



Theme © iAndrew 2016 - Forum software by © MyBB