PHP PEAR电子表格Excel Writer数据限制

时间:2015-03-23 19:39:20

标签: php spreadsheet export-to-excel pear writer

我遇到PEAR问题,这个问题似乎很奇怪。

我正在使用php生成一个电子表格,我循环几个段落以创建一个大小调整表。只要我在图表中使用少量细节,脚本就会被执行,但似乎有一个限制。一旦超过该数字,我将收到致命错误消息。

这是我用于工作簿的代码:

require_once'../ Spreadsheet / Excel / Writer.php';

        $workbook = new Spreadsheet_Excel_Writer('sizecharts/'.$file.'.xls');

        $worksheet =& $workbook->addWorksheet('NL Worksheet '.$itemname);
        $workbook->setVersion(8);

        $format_top =& $workbook->addFormat();
        $format_top->setAlign('top');
        $format_top->setTextWrap(1);

        $format_center =& $workbook->addFormat();
        $format_center->setAlign('center');

        $format_heading1 =& $workbook->addFormat();
        $format_heading1->setAlign('center');
        $format_heading1->setBold(1);
        $format_heading1->setSize(16);

        $format_info =& $workbook->addFormat();
        $format_info->setAlign('center');
        $format_info->setBold(1);
        $format_info->setSize(12);

        $bold =& $workbook->addFormat();
        $bold->setBold(1);

        $details =& $workbook->addFormat();
        $details->setBorder(1);

        $details_header =& $workbook->addFormat();
        $details_header->setBold(1);
        $details_header->setBorder(1);

        $details_cell =& $workbook->addFormat();
        $details_cell->setBorder(1);
        $details_cell->setAlign('center');

        $details_cell_header =& $workbook->addFormat();
        $details_cell_header->setBold(1);
        $details_cell_header->setBorder(1);
        $details_cell_header->setAlign('center');

        $details_num =& $workbook->addFormat();
        $details_num->setBold(1);
        $details_num->setBorder(1);
        $details_num->setAlign('right');


        $worksheet->setMerge(1,0,1,$size_count-1);
        $worksheet->setMerge(3,0,3,$size_count-1);
        $worksheet->setMerge(5,0,5,$size_count-1);

        $worksheet->setInputEncoding('utf-8');
        $worksheet->write(1, 0, 'MYCOMPANY', $format_heading1);
        $worksheet->write(3, 0, '耐斯德克服饰(上海)有限公司', $format_heading1);
        $worksheet->write(5, 0, 'Measurements  '.$itemname, $format_info);

        $worksheet->setInputEncoding('ISO-8859-7');
        $worksheet->write(7, $size_count-2, 'File#:');
        $worksheet->write(7, $size_count-1, $file);

        $worksheet->write(8, 0, 'Date:');
        $worksheet->write(8, 1, $date);

        $worksheet->write(9, 0, 'Customer:');
        $worksheet->write(9, 1, $customer);

        $worksheet->write(10, 0, 'Item Type:');
        $worksheet->write(10, 1, $type);

        $worksheet->write(11, 0, 'Units:');
        $worksheet->write(11, 1, $unit);

        $worksheet->setColumn(0,0,10);
        $worksheet->setColumn(0,1,30);

        $worksheet->write(13, 0, '#',$details_num);
        $worksheet->write(13, 1, 'Details:',$details_header);




        for($k=1;$k<($size_count-1);$k++){

            $size_collect_xls   = $sizes_arr[$k];

            $worksheet->setInputEncoding('utf-8');  
            $worksheet->write(13,$k+1, $size_collect_xls,$details_cell_header);
            $worksheet->setInputEncoding('ISO-8859-7');

        }


        for($i=0;$i<$count;$i++){

            if(isset($_POST['details'][$i])){   

            $detail             = $_POST['details'][$i];    

            $worksheet->write(14+$i, 0, ($i+1).'.',$details_num);
            $worksheet->write(14+$i, 1, $detail,$details);

            $det_collect        = "";

                        for($k=1;$k<($size_count-1);$k++){


                            $key                = "det".$k;

                            $det_collect_val    = $_POST[$key][$i]; 

                            $worksheet->write(14+$i,$k+1, $det_collect_val,$details_cell);

                        }


            }

        }           


        // We still need to explicitly close the workbook
        $workbook->close();
        ?>

我用这个来写文件。

我后来得到的是此错误消息

 <b>Fatal error</b>:  Call to undefined method PEAR_Error::setInputEncoding() in <b>/home/MYCOMPANY/www/www/quotbot/sizechartinput.php</b> on line <b>740</b><br />

这是指这行代码:

 $worksheet->setMerge(1,0,1,$size_count-1);

如果我交换这一行,请说:

 $worksheet->setInputEncoding('utf-8');

我的错误消息更改为:

 <b>Fatal error</b>:  Call to undefined method PEAR_Error::setInputEncoding()

在这种情况下,错误报告编码而不是单元格存在问题。所以这意味着该命令没有问题。生成的工作表中的数据量更是一个问题。

那么插入到Excel工作表中的数据量有限制吗?

1 个答案:

答案 0 :(得分:2)

这是无关的。

该行

$worksheet =& $workbook->addWorksheet('NL Worksheet '.$itemname);

可以在成功时返回“对工作表对象的引用,在失败时返回PEAR_Error”(ref here)。该错误消息告诉您正在PEAR_Error上调用未定义的方法,这意味着您的调用失败。

您需要在该行之后检查 addWorksheet 是否成功。从文档中获取的简单示例:

// Make sure the worksheet name is less than 31 characters
$worksheet =& $workbook->addWorksheet(substr('NL Worksheet '.$itemname, 0, 31));
if (PEAR::isError($worksheet)) {
    die($worksheet->getMessage());
}