Writer.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /*
  3. * Module written/ported by Xavier Noguer <xnoguer@rezebra.com>
  4. *
  5. * PERL Spreadsheet::WriteExcel module.
  6. *
  7. * The author of the Spreadsheet::WriteExcel module is John McNamara
  8. * <jmcnamara@cpan.org>
  9. *
  10. * I _DO_ maintain this code, and John McNamara has nothing to do with the
  11. * porting of this code to PHP. Any questions directly related to this
  12. * class library should be directed to me.
  13. *
  14. * License Information:
  15. *
  16. * Spreadsheet_Excel_Writer: A library for generating Excel Spreadsheets
  17. * Copyright (c) 2002-2003 Xavier Noguer xnoguer@rezebra.com
  18. *
  19. * This library is free software; you can redistribute it and/or
  20. * modify it under the terms of the GNU Lesser General Public
  21. * License as published by the Free Software Foundation; either
  22. * version 2.1 of the License, or (at your option) any later version.
  23. *
  24. * This library is distributed in the hope that it will be useful,
  25. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  26. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  27. * Lesser General Public License for more details.
  28. *
  29. * You should have received a copy of the GNU Lesser General Public
  30. * License along with this library; if not, write to the Free Software
  31. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  32. */
  33. //require_once(api_get_path(LIBRARY_PATH).'pear/PEAR.php');
  34. require_once 'Writer/Workbook.php';
  35. /**
  36. * Class for writing Excel Spreadsheets. This class should change COMPLETELY.
  37. *
  38. * @author Xavier Noguer <xnoguer@rezebra.com>
  39. * @category FileFormats
  40. * @package Spreadsheet_Excel_Writer
  41. */
  42. class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook
  43. {
  44. /**
  45. * The constructor. It just creates a Workbook
  46. *
  47. * @param string $filename The optional filename for the Workbook.
  48. * @return Spreadsheet_Excel_Writer_Workbook The Workbook created
  49. */
  50. function Spreadsheet_Excel_Writer($filename = '')
  51. {
  52. $this->_filename = $filename;
  53. $this->Spreadsheet_Excel_Writer_Workbook($filename);
  54. }
  55. /**
  56. * Send HTTP headers for the Excel file.
  57. *
  58. * @param string $filename The filename to use for HTTP headers
  59. * @access public
  60. */
  61. function send($filename)
  62. {
  63. header("Content-type: application/vnd.ms-excel");
  64. header("Content-Disposition: attachment; filename=\"$filename\"");
  65. header("Expires: 0");
  66. header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
  67. header("Pragma: public");
  68. }
  69. /**
  70. * Utility function for writing formulas
  71. * Converts a cell's coordinates to the A1 format.
  72. *
  73. * @access public
  74. * @static
  75. * @param integer $row Row for the cell to convert (0-indexed).
  76. * @param integer $col Column for the cell to convert (0-indexed).
  77. * @return string The cell identifier in A1 format
  78. */
  79. function rowcolToCell($row, $col)
  80. {
  81. if ($col > 255) { //maximum column value exceeded
  82. return new PEAR_Error("Maximum column value exceeded: $col");
  83. }
  84. $int = (int)($col / 26);
  85. $frac = $col % 26;
  86. $chr1 = '';
  87. if ($int > 0) {
  88. $chr1 = chr(ord('A') + $int - 1);
  89. }
  90. $chr2 = chr(ord('A') + $frac);
  91. $row++;
  92. return $chr1 . $chr2 . $row;
  93. }
  94. }
  95. ?>