How to Generate Excel File With Autofilters in PHP?





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}







14















Okay, here's my dilemma.



I've been working on a Wordpress plugin for Medical Marcom to automatically update his List of US Twitter Doctors. Basically, it provides the ability to create a form where users can request to be added to the list, requests can be confirmed in the admin panel, when added they're available in the Excel file and the initial data is filled out, and finally, certain fields are automatically updated throughout the week.



Here's the problem.



My code is generating an Excel file with PHP using PHPExcel. However, I need to have a simple autofilter applied to the sheet at startup (honestly, I don't know what the big deal is... anyone can easily apply an autofilter in Excel, but he wants it available from the start). So, I tried applying the code I found:



$excel->getActiveSheet()->setAutoFilter('A1:J' . $row);


$excel is my PHPExcel instance. $row is the last row being outputted from the database. The file is generated immediately when the url is clicked and PHP's headers are set to translate the output as an Excel file, like so:



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


But when I open the file, no autofilters are set... I tried posting a question over at PHPExcel's website, but I didn't get any replies, so I decided to ask here.



Does anyone know what I may be doing wrong? For now he's going with the original file (updated a bit, though) until this issue is resolved.










share|improve this question





























    14















    Okay, here's my dilemma.



    I've been working on a Wordpress plugin for Medical Marcom to automatically update his List of US Twitter Doctors. Basically, it provides the ability to create a form where users can request to be added to the list, requests can be confirmed in the admin panel, when added they're available in the Excel file and the initial data is filled out, and finally, certain fields are automatically updated throughout the week.



    Here's the problem.



    My code is generating an Excel file with PHP using PHPExcel. However, I need to have a simple autofilter applied to the sheet at startup (honestly, I don't know what the big deal is... anyone can easily apply an autofilter in Excel, but he wants it available from the start). So, I tried applying the code I found:



    $excel->getActiveSheet()->setAutoFilter('A1:J' . $row);


    $excel is my PHPExcel instance. $row is the last row being outputted from the database. The file is generated immediately when the url is clicked and PHP's headers are set to translate the output as an Excel file, like so:



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


    But when I open the file, no autofilters are set... I tried posting a question over at PHPExcel's website, but I didn't get any replies, so I decided to ask here.



    Does anyone know what I may be doing wrong? For now he's going with the original file (updated a bit, though) until this issue is resolved.










    share|improve this question

























      14












      14








      14


      1






      Okay, here's my dilemma.



      I've been working on a Wordpress plugin for Medical Marcom to automatically update his List of US Twitter Doctors. Basically, it provides the ability to create a form where users can request to be added to the list, requests can be confirmed in the admin panel, when added they're available in the Excel file and the initial data is filled out, and finally, certain fields are automatically updated throughout the week.



      Here's the problem.



      My code is generating an Excel file with PHP using PHPExcel. However, I need to have a simple autofilter applied to the sheet at startup (honestly, I don't know what the big deal is... anyone can easily apply an autofilter in Excel, but he wants it available from the start). So, I tried applying the code I found:



      $excel->getActiveSheet()->setAutoFilter('A1:J' . $row);


      $excel is my PHPExcel instance. $row is the last row being outputted from the database. The file is generated immediately when the url is clicked and PHP's headers are set to translate the output as an Excel file, like so:



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


      But when I open the file, no autofilters are set... I tried posting a question over at PHPExcel's website, but I didn't get any replies, so I decided to ask here.



      Does anyone know what I may be doing wrong? For now he's going with the original file (updated a bit, though) until this issue is resolved.










      share|improve this question














      Okay, here's my dilemma.



      I've been working on a Wordpress plugin for Medical Marcom to automatically update his List of US Twitter Doctors. Basically, it provides the ability to create a form where users can request to be added to the list, requests can be confirmed in the admin panel, when added they're available in the Excel file and the initial data is filled out, and finally, certain fields are automatically updated throughout the week.



      Here's the problem.



      My code is generating an Excel file with PHP using PHPExcel. However, I need to have a simple autofilter applied to the sheet at startup (honestly, I don't know what the big deal is... anyone can easily apply an autofilter in Excel, but he wants it available from the start). So, I tried applying the code I found:



      $excel->getActiveSheet()->setAutoFilter('A1:J' . $row);


      $excel is my PHPExcel instance. $row is the last row being outputted from the database. The file is generated immediately when the url is clicked and PHP's headers are set to translate the output as an Excel file, like so:



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


      But when I open the file, no autofilters are set... I tried posting a question over at PHPExcel's website, but I didn't get any replies, so I decided to ask here.



      Does anyone know what I may be doing wrong? For now he's going with the original file (updated a bit, though) until this issue is resolved.







      php phpexcel autofilter






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Sep 8 '11 at 7:41









      JaidynReimanJaidynReiman

      6393922




      6393922
























          3 Answers
          3






          active

          oldest

          votes


















          29














          In case anyone comes across this question. The feature has been implemented both for XLSX and XLS.



          You just need to specify the range of your header row for it to work:



          $excel->getActiveSheet()->setAutoFilter('A1:J1');





          share|improve this answer



















          • 1





            Only specifying the header row works. Thanks!

            – Oak
            Dec 3 '15 at 11:38



















          1














          I understand from this link that it has not been implemented yet.



          It seems like it is still a work item (with a low priority sorry).



          [EDIT] seems like it may work with Excel 2007 (see this work item). Which version of Excel do your client use?






          share|improve this answer
























          • I'll have to ask him about it. I've seen that it HAS been implemented, and it shows it right in the documentation, but it didn't work for me. Another person who posted a work item apparently had got it working, it just didn't have the advanced features. I was starting to think, though, that I may have been trying to output the wrong type of Excel file. I'll go and ask my client if using Excel 2007 is fine. The current file is 2003, though, unfortunately...

            – JaidynReiman
            Sep 9 '11 at 3:10



















          1














          PHPSpreadsheet have a much nicer implementation if you want your whole sheet auto-filtered:



              $sheet->setAutoFilter(
          $sheet->calculateWorksheetDimension()
          );





          share|improve this answer
























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7344707%2fhow-to-generate-excel-file-with-autofilters-in-php%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            3 Answers
            3






            active

            oldest

            votes








            3 Answers
            3






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            29














            In case anyone comes across this question. The feature has been implemented both for XLSX and XLS.



            You just need to specify the range of your header row for it to work:



            $excel->getActiveSheet()->setAutoFilter('A1:J1');





            share|improve this answer



















            • 1





              Only specifying the header row works. Thanks!

              – Oak
              Dec 3 '15 at 11:38
















            29














            In case anyone comes across this question. The feature has been implemented both for XLSX and XLS.



            You just need to specify the range of your header row for it to work:



            $excel->getActiveSheet()->setAutoFilter('A1:J1');





            share|improve this answer



















            • 1





              Only specifying the header row works. Thanks!

              – Oak
              Dec 3 '15 at 11:38














            29












            29








            29







            In case anyone comes across this question. The feature has been implemented both for XLSX and XLS.



            You just need to specify the range of your header row for it to work:



            $excel->getActiveSheet()->setAutoFilter('A1:J1');





            share|improve this answer













            In case anyone comes across this question. The feature has been implemented both for XLSX and XLS.



            You just need to specify the range of your header row for it to work:



            $excel->getActiveSheet()->setAutoFilter('A1:J1');






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 20 '15 at 23:42









            Maxime RainvilleMaxime Rainville

            1,4441923




            1,4441923








            • 1





              Only specifying the header row works. Thanks!

              – Oak
              Dec 3 '15 at 11:38














            • 1





              Only specifying the header row works. Thanks!

              – Oak
              Dec 3 '15 at 11:38








            1




            1





            Only specifying the header row works. Thanks!

            – Oak
            Dec 3 '15 at 11:38





            Only specifying the header row works. Thanks!

            – Oak
            Dec 3 '15 at 11:38













            1














            I understand from this link that it has not been implemented yet.



            It seems like it is still a work item (with a low priority sorry).



            [EDIT] seems like it may work with Excel 2007 (see this work item). Which version of Excel do your client use?






            share|improve this answer
























            • I'll have to ask him about it. I've seen that it HAS been implemented, and it shows it right in the documentation, but it didn't work for me. Another person who posted a work item apparently had got it working, it just didn't have the advanced features. I was starting to think, though, that I may have been trying to output the wrong type of Excel file. I'll go and ask my client if using Excel 2007 is fine. The current file is 2003, though, unfortunately...

              – JaidynReiman
              Sep 9 '11 at 3:10
















            1














            I understand from this link that it has not been implemented yet.



            It seems like it is still a work item (with a low priority sorry).



            [EDIT] seems like it may work with Excel 2007 (see this work item). Which version of Excel do your client use?






            share|improve this answer
























            • I'll have to ask him about it. I've seen that it HAS been implemented, and it shows it right in the documentation, but it didn't work for me. Another person who posted a work item apparently had got it working, it just didn't have the advanced features. I was starting to think, though, that I may have been trying to output the wrong type of Excel file. I'll go and ask my client if using Excel 2007 is fine. The current file is 2003, though, unfortunately...

              – JaidynReiman
              Sep 9 '11 at 3:10














            1












            1








            1







            I understand from this link that it has not been implemented yet.



            It seems like it is still a work item (with a low priority sorry).



            [EDIT] seems like it may work with Excel 2007 (see this work item). Which version of Excel do your client use?






            share|improve this answer













            I understand from this link that it has not been implemented yet.



            It seems like it is still a work item (with a low priority sorry).



            [EDIT] seems like it may work with Excel 2007 (see this work item). Which version of Excel do your client use?







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Sep 8 '11 at 7:45









            JMaxJMax

            20.7k85785




            20.7k85785













            • I'll have to ask him about it. I've seen that it HAS been implemented, and it shows it right in the documentation, but it didn't work for me. Another person who posted a work item apparently had got it working, it just didn't have the advanced features. I was starting to think, though, that I may have been trying to output the wrong type of Excel file. I'll go and ask my client if using Excel 2007 is fine. The current file is 2003, though, unfortunately...

              – JaidynReiman
              Sep 9 '11 at 3:10



















            • I'll have to ask him about it. I've seen that it HAS been implemented, and it shows it right in the documentation, but it didn't work for me. Another person who posted a work item apparently had got it working, it just didn't have the advanced features. I was starting to think, though, that I may have been trying to output the wrong type of Excel file. I'll go and ask my client if using Excel 2007 is fine. The current file is 2003, though, unfortunately...

              – JaidynReiman
              Sep 9 '11 at 3:10

















            I'll have to ask him about it. I've seen that it HAS been implemented, and it shows it right in the documentation, but it didn't work for me. Another person who posted a work item apparently had got it working, it just didn't have the advanced features. I was starting to think, though, that I may have been trying to output the wrong type of Excel file. I'll go and ask my client if using Excel 2007 is fine. The current file is 2003, though, unfortunately...

            – JaidynReiman
            Sep 9 '11 at 3:10





            I'll have to ask him about it. I've seen that it HAS been implemented, and it shows it right in the documentation, but it didn't work for me. Another person who posted a work item apparently had got it working, it just didn't have the advanced features. I was starting to think, though, that I may have been trying to output the wrong type of Excel file. I'll go and ask my client if using Excel 2007 is fine. The current file is 2003, though, unfortunately...

            – JaidynReiman
            Sep 9 '11 at 3:10











            1














            PHPSpreadsheet have a much nicer implementation if you want your whole sheet auto-filtered:



                $sheet->setAutoFilter(
            $sheet->calculateWorksheetDimension()
            );





            share|improve this answer




























              1














              PHPSpreadsheet have a much nicer implementation if you want your whole sheet auto-filtered:



                  $sheet->setAutoFilter(
              $sheet->calculateWorksheetDimension()
              );





              share|improve this answer


























                1












                1








                1







                PHPSpreadsheet have a much nicer implementation if you want your whole sheet auto-filtered:



                    $sheet->setAutoFilter(
                $sheet->calculateWorksheetDimension()
                );





                share|improve this answer













                PHPSpreadsheet have a much nicer implementation if you want your whole sheet auto-filtered:



                    $sheet->setAutoFilter(
                $sheet->calculateWorksheetDimension()
                );






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 3 at 10:07









                Ng Sek LongNg Sek Long

                595417




                595417






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f7344707%2fhow-to-generate-excel-file-with-autofilters-in-php%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

                    SQL update select statement

                    'app-layout' is not a known element: how to share Component with different Modules