~adamzammit/quexs/quexscativm

« back to all changes in this revision

Viewing changes to include/limesurvey/admin/classes/pear/Spreadsheet/Excel/Writer.php

  • Committer: azammitdcarf
  • Date: 2008-10-15 04:55:53 UTC
  • Revision ID: svn-v4:fd4a0071-7450-0410-a91b-842f6942ebe7:trunk:6
Import from DCARF SVN

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
34
if (isset($_REQUEST['homedir'])) {die('You cannot start this script directly');}
 
35
require_once $homedir.'/classes/pear/PEAR.php';
 
36
require_once $homedir.'/classes/pear/Spreadsheet/Excel/Writer/Workbook.php';
 
37
 
 
38
/**
 
39
* Class for writing Excel Spreadsheets. This class should change COMPLETELY.
 
40
*
 
41
* @author   Xavier Noguer <xnoguer@rezebra.com>
 
42
* @category FileFormats
 
43
* @package  Spreadsheet_Excel_Writer
 
44
*/
 
45
 
 
46
class Spreadsheet_Excel_Writer extends Spreadsheet_Excel_Writer_Workbook
 
47
{
 
48
    /**
 
49
    * The constructor. It just creates a Workbook
 
50
    *
 
51
    * @param string $filename The optional filename for the Workbook.
 
52
    * @return Spreadsheet_Excel_Writer_Workbook The Workbook created
 
53
    */
 
54
    function Spreadsheet_Excel_Writer($filename = '')
 
55
    {
 
56
        $this->_filename = $filename;
 
57
        $this->Spreadsheet_Excel_Writer_Workbook($filename);
 
58
    }
 
59
 
 
60
    /**
 
61
    * Send HTTP headers for the Excel file.
 
62
    *
 
63
    * @param string $filename The filename to use for HTTP headers
 
64
    * @access public
 
65
    */
 
66
    function send($filename)
 
67
    {
 
68
        header("Content-type: application/vnd.ms-excel");
 
69
        header("Content-Disposition: attachment; filename=\"$filename\"");
 
70
        header("Expires: 0");
 
71
        header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
 
72
        header("Pragma: public");
 
73
    }
 
74
 
 
75
    /**
 
76
    * Utility function for writing formulas
 
77
    * Converts a cell's coordinates to the A1 format.
 
78
    *
 
79
    * @access public
 
80
    * @static
 
81
    * @param integer $row Row for the cell to convert (0-indexed).
 
82
    * @param integer $col Column for the cell to convert (0-indexed).
 
83
    * @return string The cell identifier in A1 format
 
84
    */
 
85
    function rowcolToCell($row, $col)
 
86
    {
 
87
        if ($col > 255) { //maximum column value exceeded
 
88
            return new PEAR_Error("Maximum column value exceeded: $col");
 
89
        }
 
90
 
 
91
        $int = (int)($col / 26);
 
92
        $frac = $col % 26;
 
93
        $chr1 = '';
 
94
 
 
95
        if ($int > 0) {
 
96
            $chr1 = chr(ord('A') + $int - 1);
 
97
        }
 
98
 
 
99
        $chr2 = chr(ord('A') + $frac);
 
100
        $row++;
 
101
 
 
102
        return $chr1 . $chr2 . $row;
 
103
    }
 
104
}
 
105
?>