예제 #1
0
<?php

include "excel.php";
//parse le document excel et le retourne comme un tableau
$excel = getExcel('/var/www/html/rezo/Hosts.xlsx', '/var/www/html/rezo/xls/');
$vlans = array();
//va contenir la liste des différents vlan
for ($i = 0; $i < count($excel); $i++) {
    //pour chaque case du tableau on cherche à connaître tous les vlans
    foreach ($excel[$i] as $aa => $bb) {
        if (strstr($aa, "VLAN")) {
            $vlane = $bb;
        }
        $change = 0;
        //incrément si le vlan présent à la case est déjà rentré
        foreach ($vlans as $vlan) {
            if ($vlane == $vlan) {
                $change++;
            }
        }
        if ($change == 0 && $vlane != "") {
            $vlans[] = $vlane;
        }
    }
}
//->pour la récupération des vlans
//si la demande d'ip est faîte
if (isset($_POST["vlan"])) {
    for ($i = 0; $i < count($excel); $i++) {
        $data = var_export($excel[$i], true);
        //contient toutes les chaînes de caractère de la ligne excel
예제 #2
0
<?php

/**
 * PHPEXCEL生成excel文件
 * @author:firmy
 * @desc 支持任意行列数据生成excel文件,暂未添加单元格样式和对齐
 */
ini_set('memory_limit', '120M');
require_once 'Classes/PHPExcel.php';
require_once 'Classes/PHPExcel/Writer/Excel2007.php';
require_once 'Classes/PHPExcel/Writer/Excel5.php';
include_once 'Classes/PHPExcel/IOFactory.php';
$fileName = "test_excel";
$headArr = array("aaa", "bbb", "ccc");
$data = array(array(iconv('gbk', 'utf-8', '中文Hello'), 2, 5), array(1, 3, 6), array(5, 7, 8));
getExcel($fileName, $headArr, $data);
function getExcel($fileName, $headArr, $data)
{
    if (empty($data) || !is_array($data)) {
        die("data must be a array");
    }
    if (empty($fileName)) {
        exit;
    }
    $date = date("Y_m_d", time());
    $fileName .= "_{$date}.xlsx";
    //创建新的PHPExcel对象
    $objPHPExcel = new PHPExcel();
    $objProps = $objPHPExcel->getProperties();
    //设置表头
    $key = ord("A");
예제 #3
0
/*
    批量处理gbk->utf-8
*/
function icon_to_utf8($s)
{
    if (is_array($s)) {
        foreach ($s as $key => $val) {
            $s[$key] = icon_to_utf8($val);
        }
    } else {
        $s = ct2($s);
    }
    return $s;
}
$fileName = "AirData";
getExcel($fileName);
function getExcel($fileName)
{
    $date = date('Y-m-d h:i:s', time());
    $fileName .= "_{$date}.xls";
    $filename1 = "data.json";
    //bug : if you use "/data.json", you cannnot open this file . you need to use "data.json"
    $json_string = file_get_contents($filename1);
    //$json2_string = icon_to_utf8($json_string);
    $obj = json_decode($json_string, true);
    $objPHPExcel = new PHPExcel();
    $objProps = $objPHPExcel->getProperties();
    $baseRow = 1;
    foreach ($obj as $r => $dataRow) {
        $row = $baseRow + $r;
        $objPHPExcel->getActiveSheet()->insertNewRowBefore($row, 1);