| @@ -7,8 +7,10 @@ | ||
| 7 | 7 | * @author Tobias Bäthge |
| 8 | 8 | * @since 2.0.0 |
| 9 | 9 | */ |
| 10 | 10 | |
| 11 | +declare(strict_types=1); | |
| 12 | + | |
| 11 | 13 | use TablePress\Import\File; |
| 12 | 14 | |
| 13 | 15 | // Prohibit direct script loading. |
| 14 | 16 | defined( 'ABSPATH' ) || die( 'No direct script access allowed!' ); |
| @@ -29,9 +31,9 @@ | ||
| 29 | 31 | * @since 2.0.0 |
| 30 | 32 | */ |
| 31 | 33 | public function __construct() { |
| 32 | 34 | // Load PHPSpreadsheet via its autoloading mechanism. |
| 33 | - TablePress::load_file( 'autoload.php', 'libraries' ); | |
| 35 | + TablePress::load_file( 'autoload.php', 'libraries/vendor' ); | |
| 34 | 36 | } |
| 35 | 37 | |
| 36 | 38 | /** |
| 37 | 39 | * Imports a table from a file. |
| @@ -176,9 +178,9 @@ | ||
| 176 | 178 | |
| 177 | 179 | try { |
| 178 | 180 | // Treat all cell values as strings, except for formulas (due to recognition of quoted/escaped formulas like `'=A2`). |
| 179 | 181 | \TablePress\PhpOffice\PhpSpreadsheet\Cell\Cell::setValueBinder( new \TablePress\PhpOffice\PhpSpreadsheet\Cell\StringValueBinder() ); |
| 180 | - \TablePress\PhpOffice\PhpSpreadsheet\Cell\Cell::getValueBinder()->setFormulaConversion( false ); // @phpstan-ignore-line | |
| 182 | + \TablePress\PhpOffice\PhpSpreadsheet\Cell\Cell::getValueBinder()->setFormulaConversion( false ); // @phpstan-ignore method.notFound | |
| 181 | 183 | |
| 182 | 184 | /* |
| 183 | 185 | * Try to detect a reader from the file extension and MIME type. |
| 184 | 186 | * Fall back to CSV if no reader could be determined. |
| @@ -207,10 +209,10 @@ | ||
| 207 | 209 | $class_type = explode( '\\', $class_name ); |
| 208 | 210 | $detected_format = strtolower( array_pop( $class_type ) ); |
| 209 | 211 | |
| 210 | 212 | if ( 'csv' === $detected_format ) { |
| 211 | - $reader->setInputEncoding( \TablePress\PhpOffice\PhpSpreadsheet\Reader\Csv::GUESS_ENCODING ); // @phpstan-ignore-line | |
| 212 | - // @phpstan-ignore-next-line | |
| 213 | + $reader->setInputEncoding( \TablePress\PhpOffice\PhpSpreadsheet\Reader\Csv::GUESS_ENCODING ); // @phpstan-ignore method.notFound | |
| 214 | + // @phpstan-ignore method.notFound, smaller.alwaysFalse (PHPStan thinks that the Composer minimum version will always be fulfilled.) | |
| 213 | 215 | $reader->setEscapeCharacter( ( PHP_VERSION_ID < 70400 ) ? "\x0" : '' ); // Disable the proprietary escape mechanism of PHP's fgetcsv() in PHP >= 7.4. |
| 214 | 216 | } |
| 215 | 217 | |
| 216 | 218 | $reader->setIncludeCharts( false ); |
| @@ -222,9 +224,9 @@ | ||
| 222 | 224 | } |
| 223 | 225 | |
| 224 | 226 | // For formats where it's supported, import only the first sheet. |
| 225 | 227 | if ( in_array( $detected_format, array( 'csv', 'html', 'slk' ), true ) ) { |
| 226 | - $reader->setSheetIndex( 0 ); // @phpstan-ignore-line | |
| 228 | + $reader->setSheetIndex( 0 ); // @phpstan-ignore method.notFound | |
| 227 | 229 | } |
| 228 | 230 | |
| 229 | 231 | $spreadsheet = $reader->load( $file->location ); |
| 230 | 232 | $worksheet = $spreadsheet->getActiveSheet(); |
| @@ -240,12 +242,12 @@ | ||
| 240 | 242 | $max_col = $worksheet->getHighestColumn(); |
| 241 | 243 | $max_row = $worksheet->getHighestRow(); |
| 242 | 244 | |
| 243 | 245 | // Adapted from \TablePress\PhpOffice\PhpSpreadsheet\Worksheet\Worksheet::rangeToArray(). |
| 244 | - ++$max_col; // Due to for-loop with characters for columns. | |
| 246 | + \TablePress\PhpOffice\PhpSpreadsheet\Shared\StringHelper::stringIncrement( $max_col ); // Due to for-loop with characters for columns. | |
| 245 | 247 | for ( $row = $min_row; $row <= $max_row; $row++ ) { |
| 246 | 248 | $row_data = array(); |
| 247 | - for ( $col = $min_col; $col !== $max_col; $col++ ) { | |
| 249 | + for ( $col = $min_col; $col !== $max_col; \TablePress\PhpOffice\PhpSpreadsheet\Shared\StringHelper::stringIncrement( $col ) ) { | |
| 248 | 250 | $cell_reference = $col . $row; |
| 249 | 251 | if ( ! $cell_collection->has( $cell_reference ) ) { |
| 250 | 252 | $row_data[] = ''; |
| 251 | 253 | continue; |
| @@ -285,13 +287,13 @@ | ||
| 285 | 287 | } |
| 286 | 288 | $cell_data = \TablePress\PhpOffice\PhpSpreadsheet\Style\NumberFormat::toFormattedString( |
| 287 | 289 | $cell_data, |
| 288 | 290 | $format, |
| 289 | - array( $this, 'format_color' ) | |
| 291 | + array( $this, 'format_color' ), | |
| 290 | 292 | ); |
| 291 | 293 | |
| 292 | 294 | if ( strlen( $cell_data ) > 1 && '=' === $cell_data[0] ) { |
| 293 | - if ( $style->getQuotePrefix() ) { | |
| 295 | + if ( 'xlsx' === $detected_format && $style->getQuotePrefix() ) { | |
| 294 | 296 | // Prepend a ' to quoted/escaped formulas (so that they are shown as text). This is currently not supported (at least) for the XLS format. |
| 295 | 297 | $cell_data = "'{$cell_data}"; |
| 296 | 298 | } else { |
| 297 | 299 | // Bail early, to not add inline HTML styling around formulas, as they won't work anymore then. |