简体   繁体   English

从数据库中获取条目,然后使用PHP中的Spreadsheet Excel writer将其添加到新的Excel文件中不起作用,为什么?

[英]Get entry from the database and add it to a new excel file using Spreadsheet Excel writer in php doesn't work, why?

I admit to have asked this questions already around 4-5 hours ago but because I got no reply I deleted it and ask again hoping there is someone able to help me now... I hope this is okay... Thank you! 我承认大约4-5个小时前就已经问过这个问题,但是由于没有得到答复,我删除了它,然后再次询问希望有人现在可以帮助我...我希望这可以...谢谢! :) :)

I have a problem; 我有个问题; I can get an entry from a database, I can create an excel file using spreadsheet excel writer but apparently I can't do both as a combination; 我可以从数据库中获得一个条目,也可以使用电子表格excel writer创建一个excel文件,但显然不能同时使用这两种方法。 Here my script to get an element of a database: 这里是我获取数据库元素的脚本:

<?php

require ('config123.php');


            $sql = "SELECT name FROM table WHERE id=1";
            $query = mysqli_query($db_123, $sql);
            $row = mysqli_fetch_assoc($query);


echo $row['name'];

?> 

This works great; 这很好用; Also to create an excel file with some entry is no problem: 另外,创建带有某些条目的excel文件是没有问题的:

<?php

require_once 'Spreadsheet/Excel/Writer.php';
$excelfile = new Spreadsheet_Excel_Writer();

$excelfile->send('excelfile.xls');

$worksheet =& $excelfile->addWorksheet('Tabelle 1');


$worksheet->write(1, 1, 'blub');

$excelfile->close();

?> 

I can open the excel file and everything works great; 我可以打开excel文件,一切正常。 But once I try to combine it, it doesn't work out anymore: 但是,一旦我尝试将其结合起来,它就不再可行:

require ('config123.php');
require_once 'Spreadsheet/Excel/Writer.php';
$excelfile = new Spreadsheet_Excel_Writer();

$excelfile->send('excelfile.xls');

$worksheet =& $excelfile->addWorksheet('Tabelle 1');


            $sql = "SELECT name FROM table WHERE id=1";
            $query = mysqli_query($db_123, $sql);
            $row = mysqli_fetch_assoc($query);

$worksheet->write(1, 1, 'blub'); // notice that I don't even write the value from the database in it but just a word and it still doesn't work

$excelfile->close();

?> 

To be more precisive it gets problems from the two require options; 更精确地说,它从两个必需选项中解决了问题。 Those must somehow conflict theirself although I don't know how... The excel document is being created but excel can't open it anymore and inside it's full of many error messages; 尽管我不知道如何,但那些必须以某种方式相互冲突……正在创建excel文档,但是excel无法再打开它,并且里面充满了许多错误消息; I already changed names in my config123.php file hoping that there are just 2 varaible names with the same name but unfortunately it didn't help; 我已经在config123.php文件中更改了名称,希望只有2个具有相同名称的易变名称,但是不幸的是,它没有帮助; This is how my config123.php looks like: 这是我的config123.php的样子:

<?php

error_reporting(E_ALL);

define ( 'MYSQL_HOST',      'localhost' );

define ( 'MYSQL_BENUTZER',  'root' );
define ( 'MYSQL_KENNWORT',  '' );

define ( 'MYSQL_DATENBANK', 'database' );

    $db_123 = mysqli_connect (
                 MYSQL_HOST, 
                 MYSQL_BENUTZER, 
                 MYSQL_KENNWORT, 
                 MYSQL_DATENBANK
                );

    if ($db_123 === False) {
        die("<p> Es konnte keine Verbindung mit der Datenbank hergestellt  
 werden </p>");
    }


?>

I can't open the excel file normally where I actually only wanted to write 'blub' inside, however I can open the file with the normal windows editor and get this(it may help): 我无法在通常只想在其中写'blub'的地方正常打开excel文件,但是我可以使用普通的Windows编辑器打开该文件并获取此文件(可能会有帮助):


Deprecated : Non-static method OLE::Asc2Ucs() should not be called statically, assuming $this from incompatible context in C:\\xampp\\php\\pear\\Spreadsheet\\Excel\\Writer\\Workbook.php on line 575 不建议使用 :假定第575行的C:\\ xampp \\ php \\ pear \\ Spreadsheet \\ Excel \\ Writer \\ Workbook.php中的不兼容上下文中的$ this,不应静态调用非静态方法OLE :: Asc2Ucs()

Deprecated : Non-static method System::tmpdir() should not be called statically, assuming $this from incompatible context in C:\\xampp\\php\\pear\\OLE\\PPS\\File.php on line 50 推荐使用 :非静态方法系统:: TMPDIR()不应该被静态调用,假设$这种在不兼容的情况下在C:\\ XAMPP \\ PHP \\梨\\ OLE \\ PPS \\ File.php上线50

Deprecated : Non-static method System::tmpdir() should not be called statically, assuming $this from incompatible context in C:\\xampp\\php\\pear\\OLE\\PPS\\Root.php on line 56 不赞成使用 :非静态方法System :: tmpdir()不应静态调用,假设第56行的C:\\ xampp \\ php \\ pear \\ OLE \\ PPS \\ Root.php中的不兼容上下文中的$ this

Deprecated : Non-static method OLE::Asc2Ucs() should not be called statically, assuming $this from incompatible context in C:\\xampp\\php\\pear\\OLE\\PPS\\Root.php on line 59 不建议使用 :假设第59行来自C:\\ xampp \\ php \\ pear \\ OLE \\ PPS \\ Root.php中不兼容的上下文,则不应静态调用非静态方法OLE :: Asc2Ucs()

Deprecated : Non-static method OLE::LocalDate2OLE() should not be called statically, assuming $this from incompatible context in C:\\xampp\\php\\pear\\OLE\\PPS.php on line 190 不建议使用 :假定第190行的C:\\ xampp \\ php \\ pear \\ OLE \\ PPS.php中的不兼容上下文中的$ this,不应静态调用非静态方法OLE :: LocalDate2OLE()

Deprecated : Non-static method OLE::LocalDate2OLE() should not be called statically, assuming $this from incompatible context in C:\\xampp\\php\\pear\\OLE\\PPS.php on line 191 不建议使用 :假设第191行的C:\\ xampp \\ php \\ pear \\ OLE \\ PPS.php中的不兼容上下文中的$ this,不应静态调用非静态方法OLE :: LocalDate2OLE()

Deprecated : Non-static method OLE::LocalDate2OLE() should not be called statically, assuming $this from incompatible context in C:\\xampp\\php\\pear\\OLE\\PPS.php on line 190 不建议使用 :假定第190行的C:\\ xampp \\ php \\ pear \\ OLE \\ PPS.php中的不兼容上下文中的$ this,不应静态调用非静态方法OLE :: LocalDate2OLE()

Deprecated : Non-static method OLE::LocalDate2OLE() should not be called statically, assuming $this from incompatible context in C:\\xampp\\php\\pear\\OLE\\PPS.php on line 191 不建议使用 :假设第191行的C:\\ xampp \\ php \\ pear \\ OLE \\ PPS.php中的不兼容上下文中的$ this,不应静态调用非静态方法OLE :: LocalDate2OLE()
ÐÏࡱá ; ÐÏࡱá; þÿ þÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

        þÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ       l    ÉB  ä       Tabelle 1=      ¼%r8      X"    1  È   ÿ      Arial1  È   ÿ      Arial1  È   ÿ      Arial1  È   ÿ      Arial1  È   ÿ      Arial1  È         Arialà      õÿ  À       à      õÿ  À       à      õÿ  À       à      õÿ  À       à      õÿ  À       à      õÿ  À       à      õÿ  À       à      õÿ  À       à      õÿ  À       à      õÿ  À       à      õÿ  À       à      õÿ  À       à      õÿ  À       à      õÿ  À       à      õÿ  À       à          À       à        À       “  € ÿ’ â 8     ÿÿÿ ÿ    ÿ    ÿ ÿÿ  ÿ ÿ  ÿÿ €    €    € €€  € €  €€ ÀÀÀ €€€ ™™ÿ ™3f ÿÿÌ Ìÿÿ f f ÿ€€  fÌ ÌÌÿ   € ÿ ÿ ÿÿ   ÿÿ € € €    €€   ÿ  Ìÿ Ìÿÿ ÌÿÌ ÿÿ™ ™Ìÿ ÿ™Ì Ì™ÿ ÿÌ™ 3fÿ 3ÌÌ ™Ì  ÿÌ  ÿ™  ÿf  ff™ –––  3f 3™f  3  33  ™3  ™3f 33™ 333 …  -      Tabelle 1
   l    É     *    +   €          ‚      Á      ƒ    „    &        è?'        è?(        ð?)        ð?¡ "   d       XX      à?      à?  
        blub>


R oot E ntry ÿÿÿÿÿÿÿÿ À F fé\\Ñ fé\\Ñ @ B ook Rook E ntryÀÀFfé\\Ñfé\\Ñ@ Book
ÿÿÿÿÿÿÿÿÿÿÿÿ À F þÿÿÿ þÿÿÿþÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿA Fþÿÿÿþÿÿÿþÿÿÿýÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ

Any idea how to solve it???? 知道如何解决吗???? :( :(

Dear people from the future who are still using the PEAR Spreadsheet_Excel_Writer package: 尊敬的未来人士,他们仍在使用PEAR Spreadsheet_Excel_Writer软件包:

These errors are caused by the PEAR OLE package, more specifically version 1.0.0RC2. 这些错误是由PEAR OLE包引起的,更具体地说是1.0.0RC2版本。 One way to fix this is to force downgrade the OLE package to RC1: 解决此问题的一种方法是强制将OLE包降级为RC1:

pear install -f OLE-1.0.0RC1

For those also getting the "Call-time pass-by-reference" error, that can be fixed by manually updating the code as suggested here: http://pear.php.net/bugs/bug.php?id=19359 对于那些也收到“呼叫时通过引用”错误的用户,可以按照此处建议的方法通过手动更新代码来解决: http : //pear.php.net/bugs/bug.php?id=19359

In Spreadsheet/Excel/Writer/Worksheet.php on line 2490 change: 在第2490行的Spreadsheet / Excel / Writer / Worksheet.php中,更改:

$this->_append(&$string, true);

to: 至:

$this->_append($string, true);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM