您可以使用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 Question,PHPExcel Example
讀取Excel內容到PHP,操作字符串的內容(正則表達式可能是必要的),然後重新創建excel文件。 – ihsan
查看[PHP-ExcelReader](http://sourceforge.net/projects/phpexcelreader/) – gwillie
@mazraara你需要VBA而不是php。 – ihsan