2012-05-14 54 views

回答

1

從PHP,你需要有類似phpExcel打開電子表格,並將每個選項卡重寫爲新文件。

1

使用PHPExcel庫:

include 'PHPExcel.php'; 

$fileType = 'Excel2007'; 
$inputFileName = 'testExcel.xlsx'; 

$objPHPExcelReader = PHPExcel_IOFactory::createReader($fileType); 
$objPHPExcel = $objPHPExcelReader->load($inputFileName); 

$sheetIndex = 0; 
$sheetCount = $objPHPExcel->getSheetCount(); 
while ($sheetIndex < $sheetCount) { 
    ++$sheetIndex; 
    $workSheet = $objPHPExcel->getSheet(0); 

    $newObjPHPExcel = new PHPExcel(); 
    $newObjPHPExcel->removeSheetByIndex(0); 
    $newObjPHPExcel->addExternalSheet($workSheet); 

    $objPHPExcelWriter = PHPExcel_IOFactory::createWriter($newObjPHPExcel,$fileType); 
    $outputFileTemp = explode('.',$inputFileName); 
    $outputFileName = $outputFileTemp[0].$sheetIndex.'.'.$outputFileTemp[1]; 
    $objPHPExcelWriter->save($outputFileName); 
} 
相關問題