행과 열
Facade API
전체 Facade API 타입 정의는 Facade API에서 확인할 수 있습니다.
행
지정한 위치 뒤에 행 삽입
insertRowAfter(afterPosition): 지정한 행 위치 뒤에 행을 삽입합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts a row after the first row positionsheet.insertRowAfter(0)지정한 위치 앞에 행 삽입
insertRowBefore(beforePosition): 지정한 행 위치 앞에 행을 삽입합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts a row before the first row positionsheet.insertRowBefore(0)지정한 위치에 여러 행 삽입
insertRows(rowIndex, numRows): 시트의 지정한 위치부터 하나 이상의 연속된 빈 행을 삽입합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Shifts all rows down by threesheet.insertRows(0, 3)지정한 위치 뒤에 여러 행 삽입
insertRowsAfter(afterPosition, howMany): 지정한 행 위치 뒤에 지정한 수의 행을 삽입합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts five rows after the first rowsheet.insertRowsAfter(0, 5)지정한 위치 앞에 여러 행 삽입
insertRowsBefore(beforePosition, howMany): 지정한 행 위치 앞에 지정한 수의 행을 삽입합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts five rows before the first rowsheet.insertRowsBefore(0, 5)지정한 위치의 행 삭제
deleteRow(rowPosition): 지정한 행 위치의 행을 삭제합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Rows start at "0" - this deletes the first rowsheet.deleteRow(0)지정한 위치부터 여러 행 삭제
deleteRows(rowPosition, howMany): 지정한 행 위치부터 지정한 수의 행을 삭제합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Rows start at "0" - this deletes the first two rowssheet.deleteRows(0, 2)지정한 여러 위치의 행 삭제
deleteRowsByPoints(rowPoints): 행 위치 배열로 지정한 여러 행을 삭제합니다. 행은 연속되지 않아도 됩니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Rows start at "0" - this deletes the 3rd row and rows 5 to 7fWorksheet.deleteRowsByPoints([2, [4, 6]])행을 새 위치로 이동
moveRows(rowSpec, destinationIndex): 지정한 범위가 선택한 행을 destinationIndex가 가리키는 위치로 이동합니다. rowSpec 자체가 이동할 전체 행 또는 행 그룹을 정확히 나타낼 필요는 없으며, 범위에 걸쳐 있는 모든 행을 선택합니다.
// The code below moves rows 1-2 to destination index 5// This results in those rows becoming rows 3-4const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Selects row 1 and row 2 to be movedconst rowSpec = sheet.getRange('1:2')sheet.moveRows(rowSpec, 5)지정한 범위의 행 숨기기
hideRow(row): 지정한 범위의 행을 숨깁니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This hides the first rowconst range = sheet.getRange('1:1')sheet.hideRow(range)연속된 여러 행 숨기기
hideRows(rowIndex, numRows): 지정한 인덱스부터 하나 이상의 연속된 행을 숨깁니다. 이 메서드는 0부터 시작하는 인덱스를 사용합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Hides the first three rowssheet.hideRows(0, 3)지정한 범위의 행 숨기기 해제
unhideRow(row): 지정한 범위의 행 숨기기를 해제합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This unhides the first row if it was previously hiddenconst range = sheet.getRange('1:1')sheet.unhideRow(range)연속된 여러 행 숨기기 해제
showRows(rowIndex, numRows): 지정한 인덱스부터 하나 이상의 연속된 행 숨기기를 해제합니다. 이 메서드는 0부터 시작하는 인덱스를 사용합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Unhides the first three rowssheet.showRows(0, 3)행 높이 설정
setRowHeight(rowPosition, height): 지정한 행의 높이를 픽셀 단위로 설정합니다. 기본적으로 행은 셀 내용에 맞게 늘어납니다. 행을 지정한 높이로 고정하려면 setRowHeightsForced(startRow, numRows, height)를 사용하세요.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Sets the first row to a height of 200 pixelssheet.setRowHeight(0, 200)여러 행의 높이 설정
setRowHeights(startRow, numRows, height): 지정한 행들의 높이를 픽셀 단위로 설정합니다. 기본적으로 행은 셀 내용에 맞게 늘어납니다. 행을 지정한 높이로 고정하려면 setRowHeightsForced(startRow, numRows, height)를 사용하세요.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Sets the first three rows to a height of 200 pixelssheet.setRowHeights(0, 3, 200)여러 행의 높이 강제 설정
setRowHeightsForced(startRow, numRows, height): 지정한 행들의 높이를 픽셀 단위로 설정합니다. setRowHeightsForced를 사용하면 셀 내용이 행 높이보다 크더라도 행이 지정한 높이로 강제 설정됩니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Sets the first three rows to a height of 5 pixelssheet.setRowHeightsForced(0, 3, 5)행 크기 자동 조정
autoResizeRows(startRow, numRows): 지정한 행의 높이를 텍스트 내용에 맞게 자동 조정합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Set the first 3 rows to a height that fits their text.sheet.autoResizeRows(0, 3)행 사용자 지정 속성 설정
setRowCustom(custom): 지정한 행에 사용자 지정 속성을 설정합니다. 행에 custom 객체를 저장하며, 추가 정보를 저장하기 위해 JSON 형식을 따르는 모든 데이터를 넣을 수 있습니다.
custom 데이터를 업데이트하면 기존 custom 데이터를 덮어씁니다. 업데이트할 때 기존 데이터를 유지해야 한다면 먼저 custom 데이터를 가져와 새 데이터와 병합한 후 업데이트하세요.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Set custom properties for the first and third rowssheet.setRowCustom({ 0: { color: 'red' }, 2: { size: 16 },})열
지정한 위치 뒤에 열 삽입
insertColumnAfter(afterPosition): 지정한 열 위치 뒤에 열을 삽입합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts a column after the first column positionsheet.insertColumnAfter(0)지정한 위치 앞에 열 삽입
insertColumnBefore(beforePosition): 지정한 열 위치 앞에 열을 삽입합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts a column in the first column positionsheet.insertColumnBefore(0)지정한 위치에 여러 열 삽입
insertColumns(columnIndex, numColumns): 시트의 지정한 위치부터 하나 이상의 연속된 빈 열을 삽입합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Shifts all columns by threesheet.insertColumns(0, 3)지정한 위치 뒤에 여러 열 삽입
insertColumnsAfter(afterPosition, howMany): 지정한 열 위치 뒤에 지정한 수의 열을 삽입합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Inserts two columns after the first columnsheet.insertColumnsAfter(0, 2)지정한 위치 앞에 여러 열 삽입
insertColumnsBefore(beforePosition, howMany): 지정한 열 위치 앞에 지정한 수의 열을 삽입합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This inserts five columns before the first columnsheet.insertColumnsBefore(0, 5)지정한 위치의 열 삭제
deleteColumn(columnPosition): 지정한 열 위치의 열을 삭제합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Columns start at "0" - this deletes the first columnsheet.deleteColumn(0)지정한 위치부터 여러 열 삭제
deleteColumns(columnPosition, howMany): 지정한 열 위치부터 여러 열을 삭제합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Columns start at "0" - this deletes the first two columnssheet.deleteColumns(0, 2)지정한 여러 위치의 열 삭제
deleteColumnsByPoints(columnPoints): 열 위치 배열로 지정한 여러 열을 삭제합니다. 열은 연속되지 않아도 됩니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Columns start at "0" - this deletes the Column C and Columns E-GfWorksheet.deleteColumnsByPoints([2, [4, 6]])열을 새 위치로 이동
moveColumns(columnSpec, destinationIndex): 지정한 범위가 선택한 열을 destinationIndex가 가리키는 위치로 이동합니다. columnSpec 자체가 이동할 전체 열 또는 열 그룹을 정확히 나타낼 필요는 없으며, 범위에 걸쳐 있는 모든 열을 선택합니다.
// The code below moves rows A-B to destination index 5.// This results in those columns becoming columns C-D.const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Selects column A and column B to be moved.const columnSpec = sheet.getRange('A:B')sheet.moveColumns(columnSpec, 5)지정한 범위의 열 숨기기
hideColumn(column): 지정한 범위의 열을 숨깁니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This hides the first columnconst range = sheet.getRange('A:A')sheet.hideColumn(range)연속된 여러 열 숨기기
hideColumns(columnIndex, numColumns): 지정한 인덱스부터 하나 이상의 연속된 열을 숨깁니다. 이 메서드는 0부터 시작하는 인덱스를 사용합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Hides the first three columnssheet.hideColumns(0, 3)지정한 범위의 열 숨기기 해제
unhideColumn(column): 지정한 범위의 열 숨기기를 해제합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// This unhides the first column if it was previously hiddenconst range = sheet.getRange('A:A')sheet.unhideColumn(range)연속된 여러 열 숨기기 해제
showColumns(columnIndex, numColumns): 지정한 인덱스부터 하나 이상의 연속된 열 숨기기를 해제합니다. 이 메서드는 0부터 시작하는 인덱스를 사용합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Unhides the first three columnssheet.showColumns(0, 3)열 너비 설정
setColumnWidth(columnPosition, width): 지정한 열의 너비를 픽셀 단위로 설정합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Sets the first column to a width of 200 pixelssheet.setColumnWidth(0, 200)여러 열의 너비 설정
setColumnWidths(startColumn, numColumns, width): 지정한 열들의 너비를 픽셀 단위로 설정합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Sets the first three columns to a width of 200 pixelssheet.setColumnWidths(0, 3, 200)열 크기 자동 조정
autoResizeColumns(startColumn, numColumns): 지정한 열의 너비를 텍스트 내용에 맞게 자동 조정합니다.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Set the A:C columns to a width that fits their text.sheet.autoResizeColumns(0, 3)열 사용자 지정 속성 설정
setColumnCustom(custom): 지정한 열에 사용자 지정 속성을 설정합니다. 열에 custom 객체를 저장하며, 추가 정보를 저장하기 위해 JSON 형식을 따르는 모든 데이터를 넣을 수 있습니다.
custom 데이터를 업데이트하면 기존 custom 데이터를 덮어씁니다. 업데이트할 때 기존 데이터를 유지해야 한다면 먼저 custom 데이터를 가져와 새 데이터와 병합한 후 업데이트하세요.
const sheet = univerAPI.getActiveWorkbook().getActiveSheet()// Set custom properties for the first and third columnssheet.setColumnCustom({ 0: { color: 'red' }, 2: { size: 16 },})크기 검증과 크기가 0인 행·열
행 높이와 열 너비는 유한한 음이 아닌 숫자여야 합니다. 크기 명령은 숫자 문자열, 음수, NaN, Infinity를 거부합니다. 개별 행·열은 0을 허용하지만 defaultRowHeight와 defaultColumnWidth는 양수여야 합니다. 시트를 만들 때 스냅샷의 잘못된 크기가 정규화됩니다.
크기 0과 표시 플래그로 숨긴 상태는 다릅니다. 표시 상태지만 크기가 0인 행·열의 숨기기를 해제하면 시트 기본 크기로 복원되며 실행 취소와 다시 실행도 지원합니다. 외부 크기를 전달하기 전에 아래 공개 검증 함수를 사용할 수 있습니다.
import { isValidColumnDimensions, isValidRowDimensions, isValidSheetDimension } from '@univerjs/core'isValidSheetDimension(24) // trueisValidSheetDimension(0, false) // false: default dimensions must be positiveisValidRowDimensions({ h: 24, ah: 32 }) // trueisValidColumnDimensions({ w: -1 }) // false이 가이드는 어떠셨나요?