Создание excel-таблиц с помощью php

StDyavol

Новичок
Создание excel-таблиц с помощью php

ситуация такова: есть страничка, при переходе на которую запускается php-скрипт и генерит excel-тблицу с банными из БД...
корочеговоря дамп в escel-формате....
все работает... вот только никак не получается заставить срипт рисовать границы таблицы (ее структуру), помимо внесения данных в ячейки....
вот код:
PHP:
//execute query                              
$result =  @mysql_query($zapros,$li)
    or die("Ошибка при обработке запроса:<br>" . mysql_error(). "<br>" . mysql_errno());

$file_type = "vnd.ms-excel";
$file_ending = "xls";

//header info for browser: determines file type
header("Content-Type: application/$file_type");
header("Content-Disposition: attachment; filename=History.$file_ending");
header("Pragma: no-cache");
header("Expires: 0");

//create title with timestamp:
if ($Use_Title == 1){
echo("$title\n");
}
//define separator (defines columns in excel & tabs in word)
$sep = "\t"; //tabbed character

//start of printing column names as names of MySQL fields
for ($i = 0; $i < mysql_num_fields($result); $i++) {
echo mysql_field_name($result,$i) . "\t";
}
print("\n");
//end of printing column names

//start while loop to get data
/*
note: the following while-loop was taken from phpMyAdmin 2.1.0.
--from the file "lib.inc.php".
*/
    while($row = mysql_fetch_row($result))
    {
        //set_time_limit(60); // HaRa
        $schema_insert = "";
        for($j=0; $j<mysql_num_fields($result);$j++)
        {
            if(!isset($row[$j]))
                $schema_insert .= "NULL".$sep;
            elseif ($row[$j] != "")
                $schema_insert .= "$row[$j]".$sep;
            else
                $schema_insert .= "".$sep;
        }
        $schema_insert = str_replace($sep."$", "", $schema_insert);
		//following fix suggested by Josue (thanks, Josue!)
		//this corrects output in excel when table fields contain \n or \r
		//these two characters are now replaced with a space
		$schema_insert = preg_replace("/\r\n|\n\r|\n|\r/", " ", $schema_insert);
        $schema_insert .= "\t";
        print(trim($schema_insert));
        print "\n";
    }
впринципе код достаточно простой....

скажите возможно ли реализовать мою задачу вообще... если да, то как?
все заранее спасибо!
P.S. честно признаюсь этот код писал не я... просто скачал с какого-то сайта...:cool:
 

dimagolov

Новичок
возможно ли реализовать мою задачу вообще
да
P.S. честно признаюсь этот код писал не я... просто скачал с какого-то сайта...
ну так разберись что он делает, и тогда ответ на вопрос "реализовать мою задачу... как" будет очевидным

п.с. загляни в полученный файл, много нового узнаешь
 

DiMA

php.spb.ru
Команда форума
эксель можно генерить хтмл кодом
в экселе рисуешь нужный вид документа, сохраняешь как хтмл
на пхп воспроизводишь
 
Сверху