9

In searching for an answer, I found lots of questions regarding turning a table into a spreadsheet, or outputting a spreadsheet into a table, but nothing about creating an Excel table within a spreadsheet with PHPExcel.

I'd like to create a table within Excel - that is, I'd like to isolate a section of cells/data from the rest of the spreadsheet, so that the data can be sorted and filtered independently from the rest of the sheet. This is the same as doing Insert -> Table in Excel.

This seems like a pretty common thing to do, but I can't find any way of doing it in the PHPExcel documentation.

How do I create a table within a spreadsheet using PHPExcel?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Luke Shaheen
  • 4,262
  • 12
  • 52
  • 82
  • such classes/scripts of course cannot do everything that microsoft office can do; if the functionality hasn't been made yet, you may need to submit a feature request for the future and hope it is popular enough. Try doing that in excel, saving as a .csv file and seeing if it still shows. If it doesn't it isn't easy to script it to make it work. – scott May 09 '12 at 16:05
  • I guess I'm more surprised that I can't seem to find anyone else asking for this, anywhere. Makes me think it's something that exists! – Luke Shaheen May 09 '12 at 16:07
  • No, php can be a bit limited to writing other file types of course. We should be happy it can write so many as is :) – scott May 09 '12 at 16:11

1 Answers1

4

Insert/Table is simply a GUI "shortcut" method for styling and setting autofilters against a block of cells. Both of these can be done as individual tasks using PHPExcel, but the library does not provide a "shortcut" way of doing this with a single method call.

Take a look at section 4.6.25 of the Developer documentation, and the 10autofilter.php example in the /Tests directory of the distribution

Mark Baker
  • 209,507
  • 32
  • 346
  • 385
  • 3
    Well, it's more than that. Table and column names can be used in formulas. If you manually styled and autofiltered a range of cells in Excel, it would not automatically treat it as a defined table that you could later work with in the Table Tools->Design tab in Excel. If I'm not mistaken, the newer Excel format is really just Zipped XML, so it would just be a matter of figuring out the XML to define an Excel Table. – livefree75 Jul 29 '13 at 19:57
  • @livefree - If it's as simple as you suggest, perhaps you'd care to submit a patch to the github repository for PHPExcel – Mark Baker Jul 29 '13 at 20:11
  • I didn't mean to imply that it would be simple - just possible. :) If I had the time, it would be an interesting exercise. – livefree75 Jul 30 '13 at 10:23
  • @MarkBaker thanks, i mixed filters with Pivot tables previously :D now all clear for me – Oleg Abrazhaev Jan 04 '19 at 13:19