IBSheet8 Manual Sample

author(s): IBSheet

HTML

<!-- ibsheet css -->
<link rel="stylesheet" href="https://www.ibsheet.com/v8/assets/lib/ibsheet/css/default/main.css"/>
<!--  ibsheet 필수 js -->
<script src="https://www.ibsheet.com/v8/assets/lib/iblicense.js"></script>
<script src="https://www.ibsheet.com/v8/assets/lib/ibsheet/ibsheet.js"></script>
<script src="https://www.ibsheet.com/v8/assets/lib/ibsheet/locale/ko.js"></script>

<!--  ibsheet 선택/추가 js -->
<script src="https://www.ibsheet.com/v8/assets/lib/ibsheet/plugins/ibsheet-common.js"></script>
<script src="https://www.ibsheet.com/v8/assets/lib/ibsheet/plugins/ibsheet-excel.js"></script>

<h3 style="margin:0 0 6px">맞벌이 부부 가계부 - down2Excel(서버) 사용자별 다운로드</h3>

<p style="margin:0 0 8px;font-size:13px;color:#333">
  서버 모듈로 다운로드하는 <code>down2Excel</code>은 <b>연달아 호출하면 마지막 파일만</b> 내려옵니다.
  그래서 사용자별로 나눠 받으려면 아래 방법을 씁니다.
</p>
<ul style="margin:0 0 8px;padding-left:18px;font-size:12px;color:#444;line-height:1.7">
  <li><b>여러 파일 (downRows+useXhr)</b> : 한 시트에서 <b>downRows로 행을 골라</b> <code>useXhr:1</code>로 각각 다운로드. 간편하지만 <b>서버가 다른 도메인이면 CORS에 걸릴 수 있습니다.</b></li>
  <li><b>여러 파일 (하나씩)</b> : 앞 파일이 끝나면 다음 파일을 이어서 받습니다. <b>서버가 다른 도메인이어도 동작합니다.</b></li>
  <li><b>한 파일 워크시트 (buffer)</b> : 임시 시트 + <code>down2ExcelBuffer</code>로 <b>한 파일 안에 워크시트 3개</b>.</li>
</ul>

<div>
  <button type='button' onclick='ib.sampleBtn(this)'>여러 파일 (downRows+useXhr)</button>
  <button type='button' onclick='ib.sampleBtn(this)'>여러 파일 (하나씩)</button>
  <button type='button' onclick='ib.sampleBtn(this)'>한 파일 워크시트 (buffer)</button>
  <button type='button' onclick='ib.sampleBtn(this)'>로그 지우기</button>
</div>

<div style='height:240px;margin-top:8px'><div id='sheetDiv' style='width:100%;height:100%'></div></div>
<div id="log"></div>

CSS

body { font-family: sans-serif; padding: 10px; }
button { padding: 6px 10px; margin-right: 6px; margin-bottom: 4px; }
#log {
  margin-top: 8px; padding: 8px; border: 1px solid #ccc;
  height: 110px; overflow: auto; white-space: pre-wrap; font-size: 12px;
}

JavaScript

var EXPORT_URL = "https://api.ibsheet.com/ibsheet/v8/";   // down2Excel 서버 URL

var ib = ib || {}
ib = {
  //시트 초기화 구문
  'init': {
    "Cfg": { "SearchMode": 2, "Export": { "Url": EXPORT_URL } },
    "Cols": [
      { "Header": "No",   "Name": "SEQ",  "Type": "Int",  "Width": 50,  "Align": "Center" },
      { "Header": "사용자", "Name": "USER", "Type": "Enum", "Enum": "|남편|아내|공동", "Width": 70, "Align": "Center" },
      { "Header": "분류", "Name": "CAT",  "Type": "Text", "Width": 80,  "Align": "Center" },
      { "Header": "내용", "Name": "ITEM", "Type": "Text", "Width": 150 },
      { "Header": "금액", "Name": "AMT",  "Type": "Int",  "Width": 110, "Format": "#,##0" }
    ]
  },

  //시트 이벤트
  event: {
    onRenderFirstFinish: function (evtParam) {
      evtParam.sheet.loadSearchData(ib.data)
    },
    // 방법2(하나씩) 전용: 이 모드가 켜져 있을 때만 앞 파일이 끝난 뒤 다음 파일 다운로드
    onExportFinish: function (evtParam) {
      if (!ib.chain) return
      ib.log("  ✔ " + ib.chainFiles[ib.chainIdx].fileName + " 완료")
      ib.chainIdx++
      if (ib.chainIdx < ib.chainFiles.length) {
        ib.log("down2Excel: " + ib.chainFiles[ib.chainIdx].fileName)
        evtParam.sheet.down2Excel(ib.chainFiles[ib.chainIdx])
      } else {
        ib.chain = false
        ib.log("전체 완료")
      }
    }
  },

  //하나씩 다운로드 진행 상태
  chain: false, chainFiles: [], chainIdx: 0,

  //시트객체 생성
  create: function () {
    var options = this.init
    options.Events = this.event
    IBSheet.create({ id: "sheet", el: "sheetDiv", options: options })
  },

  //로그 출력
  log: function (msg) {
    var el = document.getElementById("log")
    el.textContent += msg + "\n"
    el.scrollTop = el.scrollHeight
  },

  //USER 별 데이터행 index(1부터) → downRows 문자열용
  filesByUser: function () {
    var map = {}
    sheet.getSaveJson({ saveMode: 0 }).data.forEach(function (row, i) {
      (map[row.USER] = map[row.USER] || []).push(i + 1)
    })
    return Object.keys(map).map(function (k) {
      return { fileName: k + ".xlsx", downRows:...