EXCEL Writer

建立 XLSX 格式檔案。複製指定EXCEL檔案的資料內容,以Low-Code提供的api增修資料或樣式,產生新的EXCEL檔案 output.xlsx

EXCEL

EXCEL輸入檔,點擊 PICK 選取檔案、鍵盤輸入工作資料夾中的EXCEL檔名,或使用 %FILENAME% 變數。載入資料會預設加入輸出檔案 output.xlsx,如果毋需參考任何EXCEL可以留空。

api 物件

除了常用的檔案處理同步函式 api.files(), api.read(filename, encoding='utf8'), api.write(filename, text), api.remove(filename) 之外,另外還提供 api.addSheet(header, rows, name), api.delSheet(name), api.sheetNames(), api.mergeCells(name, startRow, startCol, endRow, endCol), api.getCell(name, row, col), api.setCell(name, row, col, value, style), api.setColWidth(name, col, width), api.setRowHeight(name, row, height) 等同步函式,使用方法可以參考以下範例:

// 列出EXCEL檔的所有sheet
console.log(api.sheetNames())

// 加入新一頁 sheet
let rows = [{col1: 1, col2: '2'},{col1: 3, col2: '4'}]
api.addSheet(['col2','col1'], rows, 'new sheet')

// 合併儲存格:B2:C3
api.mergeCells('new sheet', 1, 1, 1, 2)

// 取得A1儲存格的值
console.log(api.getCell('new sheet', 0, 0))

// 寫入B2儲存格的值
api.setCell('new sheet', 1, 1, 'hello')

// 設定第1列(row為0)高度50
api.setRowHeight('new sheet', 0, 50)

// 設定C欄寬度為0(隱藏)
api.setColWidth('new sheet', 2, 0) 

// 刪除 sheet
api.delSheet('new sheet')

也可以用樣式物件對指定儲存格設定樣式(只能支援 XLSX 格式),它的格式如下:

// 樣式物件
const style = {
  alignment: {
    vertical: 'bottom', // 'top', 'center'
    horizontal: 'left', // 'center', 'right'
    wrapText: false, // true
  },
  font: {
    name: 'Calibri', // font family name
    sz: 12, // font size
    color: { rgb: 'FF0000' },
    bold: false, // true
    italic: false, // true
    underline: false, // true
    strike: false, // true
  },
  fill: {
    fgColor: { rgb: '00FF00' }
  },
  border: {
    top: { 
      style: 'thin', // 'thick','dashed','dotted','hair','medium'
      color: { rgb: '000000' }
    },
    bottom: {
      style: 'thin',
      color: { rgb: '000000' }
    },
    left: {
      style: 'thin',
      color: { rgb: '000000' }
    },
    right: {
      style: 'thin',
      color: { rgb: '000000' }
    }
  }
}

// 設定儲存格A1樣式
api.setCell('sheet name', 0, 0, 'style demo', style)

Last updated