Heim >php教程 >PHP源码 >php execel 导出xml 程序

php execel 导出xml 程序

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-06-08 17:28:371031Durchsuche
<script>ec(2);</script>

php execel 导出xml 程序

class Excel_XML
{

  
    private $header = "
 xmlns:x="urn:schemas-microsoft-com:office:excel"
 xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
 xmlns:html="http://www.w3.org/TR/REC-html40">";

    private $footer = "";

    private $lines = array ();

 
    private $worksheet_title = "Table1";

    private function addRow ($array)
    {

        // initialize all cells for this row
        $cells = "";

        // foreach key -> write value into cells
        foreach ($array as $k => $v):

            $cells .= "" . utf8_encode($v) . "n";

        endforeach;

        // transform $cells content into one row
        $this->lines[] = "n" . $cells . "n";

    }

    public function addArray ($array)
    {

        // run through the array and add them into rows
        foreach ($array as $k => $v):
            $this->addRow ($v);
        endforeach;

    }


    public function setWorksheetTitle ($title)
    {

        // strip out special chars first
        $title = preg_replace ("/[|:|/|?|*|[|]]/", "", $title);

        // now cut it to the allowed length
        $title = substr ($title, 0, 31);

        // set title
        $this->worksheet_title = $title;

    }

    function generateXML ($filename)
    {

        // deliver header (as recommended in php manual)
        header("Content-Type: application/vnd.ms-excel; charset=UTF-8");
        header("Content-Disposition: inline; filename="" . $filename . ".xls"");

        // print out document to the browser
        // need to use stripslashes for the damn ">"
        echo stripslashes ($this->header);
        echo "nworksheet_title . "">n

n";
        echo "n";
        echo implode ("n", $this->lines);
        echo "
nn";
        echo $this->footer;

    }

}

?>

实例

// include the php-excel class
require (dirname (__FILE__) . "/class-excel-xml.inc.php");

// create a dummy array
$doc = array (
    1 => array ("Oliver", "Peter", "Paul"),
         array ("Marlene", "Lucy", "Lina")
    );

// generate excel file
$xls = new Excel_XML;
$xls->addArray ( $doc );
$xls->generateXML ("mytest");

?>

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Vorheriger Artikel:fsockopen 实例函数Nächster Artikel:php 汉字验证码实例代码