Created
December 12, 2019 08:20
-
-
Save ionstudio/6b555f8c3d4644b5a2a79ce4435f967d to your computer and use it in GitHub Desktop.
xlsx2csv
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Функция конвертирования 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