- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这里下载了 Box/Spout https://github.com/box/spout但我在启动 Spout 时遇到问题。
我将文件复制到 WAMP 的文件夹中。
<?php
use Box\Spout\Writer\WriterFactory;
use Box\Spout\Common\Type;
$writer = WriterFactory::create(Type::XLSX);
$writer->openToBrowser($fileName); // stream data directly to the browser
$writer->addRows($multipleRows); // add multiple rows at a time
$writer->close();
?>
( ! ) Fatal error: Class 'Box\Spout\Writer\WriterFactory' not found in C:\wamp\www\Spout\Index.php on line 5
最佳答案
下载文件是不够的。如果您不使用 Composer(这是使用 Spout 的推荐方式),您需要添加一个额外的自动加载器(它将为您自动加载类)。由于 Spout 符合 PSR4,因此自动加载其类并不难。
以下是一些可用于自动加载 Spout 类的工作代码:
Psr4Autoloader.php
<?php
namespace Autoloader;
class Psr4Autoloader
{
/**
* An associative array where the key is a namespace prefix and the value
* is an array of base directories for classes in that namespace.
*
* @var array
*/
protected $prefixes = array();
/**
* Register loader with SPL autoloader stack.
*
* @return void
*/
public function register()
{
spl_autoload_register(array($this, 'loadClass'));
}
/**
* Adds a base directory for a namespace prefix.
*
* @param string $prefix The namespace prefix.
* @param string $base_dir A base directory for class files in the
* namespace.
* @param bool $prepend If true, prepend the base directory to the stack
* instead of appending it; this causes it to be searched first rather
* than last.
* @return void
*/
public function addNamespace($prefix, $base_dir, $prepend = false)
{
// normalize namespace prefix
$prefix = trim($prefix, '\\') . '\\';
// normalize the base directory with a trailing separator
$base_dir = rtrim($base_dir, DIRECTORY_SEPARATOR) . '/';
// initialize the namespace prefix array
if (isset($this->prefixes[$prefix]) === false) {
$this->prefixes[$prefix] = array();
}
// retain the base directory for the namespace prefix
if ($prepend) {
array_unshift($this->prefixes[$prefix], $base_dir);
} else {
array_push($this->prefixes[$prefix], $base_dir);
}
}
/**
* Loads the class file for a given class name.
*
* @param string $class The fully-qualified class name.
* @return mixed The mapped file name on success, or boolean false on
* failure.
*/
public function loadClass($class)
{
// the current namespace prefix
$prefix = $class;
// work backwards through the namespace names of the fully-qualified
// class name to find a mapped file name
while (false !== $pos = strrpos($prefix, '\\')) {
// retain the trailing namespace separator in the prefix
$prefix = substr($class, 0, $pos + 1);
// the rest is the relative class name
$relative_class = substr($class, $pos + 1);
// try to load a mapped file for the prefix and relative class
$mapped_file = $this->loadMappedFile($prefix, $relative_class);
if ($mapped_file) {
return $mapped_file;
}
// remove the trailing namespace separator for the next iteration
// of strrpos()
$prefix = rtrim($prefix, '\\');
}
// never found a mapped file
return false;
}
/**
* Load the mapped file for a namespace prefix and relative class.
*
* @param string $prefix The namespace prefix.
* @param string $relative_class The relative class name.
* @return mixed Boolean false if no mapped file can be loaded, or the
* name of the mapped file that was loaded.
*/
protected function loadMappedFile($prefix, $relative_class)
{
// are there any base directories for this namespace prefix?
if (isset($this->prefixes[$prefix]) === false) {
return false;
}
// look through base directories for this namespace prefix
foreach ($this->prefixes[$prefix] as $base_dir) {
// replace the namespace prefix with the base directory,
// replace namespace separators with directory separators
// in the relative class name, append with .php
$file = $base_dir
. str_replace('\\', '/', $relative_class)
. '.php';
// if the mapped file exists, require it
if ($this->requireFile($file)) {
// yes, we're done
return $file;
}
}
// never found it
return false;
}
/**
* If a file exists, require it from the file system.
*
* @param string $file The file to require.
* @return bool True if the file exists, false if not.
*/
protected function requireFile($file)
{
if (file_exists($file)) {
require $file;
return true;
}
return false;
}
}
<?php
require_once "Psr4Autoloader.php";
$loader = new \Autoloader\Psr4Autoloader;
$loader->register();
$loader->addNamespace('Box\Spout', 'vendor/box/spout/src/Spout');
关于php - 发射箱喷口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30891534/
我正在尝试使用 DynamicMethod 并尝试使用 IL 来创建一些对象。我想创建以下非常基本的对象: new Queue(new List{100}); 我已经使用 ILDASM 查看生成此代码
这是我stackoverflow的第一个问题!我有一个显示 mpl 图 Canvas 的 PyQT gui。我已将主轴周围的边距设置为 0,因此绘图将完全填满图形 Canvas 和包含它的小部件。问题
我的环境是 Windows 7,安装了 scala 2.11.4(运行良好),Java 1.8 我已经尝试过 spark-1.2.0-bin-hadoop2.4 和 spark-1.2.1-bin-h
对于我的生活,我无法弄清楚为什么我不能发送或捕获一些数据。 toggleNavigation() 触发,但我不确定 .emit() 是否真的在工作。 最终我想折叠和展开导航,但现在我只想了解如何将数据
我试图在 VUE 3 中传递一个 emit prop,每次传递它时我仍然得到 false,并且 prop 无法切换。 Accordion .vue
我有一个 View 模型,它采用初始 ViewState对象并具有可公开访问的 state可以收集的变量。 class MyViewModel(initialState: ViewState) : V
现在在玩 RxJava,偶然发现了以下问题: 我有 2 个不同的流: 带有项目的流 Stream(只有 1 个项目),它发出第一个流的转换信息。 所以基本上我有项目流,我希望所有这些项目与第二个流中的
我有一个 API 登录服务,它使用 http 服务来执行登录逻辑(LoginApiService、login-api.service.ts): login(data: LoginCredentials
我们有微服务架构,我们通过网络进行服务间调用。我们在顶层服务中使用 RxJava,这会导致向底层服务创建大量并行请求。因此,我收到“没有到主机的路由错误”或“连接错误”。为此,我想减慢 RxJava
Vue.component('rating-edit', { template:` {{rating.remark}} Sav
我最近购买了 Dream Cheeky Thunder 导弹发射器,我希望通过我的树莓派来控制它。 使用来自报复的代码(https://raw.githubusercontent.com/codeda
我制作了这段代码来记录发送到我的机器人的 DM: client.on('messageCreate', async message => { if (message.author.bot) r
我需要从服务器代码、路由器/ Controller 上的任何位置发出来自服务器的套接字。我检查了一些线程和谷歌,但没有按预期工作。 app.js var app = require('express'
我是一名优秀的程序员,十分优秀!