Skip to content

Instantly share code, notes, and snippets.

@ionstudio
Created December 12, 2019 08:20
Show Gist options
  • Save ionstudio/6b555f8c3d4644b5a2a79ce4435f967d to your computer and use it in GitHub Desktop.
Save ionstudio/6b555f8c3d4644b5a2a79ce4435f967d to your computer and use it in GitHub Desktop.
xlsx2csv
//Функция конвертирования Excel (xlsx) в CSV
function xlsx2csv($file) {
//Подключим библиотеку
include "../libs/xlsx/PHPExcel.php";
//Откроем файл
$reader = PHPExcel_IOFactory::createReaderForFile($file);
//Читать только данные, без стилей
$reader->setReadDataOnly(true);
//Прочитаем файл
$xlsx = $reader->load($file);;
//Создадим CSV
$writer = new PHPExcel_Writer_CSV($xlsx);
//Установим лист 1
$writer->setSheetIndex(0);
//Запишем CSV
$writer->save("$file.csv");
//Вернем результат
return true;
}
xlsx2csv("data.xlsx");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment