English 中文(简体)
PHPExcel: Spliting an Excel document summary
原标题:PHPExcel : Splitting an Excel document sheet by sheet
  • 时间:2011-10-01 08:38:35
  •  标签:
  • phpexcel

I m using PHPExcel library for many Excel manipulations, combined with PHP/MySQL. That helps me well.

But I can t figure how to split an Excel document sheet by sheet,where each sheet is created as a new Excel document.

同时,我还需要删除新印制的Excel文件原始文件中的空线(最后数字)。

What s the best way to do it ?

All your experiences are greatly appreciated.

最好。

最佳回答

I have found the way of what I wanted.

这里的解决办法(也许不是最佳办法,而是做得当)

$file = $_POST[ file ];
$filename = pathinfo($file, PATHINFO_FILENAME);

require_once  phpexcel/Classes/PHPExcel.php ;

$xls = new PHPExcel();
$xlsReader= new PHPExcel_Reader_Excel5();
$xlsTemplate = $xlsReader->load($file);

$sheet1 = $xlsTemplate->getSheetByName( Sheet1 );
$xls->addExternalSheet($sheet1,0);
$xls->removeSheetByIndex(1);
$xlsWriter = new PHPExcel_Writer_Excel5($xls);
$xlsWriter->save($filename."_Sheet1.xls");

$sheet2 = $xlsTemplate->getSheetByName( Sheet2 );
$xls->addExternalSheet($sheet2,0);
$xls->removeSheetByIndex(1);
$xlsWriter = new PHPExcel_Writer_Excel5($xls);
$xlsWriter->save($filename."_Sheet2.xls");

$sheet3 = $xlsTemplate->getSheetByName( Sheet3 );
$xls->addExternalSheet($sheet3,0);
$xls->removeSheetByIndex(1);
$xlsWriter = new PHPExcel_Writer_Excel5($xls);
$xlsWriter->save($filename."_Sheet3.xls");

$sheet4 = $xlsTemplate->getSheetByName( Sheet4 );
$xls->addExternalSheet($sheet4,0);
$xls->removeSheetByIndex(1);
$xlsWriter = new PHPExcel_Writer_Excel5($xls);
$xlsWriter->save($filename."_Sheet4.xls");

$sheet5 = $xlsTemplate->getSheetByName( Sheet5 );
$xls->addExternalSheet($sheet5,0);
$xls->removeSheetByIndex(1);
$xlsWriter = new PHPExcel_Writer_Excel5($xls);
$xlsWriter->save($filename."_Sheet5.xls");

$sheet6 = $xlsTemplate->getSheetByName( Sheet6 );
$xls->addExternalSheet($sheet6,0);
$xls->removeSheetByIndex(1);
$xlsWriter = new PHPExcel_Writer_Excel5($xls);
$xlsWriter->save($filename."_Sheet6.xls");

然后,我原来的Excel案卷,载有6张表格,现在按我的愿望分为6份Excel案。

As you can see, it was not so hard to release, but the documentation is so confusing...

Hope this can help.

问题回答

暂无回答




相关问题
return var doesn t work when var is huge?

So I am using PHPExcel (http://phpexcel.codeplex.com/) to import a excel sheet. everything works fine on my development system, BUT it doesn t quite work on the live system. Hence I debugged and ...

Import excel files with image in php/mysql

I want to make an import script which allows users to upload their excel file (extension not important) to my php application. The application should reconize a list of items (so far so good). The ...

PHP programming logic inquiry

With the help of this community, I just recently solved some issues with PHPExcel reading multiple files through a foreach(). Now it seems I ve got logic issues. I m reading some excel files and ...

Reading multiple files with PHPExcel

I just recently started using this library (the one from CodePlex), but I ran into some issues. My goal is to use it so I can process some data from multiple Excel files, and send such data to a ...

PHPExcel set specific headers for file format

While googling I found two different sets of headers that need to be set when outputting excel generated in different file format. for e.g. For Type "Excel5" headers are: header("Pragma: public"); ...

PHPExcel how to set cell value dynamically

How to set cell/column value dynamically using PHPExcel library? I am fetching result set from MySQL database and I want to write data in excel format using PHPExcel library. Looking at example $...

php PHPExcel split Excel cell coordinate

currently, I used PHPExcel to import excel file, there is a function $cell->getCoordinate(); I would like to ask any solution for split the cell coordinate alphabet and integer? e.g A1, A2, I ...

热门标签