您可以使用 PHPExcel 库来读取/写入 Excel 文件。(下载和文档可在http://phpexcel.codeplex.com/获得)。然后使用 RegEx 分隔字符串。
编辑 1
代码将是这样的:
// Include PHPExcel_IOFactory
include 'PHPExcel/IOFactory.php';
$inputFileName = './example1.xlsx';
$outputFileName = './output.xlsx';
// Read your Excel workbook
try {
$inputFileType = PHPExcel_IOFactory::identify($inputFileName);
$objReader = PHPExcel_IOFactory::createReader($inputFileType);
$objPHPExcel = $objReader->load($inputFileName);
$outputObj = new PHPExcel();
} catch(Exception $e) {
die('Error loading file: '. $e->getMessage());
}
// Get worksheet dimensions
$sheet = $objPHPExcel->getSheet(0);
$highestRow = $sheet->getHighestRow();
$outputObj->setActiveSheetIndex(0);
$outSheet = $outputObj->getActiveSheet();
// Loop through each row of the worksheet in turn
for ($row = 2; $row <= $highestRow; $row++){ // As row 1 seems to be header
// Read cell A2, A3, etc.
$line = $sheet->getCell('A' . $row)->getValue();
preg_match("|([^\.]+)\. <([^>]+)>|", $line, $data);
// $data[1] will be name & $data[2] will be email
$outSheet->setCellValue('A' . $row, $data[1]);
$outSheet->setCellValue('B' . $row, $data[2]);
}
// write new data into a .xlsx file
$objWriter = new PHPExcel_Writer_Excel2007($outputObj);
$objWriter->save($outputFileName);
资料来源:Stackoverflow 问题,PHPExcel 示例