# [php] composer 없이  spreadsheet 사용하기

- 주소: https://duotone.co.kr/entry/composer-%EC%97%86%EB%8B%88-phpspreadsheet-%EC%82%AC%EC%9A%A9%ED%95%98%EA%B8%B0
- 글쓴이: 서기㏇
- 카테고리: 개발·프로그래밍
- 작성일: 2020-02-05
- 수정일: 2020-02-06
- 태그: cafe24, composer, php, spreadsheet, Without, 스프레드시트, 없이, 카페24, 콤포저, 패키지

phpspreadsheet를 cafe24에서 사용하려고 하니 composer가 필요했다.
composer는 패키지들의 의존성 도구로 별도 잘못 설치하다가 꼬일 수 있는 부분을 해결해주는 도구이다. 
하지만 대부분의 일반 호스팅에서는 지원을 하지 않고 있으니 사용할 수가 없다 ㅠㅠ;;; 
해서... 찾아보니 역시 방법이 있었다... 
차후에도 사용하려고 여기에 기재해 놓는다. 

1. phpspreadsheet 다운받기 
  - [https://github.com/PHPOffice/PhpSpreadsheet](https://github.com/PHPOffice/PhpSpreadsheet) 

[PHPOffice/PhpSpreadsheet](https://github.com/PHPOffice/PhpSpreadsheet)

2. 다운받은 폴더의 src폴더를 PhpOffice로 변경한 후 웹상에 폴더에 업로드 한다. 

![[php] composer 없이  spreadsheet 사용하기](https://duotone.co.kr/media/deb237db1706d8e2.png)

3. composer에는 PSR Cache Interface라는게 존재하는데 이걸 대응할 폴더와 파일을 만든다.
    - PhpOffice에 Psr폴더를 만든다. 

![[php] composer 없이  spreadsheet 사용하기 2](https://duotone.co.kr/media/1e9a9b3c05f744a6.png)

    - Psr폴더에 autoloader.php와 Psr.php를 만든다. 
    - autoloader.php

```
    - Psr.php 

```
 value pairs. Cache keys that do not exist or are stale will have $default as value.
     *
     * @throws \Psr\SimpleCache\InvalidArgumentException
     *   MUST be thrown if $keys is neither an array nor a Traversable,
     *   or if any of the $keys are not a legal value.
     */
    public function getMultiple($keys, $default = null);

    /**
     * Persists a set of key => value pairs in the cache, with an optional TTL.
     *
     * @param iterable               $values A list of key => value pairs for a multiple-set operation.
     * @param null|int|\DateInterval $ttl    Optional. The TTL value of this item. If no value is sent and
     *                                       the driver supports TTL then the library may set a default value
     *                                       for it or let the driver take care of that.
     *
     * @return bool True on success and false on failure.
     *
     * @throws \Psr\SimpleCache\InvalidArgumentException
     *   MUST be thrown if $values is neither an array nor a Traversable,
     *   or if any of the $values are not a legal value.
     */
    public function setMultiple($values, $ttl = null);

    /**
     * Deletes multiple cache items in a single operation.
     *
     * @param iterable $keys A list of string-based keys to be deleted.
     *
     * @return bool True if the items were successfully removed. False if there was an error.
     *
     * @throws \Psr\SimpleCache\InvalidArgumentException
     *   MUST be thrown if $keys is neither an array nor a Traversable,
     *   or if any of the $keys are not a legal value.
     */
    public function deleteMultiple($keys);

    /**
     * Determines whether an item is present in the cache.
     *

     * NOTE: It is recommended that has() is only to be used for cache warming type purposes
     * and not to be used within your live applications operations for get/set, as this method
     * is subject to a race condition where your has() will return true and immediately after,
     * another script can remove it, making the state of your app out of date.
     *
     * @param string $key The cache item key.
     *
     * @return bool
     *
     * @throws \Psr\SimpleCache\InvalidArgumentException
     *   MUST be thrown if the $key string is not a legal value.
     */
    public function has($key);
}
```

4. PhpPhpSpreadsheet에도 autoloader.php를 만든다. 
  

![[php] composer 없이  spreadsheet 사용하기 3](https://duotone.co.kr/media/fad11dd02cba8c9b.png)

    - autoloader.php 
   

```
 이제 최상위 폴더(PhpOffice의 상위 폴더)에 파일을 작성한 후 테스트 해본다. 

5. excel.php로 작성하였으며, 예제는 sample.xlsx이 사용되었고, 재고라는 시트명이 있는 파일이다. 

```
getSheetByName('재고')->toArray(null, true, true, true);

?>

              |

```
