helper.php 13 KB

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