---
title: "EXCEL輸出"
description: "EMILY.RPA EXCEL 輸出模組：複製指定 EXCEL 檔案的資料內容，以 Low-Code API 增修資料或樣式，產生新的 output.xlsx。"
source: https://docs.emily.tips/wap/excel
---

# EXCEL輸出

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

![](https://docs.emily.tips/img/zh/wap-081.png)

## 參數

**`EXCEL`** - EXCEL 輸入檔，點擊「**PICK**」選取檔案、鍵盤輸入工作資料夾中的EXCEL檔名，或使用 **%FILENAME%** 變數。這個檔案的內容會被加入輸出檔案 output.xlsx 讓 Low-Code 加工處理，如果毋需參考任何 EXCEL 的內容可以留空。

## Low-Code 編輯器

### api 物件

除了共通的檔案處理同步函式之外，另外還提供 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) 等同步函式，使用方法可以參考以下範例：

```javascript
// 列出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 格式），它的格式如下：

```javascript
// 樣式物件
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)
```
