helper.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632
  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. * Read values from the sheet
  323. *
  324. * @return array
  325. *
  326. * @author viest
  327. */
  328. public function getSheetData(): array
  329. {
  330. return [];
  331. }
  332. /**
  333. * Read values from the sheet
  334. *
  335. * @return array
  336. *
  337. * @author viest
  338. */
  339. public function nextRow(): array
  340. {
  341. return [];
  342. }
  343. /**
  344. * Next Cell In Callback
  345. *
  346. * @param callable $callback function(int $row, int $cell, string $data)
  347. * @param string|NULL $sheetName sheet name
  348. *
  349. * @author viest
  350. */
  351. public function nextCellCallback(callable $callback, string $sheetName = NULL): void
  352. {
  353. //
  354. }
  355. }
  356. /**
  357. * Class Format
  358. *
  359. * @author viest
  360. *
  361. * @package Vtiful\Kernel
  362. */
  363. class Format
  364. {
  365. const UNDERLINE_SINGLE = 0x00;
  366. const UNDERLINE_DOUBLE = 0x00;
  367. const UNDERLINE_SINGLE_ACCOUNTING = 0x00;
  368. const UNDERLINE_DOUBLE_ACCOUNTING = 0x00;
  369. const FORMAT_ALIGN_LEFT = 0x00;
  370. const FORMAT_ALIGN_CENTER = 0x00;
  371. const FORMAT_ALIGN_RIGHT = 0x00;
  372. const FORMAT_ALIGN_FILL = 0x00;
  373. const FORMAT_ALIGN_JUSTIFY = 0x00;
  374. const FORMAT_ALIGN_CENTER_ACROSS = 0x00;
  375. const FORMAT_ALIGN_DISTRIBUTED = 0x00;
  376. const FORMAT_ALIGN_VERTICAL_TOP = 0x00;
  377. const FORMAT_ALIGN_VERTICAL_BOTTOM = 0x00;
  378. const FORMAT_ALIGN_VERTICAL_CENTER = 0x00;
  379. const FORMAT_ALIGN_VERTICAL_JUSTIFY = 0x00;
  380. const FORMAT_ALIGN_VERTICAL_DISTRIBUTED = 0x00;
  381. const COLOR_BLACK = 0x00;
  382. const COLOR_BLUE = 0x00;
  383. const COLOR_BROWN = 0x00;
  384. const COLOR_CYAN = 0x00;
  385. const COLOR_GRAY = 0x00;
  386. const COLOR_GREEN = 0x00;
  387. const COLOR_LIME = 0x00;
  388. const COLOR_MAGENTA = 0x00;
  389. const COLOR_NAVY = 0x00;
  390. const COLOR_ORANGE = 0x00;
  391. const COLOR_PINK = 0x00;
  392. const COLOR_PURPLE = 0x00;
  393. const COLOR_RED = 0x00;
  394. const COLOR_SILVER = 0x00;
  395. const COLOR_WHITE = 0x00;
  396. const COLOR_YELLOW = 0x00;
  397. const PATTERN_NONE = 0x00;
  398. const PATTERN_SOLID = 0x00;
  399. const PATTERN_MEDIUM_GRAY = 0x00;
  400. const PATTERN_DARK_GRAY = 0x00;
  401. const PATTERN_LIGHT_GRAY = 0x00;
  402. const PATTERN_DARK_HORIZONTAL = 0x00;
  403. const PATTERN_DARK_VERTICAL = 0x00;
  404. const PATTERN_DARK_DOWN = 0x00;
  405. const PATTERN_DARK_UP = 0x00;
  406. const PATTERN_DARK_GRID = 0x00;
  407. const PATTERN_DARK_TRELLIS = 0x00;
  408. const PATTERN_LIGHT_HORIZONTAL = 0x00;
  409. const PATTERN_LIGHT_VERTICAL = 0x00;
  410. const PATTERN_LIGHT_DOWN = 0x00;
  411. const PATTERN_LIGHT_UP = 0x00;
  412. const PATTERN_LIGHT_GRID = 0x00;
  413. const PATTERN_LIGHT_TRELLIS = 0x00;
  414. const PATTERN_GRAY_125 = 0x00;
  415. const PATTERN_GRAY_0625 = 0x00;
  416. const BORDER_THIN = 0x00;
  417. const BORDER_MEDIUM = 0x00;
  418. const BORDER_DASHED = 0x00;
  419. const BORDER_DOTTED = 0x00;
  420. const BORDER_THICK = 0x00;
  421. const BORDER_DOUBLE = 0x00;
  422. const BORDER_HAIR = 0x00;
  423. const BORDER_MEDIUM_DASHED = 0x00;
  424. const BORDER_DASH_DOT = 0x00;
  425. const BORDER_MEDIUM_DASH_DOT = 0x00;
  426. const BORDER_DASH_DOT_DOT = 0x00;
  427. const BORDER_MEDIUM_DASH_DOT_DOT = 0x00;
  428. const BORDER_SLANT_DASH_DOT = 0x00;
  429. /**
  430. * Format constructor.
  431. *
  432. * @param resource $fileHandle
  433. */
  434. public function __construct($fileHandle)
  435. {
  436. //
  437. }
  438. /**
  439. * Wrap
  440. *
  441. * @return Format
  442. *
  443. * @author viest
  444. */
  445. public function wrap(): self
  446. {
  447. return $this;
  448. }
  449. /**
  450. * Bold
  451. *
  452. * @return Format
  453. *
  454. * @author viest
  455. */
  456. public function bold(): self
  457. {
  458. return $this;
  459. }
  460. /**
  461. * Italic
  462. *
  463. * @return Format
  464. *
  465. * @author viest
  466. */
  467. public function italic(): self
  468. {
  469. return $this;
  470. }
  471. /**
  472. * Cells border
  473. *
  474. * @param int $style const BORDER_***
  475. *
  476. * @return Format
  477. *
  478. * @author viest
  479. */
  480. public function border(int $style): self
  481. {
  482. return $this;
  483. }
  484. /**
  485. * Align
  486. *
  487. * @param int ...$style const FORMAT_ALIGN_****
  488. *
  489. * @return Format
  490. *
  491. * @author viest
  492. */
  493. public function align(...$style): self
  494. {
  495. return $this;
  496. }
  497. /**
  498. * Number format
  499. *
  500. * @param string $format
  501. *
  502. * #,##0
  503. *
  504. * @return Format
  505. *
  506. * @author viest
  507. */
  508. public function number(string $format): self
  509. {
  510. return $this;
  511. }
  512. /**
  513. * Font color
  514. *
  515. * @param int $color const COLOR_****
  516. *
  517. * @return Format
  518. *
  519. * @author viest
  520. */
  521. public function fontColor(int $color): self
  522. {
  523. return $this;
  524. }
  525. /**
  526. * Font size
  527. *
  528. * @param float $size
  529. *
  530. * @return Format
  531. *
  532. * @author viest
  533. */
  534. public function fontSize(float $size): self
  535. {
  536. return $this;
  537. }
  538. /**
  539. * String strikeout
  540. *
  541. * @return Format
  542. *
  543. * @author viest
  544. */
  545. public function strikeout(): self
  546. {
  547. return $this;
  548. }
  549. /**
  550. * Underline
  551. *
  552. * @param int $style const UNDERLINE_****
  553. *
  554. * @return Format
  555. *
  556. * @author viest
  557. */
  558. public function underline(int $style): self
  559. {
  560. return $this;
  561. }
  562. /**
  563. * Cell background
  564. *
  565. * @param int $pattern const PATTERN_****
  566. * @param int $color const COLOR_****
  567. *
  568. * @return Format
  569. *
  570. * @author viest
  571. */
  572. public function background(int $pattern, int $color): self
  573. {
  574. return $this;
  575. }
  576. /**
  577. * Format to resource
  578. *
  579. * @return resource
  580. *
  581. * @author viest
  582. */
  583. public function toResource()
  584. {
  585. //
  586. }
  587. }