Welcome Guest, Not a member yet? Register   Sign In
how to export html table to excel || new question -> how to export rows generated by mysql queries to excel??
#1

[eluser]johnmiller[/eluser]
hi all...

old question

i need to export data from dynamic html table to excel...

does codeigniter provide any feature for that???

how should i do that???

new question

now the below given is my question...

how to export query result to an excel???
#2

[eluser]Colin Williams[/eluser]
http://www.codeplex.com/PHPExcel
#3

[eluser]outrage[/eluser]
You could also try this very easy to use plugin:

http://codeigniter.com/wiki/Excel_Plugin/

Good luck
#4

[eluser]Derek Allard[/eluser]
[quote author="outrage" date="1224223987"]You could also try this very easy to use plugin[/quote]

Ah that takes me back :: blank stare while I have fond memories :: Wink

Just in the interest of full disclosure, the plugin I wrote doesn't truly export to Excel. It exports to csv and tricks excel into opening it by changing the file extension. That said, it's probably good for 99% of potential needs. If you need full on Excel support with formulas and links and such, check out the PEAR library.
#5

[eluser]dcunited08[/eluser]
I may be wrong but Excel_Plugin exports data from a DATABASE table, not an HTML table. To do that you would have to pull the table out of output (or using $table->generate()) and change the <td>s to commas and </tr> to endlines. Is there a package that does that?
#6

[eluser]Derek Allard[/eluser]
No, you are correct dcunited08. When the OP wrote "dynamic" table, I assumed they meant "generated by a db". There's nothing in CI that parses html tables and extracts text.
#7

[eluser]dcunited08[/eluser]
I wrote a method for MY_Table that should allow you to output the table as a csv, please give it a try and let me know if it works for you.

Code:
/**
     * Creates a csv string from the created table
     *
     * @author dcunited08 of CodeIgniter
     *
     * @param array $table_data
     * @return string
     */
    function generate_cvs($table_data = NULL)
    {
        //save current template
        $template_holder = $this->template;

        
        $tmpl = array (
                    'table_open'          => '',

                    'heading_row_start'   => '',
                    'heading_row_end'     => '',
                    'heading_cell_start'  => '',
                    'heading_cell_end'    => ',',

                    'row_start'           => '',
                    'row_end'             => '',
                    'cell_start'          => '',
                    'cell_end'            => ',',

                    'row_alt_start'       => '',
                    'row_alt_end'         => '',
                    'cell_alt_start'      => '',
                    'cell_alt_end'        => ',',

                    'table_close'         => '');
        
        //apply csv template
        $this->set_template($tmpl);
        
        //generate csv data
        $forReturn = $this->generate($table_data);
        
        //reset to old template
        $this->set_template($template_holder);
        
        return $forReturn;
    }
#8

[eluser]johnmiller[/eluser]
Thanks a lot...
but, dcunited08, your code is for creating CSV file, right?
I would like to create an excel.
Derek is right, dynamic means generated by db only.
And actually I am exporting to excel using query.
Means... suppose... I have first_name and last_name in the dynamic table.
If I hit 'export to excel' button, all the details related to listed people have to export to excel (like first_name, last_name, address, city, state, zip etc...)
So I am trying to export data from database to excel (using query)

I tried using http://codeigniter.com/wiki/Excel_Plugin/

The below is what I did

controller

Code:
function app_details_export()
    {
       $id = $this->uri->segment(3);
       $this->load->plugin('to_excel');
       to_excel($this->app_model->app_export($id));
       to_excel($query, 'app_details');
       to_excel($query);
    }

model

Code:
function app_export($id)
    {    
       $this->load->plugin('to_excel');
       // my select query here...
       to_excel($query, 'app_details');
    }

and /system/plugins/to_excel_pi.php

but when i run this, i get a fatal error like below...

Fatal error: Call to a member function field_data() on a non-object in C:\wamp\www\mywork\system\plugins\to_excel_pi.php on line 15
#9

[eluser]johnmiller[/eluser]
and one more thing...
I told you I am getting a fatal error...
I am getting it after exporting some values to excel...
suppose... I am exporting 20 rows to excel...
sometimes 15 random rows will export to excel without any problem...
and after that, in excel, i am getting fatal error message...




Theme © iAndrew 2016 - Forum software by © MyBB