我有一个有时间输入的Excel文件。
  Mar 01, 2018  | Thursday  | 8:00 AM | 5:00 PM
  Mar 02, 2018  | Friday    | 8:00 AM | 5:00 PM
但是,当我的代码尝试读取这些单元格时,输出将变为浮点型(例如8:00 AM变为0.33333333333333)。这是我的代码
$date = $sheet->getCell("A".$row)->getValue();
$time_in = $sheet->getCell("C".$row)->getValue();
$time_out = $sheet->getCell("D".$row)->getValue();
echo "date: ".$date.          //Mar 01, 2018
     " time_in: ".$time_in.   //becomes 0.333333333333333
     " time_out: ".$time_out; //becomes 0.708333333333333
如何在不更改phpspreadsheet值的情况下原样输出?我尝试查看phpspreadsheet文档,但未找到解决方案。
再会。我使用 PhpSpreadsheet 的库来导入 xlsx。
在 xlsx 中的 I 列中,我有这个值20/10/1970 00:00:00显示,1970-10-20 00:00:00但是当我导入它时:
$dataArray = $spreadsheet->getActiveSheet()
->rangeToArray(
    'A2:AO3',    // The worksheet range that we want to retrieve
    NULL,        // Value that should be returned for empty cells
    NULL,        // Should formulas be calculated (the equivalent of getCalculatedValue() for each cell)
    TRUE,        // Should values be formatted (the equivalent of getFormattedValue() for each cell)
    TRUE         // Should the array be indexed by cell row and cell column
);
我收到奇怪的消息, …
在文档中
我没有找到任何适合我需要的有用功能。
是否可以“重置”/“删除单个单元格的整个格式”?将单元格恢复到原始状态。
我正在使用这个库.xlsx从我的PHP脚本创建文件。
按照本指南,我尝试将一些数据导出到名为hello.xlsx.
但是,此错误会显示以下消息:
警告:ZipArchive::close():创建临时文件失败:供应商/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer 中的权限被拒绝
致命错误:未捕获的 PhpOffice\PhpSpreadsheet\Writer\Exception:无法关闭 zip 文件 hello.xlsx。在第 399 行的 vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php 中
PhpOffice\PhpSpreadsheet\Writer\Exception: 无法关闭 zip 文件 hello.xlsx。在 /vendor/phpoffice/phpspreadsheet/src/PhpSpreadsheet/Writer/Xlsx.php 第 399 行
该文件不存在预执行所以我有点得到错误。我总是可以尝试touch hello.xlsx更改我的脚本以读取该文件并附加数据,但实际上,每次运行脚本时我都在尝试编写一个新文件。
这是我的(简化)代码:
require_once 'vendor/autoload.php';
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
$spreadsheet = new Spreadsheet();
$sheet = $spreadsheet->getActiveSheet();
$sheet->setCellValue('A1', 'foo');
$sheet->setCellValue('B1', 'bar');
$sheet->setCellValue('C1', 'foobar');
$sheet->setCellValue('D1', 'trey is the best');
$writer = new Xlsx($spreadsheet);
$writer->save('hello.xlsx');
转到错误中的那些行显示以下代码片段:
// Close file
if ($zip->close() === false) {
    throw new WriterException("Could not …我正在尝试几天,我不知道为什么它不起作用。我想在中间设置单元格值。我的输出如下:
我的预期输出如下:
我想每一列都必须以我为中心,我已经尝试过以下代码:-
$styleArray = [
        'font' => [
            'bold' => true,
        ],
        'alignment' => [
            'horizontal' => \PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_CENTER,
        ],
        'fill' => [
            'fillType' => \PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID,
            'startColor' => [
                'argb' => '0070C0',
            ],
            'endColor' => [
                'argb' => '0070C0',
            ],
        ],
    ];
    $spreadsheet->getDefaultStyle()->getFont()->setSize(10);
    }
我已经尝试了所有其他属性,例如HORIZONTAL_CENTER,RIGHT,LEFT,JUSTIFY..etc。请帮助我,我该怎么做。
最近,在我基于CodeIgniter的一个项目中,我需要从Excel文件(.xlsx和.xls)读取数据,并将这些数据插入MySQL。不幸的是,我以前没有使用过PHPSpreadsheet(因为我不需要使用Excel :()。
到目前为止,我所做的是,从Github 下载PHPSpreadsheet并将其解压缩到我的CodeIgniter项目的根目录中。
 CodeIgniter根目录中的PHPSpreadsheet。
CodeIgniter根目录中的PHPSpreadsheet。
到目前为止,我已经尝试将官方文档示例导入到我的CI应用程序中:
<?php
    defined('BASEPATH') OR exit('No direct script access allowed');
    use PhpOffice\PhpSpreadsheet\IOFactory;
    class Welcome extends CI_Controller {
       function __construct() {
           parent::__construct();
       }
       public function index()
       {
           $inputFileType = 'Xlsx';
           $inputFileName = 'test.xlsx';
           $reader = \PhpOffice\PhpSpreadsheet\IOFactory::createReader($inputFileType);
    /**  Load $inputFileName to a Spreadsheet Object  **/
          $spreadsheet = $reader->load($inputFileName);
          print_r( $spreadsheet );
    }
}
谁能告诉我如何在CodeIgniter中使用PHPSpreadsheet从Excel文件中读取数据并将其存储到MySQL数据库中?
这不是一个特别的编码问题。
我有一个在本地运行的脚本 (PHP V5.6),它绝对是完美的。
但是,我将它通过 FTPd 传输到我们的开发服务器以作为 cron 运行,但它失败了。我们的服务器运行 php v5.5 以解决依赖性问题。有什么方法可以让用户 composer require 在运行 PHP 5.5 的机器上安装 phpspreadsheet?
我想在我的项目中使用 PHPSpreadsheet 库将数据导出到导出的文件中,但是当我尝试打开文件时,此错误显示:excel 无法打开文件,因为文件格式或文件扩展名无效。验证文件未损坏
注意:我在我的项目中使用 MVC,所以控制器中的代码如下:
       protected function Excel($view, $variables = [])
{
  require_once PATH_LIBRARY_FOLDER.'PhpSpreadsheet\vendor\autoload.php';
  ob_start();
  // Note: make new Spreadsheet object
  $spreadsheet = new Spreadsheet();
  // Note: get current active sheet (frist sheet)
  $sheet = $spreadsheet->getActiveSheet();
  $sheet->setCellValue('A1', 'Hello World !');
  extract($variables);
  include($this->viewPath.$view.'.php');
  // Note: set the header to define it is excel file
  header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
  // Note: set the header to define excel file name
  header("Content-Disposition: attachment;filename=\"filename.xlsx\"");
  header("Cache-Control: max-age=0");
  // Note: create IOFactory object
  $writer = IOFactory::createWriter($spreadsheet, 'xlsx');
  ob_get_clean(); …我已经通过作曲家安装了PhpSpreadsheet,现在需要知道服务提供商才能输入app.php才能在控制器中使用它。