helper.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. <?php
  2. namespace Vtiful\Kernel;
  3. /**
  4. * Class Excel
  5. *
  6. * @author viest
  7. *
  8. * @package Vtiful\Kernel
  9. */
  10. class Excel
  11. {
  12. const TYPE_STRING = 0x01;
  13. const TYPE_INT = 0x02;
  14. const TYPE_DOUBLE = 0x04;
  15. const TYPE_TIMESTAMP = 0x08;
  16. const SKIP_NONE = 0x00;
  17. const SKIP_EMPTY_ROW = 0x01;
  18. const SKIP_EMPTY_CELLS = 0x02;
  19. const GRIDLINES_HIDE_ALL = 0;
  20. const GRIDLINES_SHOW_SCREEN = 1;
  21. const GRIDLINES_SHOW_PRINT = 2;
  22. const GRIDLINES_SHOW_ALL = 3;
  23. /**
  24. * Excel constructor.
  25. *
  26. * @param array $config
  27. */
  28. public function __construct(array $config)
  29. {
  30. //
  31. }
  32. /**
  33. * File Name
  34. *
  35. * @param string $fileName
  36. * @param string $sheetName
  37. *
  38. * @return Excel
  39. *
  40. * @author viest
  41. */
  42. public function fileName(string $fileName, string $sheetName = 'Sheet1'): self
  43. {
  44. return $this;
  45. }
  46. /**
  47. * Const memory model
  48. *
  49. * @param string $fileName
  50. * @param string $sheetName
  51. *
  52. * @return Excel
  53. *
  54. * @author viest
  55. */
  56. public function constMemory(string $fileName, string $sheetName = 'Sheet1'): self
  57. {
  58. return $this;
  59. }
  60. /**
  61. * Add a new worksheet to a workbook.
  62. *
  63. * The worksheet name must be a valid Excel worksheet name, i.e. it must be
  64. * less than 32 character and it cannot contain any of the characters:
  65. *
  66. * / \ [ ] : * ?
  67. *
  68. * In addition, you cannot use the same, case insensitive, `$sheetName` for more
  69. * than one worksheet.
  70. *
  71. * @param string|NULL $sheetName
  72. *
  73. * @return Excel
  74. *
  75. * @author viest
  76. */
  77. public function addSheet(?string $sheetName): self
  78. {
  79. return $this;
  80. }
  81. /**
  82. * Checkout worksheet
  83. *
  84. * @param string $sheetName
  85. *
  86. * @return Excel
  87. *
  88. * @author viest
  89. */
  90. public function checkoutSheet(string $sheetName): self
  91. {
  92. return $this;
  93. }
  94. /**
  95. * Insert data on the first line of the worksheet
  96. *
  97. * @param array $header
  98. *
  99. * @return Excel
  100. *
  101. * @author viest
  102. */
  103. public function header(array $header): self
  104. {
  105. return $this;
  106. }
  107. /**
  108. * Insert data on the worksheet
  109. *
  110. * @param array $data
  111. *
  112. * @return Excel
  113. *
  114. * @author viest
  115. */
  116. public function data(array $data): self
  117. {
  118. return $this;
  119. }
  120. /**
  121. * Generate file
  122. *
  123. * @return string
  124. *
  125. * @author viest
  126. */
  127. public function output(): string
  128. {
  129. return 'FilePath';
  130. }
  131. /**
  132. * Get file resource
  133. *
  134. * @return resource
  135. *
  136. * @author viest
  137. */
  138. public function getHandle()
  139. {
  140. //
  141. }
  142. /**
  143. * Auto filter on the worksheet
  144. *
  145. * @param string $range
  146. *
  147. * @return Excel
  148. *
  149. * @author viest
  150. */
  151. public function autoFilter(string $range): self
  152. {
  153. return $this;
  154. }
  155. /**
  156. * Insert data on the cell
  157. *
  158. * @param int $row
  159. * @param int $column
  160. * @param int|string|double $data
  161. * @param string|null $format
  162. * @param resource|null $formatHandle
  163. *
  164. * @return Excel
  165. *
  166. * @author viest
  167. */
  168. public function insertText(int $row, int $column, $data, string $format = NULL, $formatHandle = NULL): self
  169. {
  170. return $this;
  171. }
  172. /**
  173. * Insert date on the cell
  174. *
  175. * @param int $row
  176. * @param int $column
  177. * @param int $timestamp
  178. * @param string|NULL $format
  179. * @param resource|null $formatHandle
  180. *
  181. * @return Excel
  182. *
  183. * @author viest
  184. */
  185. public function insertDate(int $row, int $column, int $timestamp, string $format = NULL, $formatHandle = NULL): self
  186. {
  187. return $this;
  188. }
  189. /**
  190. * Insert chart on the cell
  191. *
  192. * @param int $row
  193. * @param int $column
  194. * @param resource $chartResource
  195. *
  196. * @return Excel
  197. *
  198. * @author viest
  199. */
  200. public function insertChart(int $row, int $column, $chartResource): self
  201. {
  202. return $this;
  203. }
  204. /**
  205. * Insert url on the cell
  206. *
  207. * @param int $row
  208. * @param int $column
  209. * @param string $url
  210. * @param resource|null $formatHandle
  211. *
  212. * @return Excel
  213. *
  214. * @author viest
  215. */
  216. public function insertUrl(int $row, int $column, string $url, $formatHandle = NULL): self
  217. {
  218. return $this;
  219. }
  220. /**
  221. * Insert image on the cell
  222. *
  223. * @param int $row
  224. * @param int $column
  225. * @param string $imagePath
  226. * @param float $width
  227. * @param float $height
  228. *
  229. * @return Excel
  230. *
  231. * @author viest
  232. */
  233. public function insertImage(int $row, int $column, string $imagePath, float $width = 1, float $height = 1): self
  234. {
  235. return $this;
  236. }
  237. /**
  238. * Insert Formula on the cell
  239. *
  240. * @param int $row
  241. * @param int $column
  242. * @param string $formula
  243. *
  244. * @return Excel
  245. *
  246. * @author viest
  247. */
  248. public function insertFormula(int $row, int $column, string $formula): self
  249. {
  250. return $this;
  251. }
  252. /**
  253. * Merge cells
  254. *
  255. * @param string $range
  256. * @param string $data
  257. *
  258. * @return Excel
  259. *
  260. * @author viest
  261. */
  262. public function MergeCells(string $range, string $data): self
  263. {
  264. return $this;
  265. }
  266. /**
  267. * Set column cells width or format
  268. *
  269. * @param string $range
  270. * @param float $cellWidth
  271. * @param resource|null $formatHandle
  272. *
  273. * @return Excel
  274. *
  275. * @author viest
  276. */
  277. public function setColumn(string $range, float $cellWidth, $formatHandle = NULL): self
  278. {
  279. return $this;
  280. }
  281. /**
  282. * Set row cells height or format
  283. *
  284. * @param string $range
  285. * @param float $cellHeight
  286. * @param resource|null $formatHandle
  287. *
  288. * @return Excel
  289. *
  290. * @author viest
  291. */
  292. public function setRow(string $range, float $cellHeight, $formatHandle = NULL): self
  293. {
  294. return $this;
  295. }
  296. /**
  297. * Open xlsx file
  298. *
  299. * @param string $fileName
  300. *
  301. * @return Excel
  302. *
  303. * @author viest
  304. */
  305. public function openFile(string $fileName): self
  306. {
  307. return $this;
  308. }
  309. /**
  310. * Open sheet
  311. *
  312. * default open first sheet
  313. *
  314. * @param string|NULL $sheetName
  315. * @param int skipFlag
  316. *
  317. * @return Excel
  318. *
  319. * @author viest
  320. */
  321. public function openSheet(string $sheetName = NULL, int $skipFlag = 0x00): self
  322. {
  323. return $this;
  324. }
  325. /**
  326. * Set row cell data type
  327. *
  328. * @param array $types
  329. *
  330. * @return Excel
  331. *
  332. * @author viest
  333. */
  334. public function setType(array $types): self
  335. {
  336. return $this;
  337. }
  338. /**
  339. * Read values from the sheet
  340. *
  341. * @return array
  342. *
  343. * @author viest
  344. */
  345. public function getSheetData(): array
  346. {
  347. return [];
  348. }
  349. /**
  350. * Read values from the sheet
  351. *
  352. * @return array
  353. *
  354. * @author viest
  355. */
  356. public function nextRow(): array
  357. {
  358. return [];
  359. }
  360. /**
  361. * Next Cell In Callback
  362. *
  363. * @param callable $callback function(int $row, int $cell, string $data)
  364. * @param string|NULL $sheetName sheet name
  365. *
  366. * @author viest
  367. */
  368. public function nextCellCallback(callable $callback, string $sheetName = NULL): void
  369. {
  370. //
  371. }
  372. /**
  373. * Freeze panes
  374. *
  375. * freezePanes(1, 0); // Freeze the first row.
  376. * freezePanes(0, 1); // Freeze the first column.
  377. * freezePanes(1, 1); // Freeze first row/column.
  378. *
  379. * @param int $row
  380. * @param int $column
  381. *
  382. * @return $this
  383. *
  384. * @author viest
  385. */
  386. public function freezePanes(int $row, int $column): self
  387. {
  388. return $this;
  389. }
  390. /**
  391. * Gridline
  392. *
  393. * Display or hide screen and print gridlines using one of the values of
  394. *
  395. * \Vtiful\Kernel\Excel::GRIDLINES_HIDE_ALL
  396. * \Vtiful\Kernel\Excel::GRIDLINES_SHOW_ALL
  397. * \Vtiful\Kernel\Excel::GRIDLINES_SHOW_PRINT
  398. * \Vtiful\Kernel\Excel::GRIDLINES_SHOW_SCREEN
  399. *
  400. * Excel default is that the screen gridlines are on and the printed worksheet is off.
  401. *
  402. * @param int $option
  403. *
  404. * @return $this
  405. *
  406. * @author viest
  407. */
  408. public function gridline(int $option): self
  409. {
  410. return $this;
  411. }
  412. /**
  413. * Worksheet zoom
  414. *
  415. * Set the worksheet zoom factor in the range 10 <= zoom <= 400:
  416. *
  417. * @param int $scale
  418. *
  419. * @return $this
  420. *
  421. * @author viest
  422. */
  423. public function zoom(int $scale): self
  424. {
  425. return $this;
  426. }
  427. }
  428. /**
  429. * Class Format
  430. *
  431. * @author viest
  432. *
  433. * @package Vtiful\Kernel
  434. */
  435. class Format
  436. {
  437. const UNDERLINE_SINGLE = 0x00;
  438. const UNDERLINE_DOUBLE = 0x00;
  439. const UNDERLINE_SINGLE_ACCOUNTING = 0x00;
  440. const UNDERLINE_DOUBLE_ACCOUNTING = 0x00;
  441. const FORMAT_ALIGN_LEFT = 0x00;
  442. const FORMAT_ALIGN_CENTER = 0x00;
  443. const FORMAT_ALIGN_RIGHT = 0x00;
  444. const FORMAT_ALIGN_FILL = 0x00;
  445. const FORMAT_ALIGN_JUSTIFY = 0x00;
  446. const FORMAT_ALIGN_CENTER_ACROSS = 0x00;
  447. const FORMAT_ALIGN_DISTRIBUTED = 0x00;
  448. const FORMAT_ALIGN_VERTICAL_TOP = 0x00;
  449. const FORMAT_ALIGN_VERTICAL_BOTTOM = 0x00;
  450. const FORMAT_ALIGN_VERTICAL_CENTER = 0x00;
  451. const FORMAT_ALIGN_VERTICAL_JUSTIFY = 0x00;
  452. const FORMAT_ALIGN_VERTICAL_DISTRIBUTED = 0x00;
  453. const COLOR_BLACK = 0x00;
  454. const COLOR_BLUE = 0x00;
  455. const COLOR_BROWN = 0x00;
  456. const COLOR_CYAN = 0x00;
  457. const COLOR_GRAY = 0x00;
  458. const COLOR_GREEN = 0x00;
  459. const COLOR_LIME = 0x00;
  460. const COLOR_MAGENTA = 0x00;
  461. const COLOR_NAVY = 0x00;
  462. const COLOR_ORANGE = 0x00;
  463. const COLOR_PINK = 0x00;
  464. const COLOR_PURPLE = 0x00;
  465. const COLOR_RED = 0x00;
  466. const COLOR_SILVER = 0x00;
  467. const COLOR_WHITE = 0x00;
  468. const COLOR_YELLOW = 0x00;
  469. const PATTERN_NONE = 0x00;
  470. const PATTERN_SOLID = 0x00;
  471. const PATTERN_MEDIUM_GRAY = 0x00;
  472. const PATTERN_DARK_GRAY = 0x00;
  473. const PATTERN_LIGHT_GRAY = 0x00;
  474. const PATTERN_DARK_HORIZONTAL = 0x00;
  475. const PATTERN_DARK_VERTICAL = 0x00;
  476. const PATTERN_DARK_DOWN = 0x00;
  477. const PATTERN_DARK_UP = 0x00;
  478. const PATTERN_DARK_GRID = 0x00;
  479. const PATTERN_DARK_TRELLIS = 0x00;
  480. const PATTERN_LIGHT_HORIZONTAL = 0x00;
  481. const PATTERN_LIGHT_VERTICAL = 0x00;
  482. const PATTERN_LIGHT_DOWN = 0x00;
  483. const PATTERN_LIGHT_UP = 0x00;
  484. const PATTERN_LIGHT_GRID = 0x00;
  485. const PATTERN_LIGHT_TRELLIS = 0x00;
  486. const PATTERN_GRAY_125 = 0x00;
  487. const PATTERN_GRAY_0625 = 0x00;
  488. const BORDER_THIN = 0x00;
  489. const BORDER_MEDIUM = 0x00;
  490. const BORDER_DASHED = 0x00;
  491. const BORDER_DOTTED = 0x00;
  492. const BORDER_THICK = 0x00;
  493. const BORDER_DOUBLE = 0x00;
  494. const BORDER_HAIR = 0x00;
  495. const BORDER_MEDIUM_DASHED = 0x00;
  496. const BORDER_DASH_DOT = 0x00;
  497. const BORDER_MEDIUM_DASH_DOT = 0x00;
  498. const BORDER_DASH_DOT_DOT = 0x00;
  499. const BORDER_MEDIUM_DASH_DOT_DOT = 0x00;
  500. const BORDER_SLANT_DASH_DOT = 0x00;
  501. /**
  502. * Format constructor.
  503. *
  504. * @param resource $fileHandle
  505. */
  506. public function __construct($fileHandle)
  507. {
  508. //
  509. }
  510. /**
  511. * Wrap
  512. *
  513. * @return Format
  514. *
  515. * @author viest
  516. */
  517. public function wrap(): self
  518. {
  519. return $this;
  520. }
  521. /**
  522. * Bold
  523. *
  524. * @return Format
  525. *
  526. * @author viest
  527. */
  528. public function bold(): self
  529. {
  530. return $this;
  531. }
  532. /**
  533. * Italic
  534. *
  535. * @return Format
  536. *
  537. * @author viest
  538. */
  539. public function italic(): self
  540. {
  541. return $this;
  542. }
  543. /**
  544. * Cells border
  545. *
  546. * @param int $style const BORDER_***
  547. *
  548. * @return Format
  549. *
  550. * @author viest
  551. */
  552. public function border(int $style): self
  553. {
  554. return $this;
  555. }
  556. /**
  557. * Align
  558. *
  559. * @param int ...$style const FORMAT_ALIGN_****
  560. *
  561. * @return Format
  562. *
  563. * @author viest
  564. */
  565. public function align(...$style): self
  566. {
  567. return $this;
  568. }
  569. /**
  570. * Number format
  571. *
  572. * @param string $format
  573. *
  574. * #,##0
  575. *
  576. * @return Format
  577. *
  578. * @author viest
  579. */
  580. public function number(string $format): self
  581. {
  582. return $this;
  583. }
  584. /**
  585. * Font color
  586. *
  587. * @param int $color const COLOR_****
  588. *
  589. * @return Format
  590. *
  591. * @author viest
  592. */
  593. public function fontColor(int $color): self
  594. {
  595. return $this;
  596. }
  597. /**
  598. * Font
  599. *
  600. * @param string $fontName
  601. *
  602. * @return Format
  603. *
  604. * @author viest
  605. */
  606. public function font(string $fontName): self
  607. {
  608. return $this;
  609. }
  610. /**
  611. * Font size
  612. *
  613. * @param float $size
  614. *
  615. * @return Format
  616. *
  617. * @author viest
  618. */
  619. public function fontSize(float $size): self
  620. {
  621. return $this;
  622. }
  623. /**
  624. * String strikeout
  625. *
  626. * @return Format
  627. *
  628. * @author viest
  629. */
  630. public function strikeout(): self
  631. {
  632. return $this;
  633. }
  634. /**
  635. * Underline
  636. *
  637. * @param int $style const UNDERLINE_****
  638. *
  639. * @return Format
  640. *
  641. * @author viest
  642. */
  643. public function underline(int $style): self
  644. {
  645. return $this;
  646. }
  647. /**
  648. * Cell background
  649. *
  650. * @param int $color const COLOR_****
  651. * @param int $pattern const PATTERN_****
  652. *
  653. * @return Format
  654. *
  655. * @author viest
  656. */
  657. public function background(int $color, int $pattern = self::PATTERN_SOLID): self
  658. {
  659. return $this;
  660. }
  661. /**
  662. * Format to resource
  663. *
  664. * @return resource
  665. *
  666. * @author viest
  667. */
  668. public function toResource()
  669. {
  670. //
  671. }
  672. }