doutao1282 2017-08-25 11:30
浏览 84
已采纳

如何通过PHP访问.xlsb文件?

I need to access an .xlsb file that does the same function as this code that accesses a .csv file:

<?php
$file1 = __DIR__ . '/download/Trabalhos.csv';
$csv1 = file($file1);
foreach ($csv1 as $row1 => $line1) {
    $row1++;
    $column1 = str_getcsv($line1, ';');
    if ($row1 == 2) {
        $column1[6]."<br>";
        $valor1 = $column1[6];
    }
}

$file2 = __DIR__ . '/download/produtividade do trabalho.csv';
$csv2 = file($file2);
foreach ($csv2 as $row2 => $line2) {
    $row2++;
    $column2 = str_getcsv($line2, ';');
    if ($row2 == 3) {
        $column2[9]."<br>";
        $valor2 = $column2[9];
    }
}
$file3 = __DIR__ . '/download/inatividade do trabalho.csv';
$csv3 = file($file3);
foreach ($csv3 as $row3 => $line3) {
    $row3++;
    $column3 = str_getcsv($line3, ';');
    if ($row3 == 2) {
        $column3[0]."<br>";
        $valor3 = $column3[0];
    }
}

$total = $valor1 * $valor2 * $valor3;

?>

Access the .xlsb file, scroll through the columns and rows, and display the row value on the screen.

Example: "Line 2, Column G(In this case, G = 6)
"A = 0
B = 1
C = 2)"
...

I want it to show me the value of row 2 that is in column G(6).

As in the first if ...

if ($row1 == 2) {
        $column1[6]."<br>";
        $valor1 = $column1[6];
    }

</div>
  • 写回答

2条回答 默认 最新

  • dongming4994 2017-08-26 11:33
    关注

    You can use the PHP Excel library from EasyXLS.

    $xls = new COM("EasyXLS.ExcelDocument");
    $rows = $xls->easy_ReadXLSBActiveSheet_AsList("Trabalhos.xlsb");
    for ($row1=0; $row1<$rows->size(); $row1++)
    {
        $rowLine = $rows->elementAt($row1);
            if ($row1 == 2) {
                $column1[6]."<br>";
                $valor1 = $row->elementAt(6);
            }
    }
    

    You can find some more code samples about importing data from xlsb file.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。