<?php

//php test_xlsxwriter.php >out.xlsx
//Generates a spreadsheet with multiple sheets, 10K rows, 10 columns
include_once __DIR__ . '/../xlsxwriter.class.php';
$headers = array('id' => 'string', 'name' => 'string', 'description' => 'string', 'n1' => 'string', 'n2' => 'string', 'n3' => 'string', 'n4' => 'string', 'n5' => 'string', 'n6' => 'string', 'n7' => 'string');
$sheet_names = array('january', 'february', 'march', 'april', 'may', 'june');
$start = microtime(true);
$writer = new XLSXWriter();
foreach ($sheet_names as $sheet_name) {
    $writer->writeSheetHeader($sheet_name, $headers);
    for ($i = 0; $i < 10000; $i++) {
        $writer->writeSheetRow($sheet_name, random_row());
    }
}
$writer->writeToStdOut();
file_put_contents("php://stderr", '#' . floor(memory_get_peak_usage() / 1024 / 1024) . "MB" . "\n");
file_put_contents("php://stderr", '#' . sprintf("%1.2f", microtime(true) - $start) . "s" . "\n");
function random_row()
{
    return $row = array(rand() % 10000, chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)) . chr(rand(97, 122)), md5(uniqid()), rand() % 10000, rand() % 10000, rand() % 10000, rand() % 10000, rand() % 10000, rand() % 10000, rand() % 10000);
}
예제 #2
0
}
if (!mysql_select_db("poll", $con)) {
    die("Error: " . mysql_error());
}
function random_row($table)
{
    $sql = "SELECT MAX(id) maxid FROM " . $table;
    $id = mysql_fetch_object(mysql_query($sql));
    do {
        $rndid = rand(1, $id->maxid);
        $sql = "SELECT * FROM " . $table . " WHERE id = " . $rndid;
        $rnd = mysql_fetch_object(mysql_query($sql));
    } while (!$rnd);
    return $sql;
}
$sql = random_row('poll');
$sql = mysql_query($sql, $con);
$sql = mysql_fetch_array($sql);
$poll_id = $sql['poll_ID'];
$question = $sql['question'];
echo '<?xml version="1.0" encoding="utf-8"?>';
echo '<ResponseInfo ver="1" req="GetNextMCQuestion" statusCode="0" errorMsg="">';
echo "<qid>" . $poll_id . "</qid>";
echo "<title>" . $question . "</title>";
$results = mysql_query("SELECT * FROM results\r\n  WHERE poll_ID='" . $poll_id . "'");
while ($row = mysql_fetch_array($results)) {
    echo "<choice>";
    echo $row['value'];
    echo "</choice>";
}
echo "</ResponseInfo>";