excel.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380
  1. <?php
  2. use Maatwebsite\Excel\Excel;
  3. use PhpOffice\PhpSpreadsheet\Reader\Csv;
  4. return [
  5. 'exports' => [
  6. /*
  7. |--------------------------------------------------------------------------
  8. | Chunk size
  9. |--------------------------------------------------------------------------
  10. |
  11. | When using FromQuery, the query is automatically chunked.
  12. | Here you can specify how big the chunk should be.
  13. |
  14. */
  15. 'chunk_size' => 1000,
  16. /*
  17. |--------------------------------------------------------------------------
  18. | Pre-calculate formulas during export
  19. |--------------------------------------------------------------------------
  20. */
  21. 'pre_calculate_formulas' => false,
  22. /*
  23. |--------------------------------------------------------------------------
  24. | Enable strict null comparison
  25. |--------------------------------------------------------------------------
  26. |
  27. | When enabling strict null comparison empty cells ('') will
  28. | be added to the sheet.
  29. */
  30. 'strict_null_comparison' => false,
  31. /*
  32. |--------------------------------------------------------------------------
  33. | CSV Settings
  34. |--------------------------------------------------------------------------
  35. |
  36. | Configure e.g. delimiter, enclosure and line ending for CSV exports.
  37. |
  38. */
  39. 'csv' => [
  40. 'delimiter' => ',',
  41. 'enclosure' => '"',
  42. 'line_ending' => PHP_EOL,
  43. 'use_bom' => false,
  44. 'include_separator_line' => false,
  45. 'excel_compatibility' => false,
  46. 'output_encoding' => '',
  47. 'test_auto_detect' => true,
  48. ],
  49. /*
  50. |--------------------------------------------------------------------------
  51. | Worksheet properties
  52. |--------------------------------------------------------------------------
  53. |
  54. | Configure e.g. default title, creator, subject,...
  55. |
  56. */
  57. 'properties' => [
  58. 'creator' => '',
  59. 'lastModifiedBy' => '',
  60. 'title' => '',
  61. 'description' => '',
  62. 'subject' => '',
  63. 'keywords' => '',
  64. 'category' => '',
  65. 'manager' => '',
  66. 'company' => '',
  67. ],
  68. ],
  69. 'imports' => [
  70. /*
  71. |--------------------------------------------------------------------------
  72. | Read Only
  73. |--------------------------------------------------------------------------
  74. |
  75. | When dealing with imports, you might only be interested in the
  76. | data that the sheet exists. By default we ignore all styles,
  77. | however if you want to do some logic based on style data
  78. | you can enable it by setting read_only to false.
  79. |
  80. */
  81. 'read_only' => true,
  82. /*
  83. |--------------------------------------------------------------------------
  84. | Ignore Empty
  85. |--------------------------------------------------------------------------
  86. |
  87. | When dealing with imports, you might be interested in ignoring
  88. | rows that have null values or empty strings. By default rows
  89. | containing empty strings or empty values are not ignored but can be
  90. | ignored by enabling the setting ignore_empty to true.
  91. |
  92. */
  93. 'ignore_empty' => false,
  94. /*
  95. |--------------------------------------------------------------------------
  96. | Heading Row Formatter
  97. |--------------------------------------------------------------------------
  98. |
  99. | Configure the heading row formatter.
  100. | Available options: none|slug|custom
  101. |
  102. */
  103. 'heading_row' => [
  104. 'formatter' => 'slug',
  105. ],
  106. /*
  107. |--------------------------------------------------------------------------
  108. | CSV Settings
  109. |--------------------------------------------------------------------------
  110. |
  111. | Configure e.g. delimiter, enclosure and line ending for CSV imports.
  112. |
  113. */
  114. 'csv' => [
  115. 'delimiter' => null,
  116. 'enclosure' => '"',
  117. 'escape_character' => '\\',
  118. 'contiguous' => false,
  119. 'input_encoding' => Csv::GUESS_ENCODING,
  120. ],
  121. /*
  122. |--------------------------------------------------------------------------
  123. | Worksheet properties
  124. |--------------------------------------------------------------------------
  125. |
  126. | Configure e.g. default title, creator, subject,...
  127. |
  128. */
  129. 'properties' => [
  130. 'creator' => '',
  131. 'lastModifiedBy' => '',
  132. 'title' => '',
  133. 'description' => '',
  134. 'subject' => '',
  135. 'keywords' => '',
  136. 'category' => '',
  137. 'manager' => '',
  138. 'company' => '',
  139. ],
  140. /*
  141. |--------------------------------------------------------------------------
  142. | Cell Middleware
  143. |--------------------------------------------------------------------------
  144. |
  145. | Configure middleware that is executed on getting a cell value
  146. |
  147. */
  148. 'cells' => [
  149. 'middleware' => [
  150. //\Maatwebsite\Excel\Middleware\TrimCellValue::class,
  151. //\Maatwebsite\Excel\Middleware\ConvertEmptyCellValuesToNull::class,
  152. ],
  153. ],
  154. ],
  155. /*
  156. |--------------------------------------------------------------------------
  157. | Extension detector
  158. |--------------------------------------------------------------------------
  159. |
  160. | Configure here which writer/reader type should be used when the package
  161. | needs to guess the correct type based on the extension alone.
  162. |
  163. */
  164. 'extension_detector' => [
  165. 'xlsx' => Excel::XLSX,
  166. 'xlsm' => Excel::XLSX,
  167. 'xltx' => Excel::XLSX,
  168. 'xltm' => Excel::XLSX,
  169. 'xls' => Excel::XLS,
  170. 'xlt' => Excel::XLS,
  171. 'ods' => Excel::ODS,
  172. 'ots' => Excel::ODS,
  173. 'slk' => Excel::SLK,
  174. 'xml' => Excel::XML,
  175. 'gnumeric' => Excel::GNUMERIC,
  176. 'htm' => Excel::HTML,
  177. 'html' => Excel::HTML,
  178. 'csv' => Excel::CSV,
  179. 'tsv' => Excel::TSV,
  180. /*
  181. |--------------------------------------------------------------------------
  182. | PDF Extension
  183. |--------------------------------------------------------------------------
  184. |
  185. | Configure here which Pdf driver should be used by default.
  186. | Available options: Excel::MPDF | Excel::TCPDF | Excel::DOMPDF
  187. |
  188. */
  189. 'pdf' => Excel::DOMPDF,
  190. ],
  191. /*
  192. |--------------------------------------------------------------------------
  193. | Value Binder
  194. |--------------------------------------------------------------------------
  195. |
  196. | PhpSpreadsheet offers a way to hook into the process of a value being
  197. | written to a cell. In there some assumptions are made on how the
  198. | value should be formatted. If you want to change those defaults,
  199. | you can implement your own default value binder.
  200. |
  201. | Possible value binders:
  202. |
  203. | [x] Maatwebsite\Excel\DefaultValueBinder::class
  204. | [x] PhpOffice\PhpSpreadsheet\Cell\StringValueBinder::class
  205. | [x] PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder::class
  206. |
  207. */
  208. 'value_binder' => [
  209. 'default' => Maatwebsite\Excel\DefaultValueBinder::class,
  210. ],
  211. 'cache' => [
  212. /*
  213. |--------------------------------------------------------------------------
  214. | Default cell caching driver
  215. |--------------------------------------------------------------------------
  216. |
  217. | By default PhpSpreadsheet keeps all cell values in memory, however when
  218. | dealing with large files, this might result into memory issues. If you
  219. | want to mitigate that, you can configure a cell caching driver here.
  220. | When using the illuminate driver, it will store each value in the
  221. | cache store. This can slow down the process, because it needs to
  222. | store each value. You can use the "batch" store if you want to
  223. | only persist to the store when the memory limit is reached.
  224. |
  225. | Drivers: memory|illuminate|batch
  226. |
  227. */
  228. 'driver' => 'memory',
  229. /*
  230. |--------------------------------------------------------------------------
  231. | Batch memory caching
  232. |--------------------------------------------------------------------------
  233. |
  234. | When dealing with the "batch" caching driver, it will only
  235. | persist to the store when the memory limit is reached.
  236. | Here you can tweak the memory limit to your liking.
  237. |
  238. */
  239. 'batch' => [
  240. 'memory_limit' => 60000,
  241. ],
  242. /*
  243. |--------------------------------------------------------------------------
  244. | Illuminate cache
  245. |--------------------------------------------------------------------------
  246. |
  247. | When using the "illuminate" caching driver, it will automatically use
  248. | your default cache store. However if you prefer to have the cell
  249. | cache on a separate store, you can configure the store name here.
  250. | You can use any store defined in your cache config. When leaving
  251. | at "null" it will use the default store.
  252. |
  253. */
  254. 'illuminate' => [
  255. 'store' => null,
  256. ],
  257. /*
  258. |--------------------------------------------------------------------------
  259. | Cache Time-to-live (TTL)
  260. |--------------------------------------------------------------------------
  261. |
  262. | The TTL of items written to cache. If you want to keep the items cached
  263. | indefinitely, set this to null. Otherwise, set a number of seconds,
  264. | a \DateInterval, or a callable.
  265. |
  266. | Allowable types: callable|\DateInterval|int|null
  267. |
  268. */
  269. 'default_ttl' => 10800,
  270. ],
  271. /*
  272. |--------------------------------------------------------------------------
  273. | Transaction Handler
  274. |--------------------------------------------------------------------------
  275. |
  276. | By default the import is wrapped in a transaction. This is useful
  277. | for when an import may fail and you want to retry it. With the
  278. | transactions, the previous import gets rolled-back.
  279. |
  280. | You can disable the transaction handler by setting this to null.
  281. | Or you can choose a custom made transaction handler here.
  282. |
  283. | Supported handlers: null|db
  284. |
  285. */
  286. 'transactions' => [
  287. 'handler' => 'db',
  288. 'db' => [
  289. 'connection' => null,
  290. ],
  291. ],
  292. 'temporary_files' => [
  293. /*
  294. |--------------------------------------------------------------------------
  295. | Local Temporary Path
  296. |--------------------------------------------------------------------------
  297. |
  298. | When exporting and importing files, we use a temporary file, before
  299. | storing reading or downloading. Here you can customize that path.
  300. | permissions is an array with the permission flags for the directory (dir)
  301. | and the create file (file).
  302. |
  303. */
  304. 'local_path' => storage_path('framework/cache/laravel-excel'),
  305. /*
  306. |--------------------------------------------------------------------------
  307. | Local Temporary Path Permissions
  308. |--------------------------------------------------------------------------
  309. |
  310. | Permissions is an array with the permission flags for the directory (dir)
  311. | and the create file (file).
  312. | If omitted the default permissions of the filesystem will be used.
  313. |
  314. */
  315. 'local_permissions' => [
  316. // 'dir' => 0755,
  317. // 'file' => 0644,
  318. ],
  319. /*
  320. |--------------------------------------------------------------------------
  321. | Remote Temporary Disk
  322. |--------------------------------------------------------------------------
  323. |
  324. | When dealing with a multi server setup with queues in which you
  325. | cannot rely on having a shared local temporary path, you might
  326. | want to store the temporary file on a shared disk. During the
  327. | queue executing, we'll retrieve the temporary file from that
  328. | location instead. When left to null, it will always use
  329. | the local path. This setting only has effect when using
  330. | in conjunction with queued imports and exports.
  331. |
  332. */
  333. 'remote_disk' => null,
  334. 'remote_prefix' => null,
  335. /*
  336. |--------------------------------------------------------------------------
  337. | Force Resync
  338. |--------------------------------------------------------------------------
  339. |
  340. | When dealing with a multi server setup as above, it's possible
  341. | for the clean up that occurs after entire queue has been run to only
  342. | cleanup the server that the last AfterImportJob runs on. The rest of the server
  343. | would still have the local temporary file stored on it. In this case your
  344. | local storage limits can be exceeded and future imports won't be processed.
  345. | To mitigate this you can set this config value to be true, so that after every
  346. | queued chunk is processed the local temporary file is deleted on the server that
  347. | processed it.
  348. |
  349. */
  350. 'force_resync_remote' => null,
  351. ],
  352. ];