1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-15 07:33:04 +01:00
invoiceninja/tests/Feature/PhpOffice/CsvConversionTest.php
2024-08-22 16:57:52 +10:00

52 lines
1.2 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace Tests\Feature\PhpOffice;
use Tests\TestCase;
use PhpOffice\PhpSpreadsheet\Spreadsheet;
use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
class CsvConversionTest extends TestCase
{
protected function setUp(): void
{
parent::setUp();
}
public function testExample()
{
$spreadsheet = new Spreadsheet();
$reader = new \PhpOffice\PhpSpreadsheet\Reader\Csv();
/* Set CSV parsing options */
$reader->setDelimiter(',');
// $reader->setEnclosure('"');
$reader->setSheetIndex(0);
/* Load a CSV file and save as a XLS */
$spreadsheet = $reader->load(base_path().'/tests/Feature/Import/expenses.csv');
$writer = new Xlsx($spreadsheet);
$writer->save(storage_path('/test.xlsx'));
$spreadsheet->disconnectWorksheets();
$this->assertTrue(file_exists(storage_path('/test.xlsx')));
unlink(storage_path('/test.xlsx'));
}
}