ExportExcel.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. /**
  3. * Class for exporting CSV dumps of tables for excel
  4. */
  5. declare(strict_types=1);
  6. namespace PhpMyAdmin\Plugins\Export;
  7. use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyMainGroup;
  8. use PhpMyAdmin\Properties\Options\Groups\OptionsPropertyRootGroup;
  9. use PhpMyAdmin\Properties\Options\Items\BoolPropertyItem;
  10. use PhpMyAdmin\Properties\Options\Items\HiddenPropertyItem;
  11. use PhpMyAdmin\Properties\Options\Items\SelectPropertyItem;
  12. use PhpMyAdmin\Properties\Options\Items\TextPropertyItem;
  13. use PhpMyAdmin\Properties\Plugins\ExportPluginProperties;
  14. use function __;
  15. /**
  16. * Handles the export for the CSV-Excel format
  17. */
  18. class ExportExcel extends ExportCsv
  19. {
  20. /**
  21. * @psalm-return non-empty-lowercase-string
  22. */
  23. public function getName(): string
  24. {
  25. return 'excel';
  26. }
  27. protected function setProperties(): ExportPluginProperties
  28. {
  29. $exportPluginProperties = new ExportPluginProperties();
  30. $exportPluginProperties->setText('CSV for MS Excel');
  31. $exportPluginProperties->setExtension('csv');
  32. $exportPluginProperties->setMimeType('text/comma-separated-values');
  33. $exportPluginProperties->setOptionsText(__('Options'));
  34. // create the root group that will be the options field for
  35. // $exportPluginProperties
  36. // this will be shown as "Format specific options"
  37. $exportSpecificOptions = new OptionsPropertyRootGroup('Format Specific Options');
  38. // general options main group
  39. $generalOptions = new OptionsPropertyMainGroup('general_opts');
  40. // create primary items and add them to the group
  41. $leaf = new TextPropertyItem(
  42. 'null',
  43. __('Replace NULL with:')
  44. );
  45. $generalOptions->addProperty($leaf);
  46. $leaf = new BoolPropertyItem(
  47. 'removeCRLF',
  48. __('Remove carriage return/line feed characters within columns')
  49. );
  50. $generalOptions->addProperty($leaf);
  51. $leaf = new BoolPropertyItem(
  52. 'columns',
  53. __('Put columns names in the first row')
  54. );
  55. $generalOptions->addProperty($leaf);
  56. $leaf = new SelectPropertyItem(
  57. 'edition',
  58. __('Excel edition:')
  59. );
  60. $leaf->setValues(
  61. [
  62. 'win' => 'Windows',
  63. 'mac_excel2003' => 'Excel 2003 / Macintosh',
  64. 'mac_excel2008' => 'Excel 2008 / Macintosh',
  65. ]
  66. );
  67. $generalOptions->addProperty($leaf);
  68. $leaf = new HiddenPropertyItem('structure_or_data');
  69. $generalOptions->addProperty($leaf);
  70. // add the main group to the root group
  71. $exportSpecificOptions->addProperty($generalOptions);
  72. // set the options for the export plugin property item
  73. $exportPluginProperties->setOptions($exportSpecificOptions);
  74. return $exportPluginProperties;
  75. }
  76. }