워크시트를 사용하는 Angular

    The Infragistics Angular Excel Engine's worksheet is where your data is kept. You can input data by working with the Worksheet's rows and cells and setting their corresponding values. The worksheet allows you to filter, sort, and customize the formats of the cells, as shown below.

    Angular Using Worksheets Example

    다음 코드는 아래 코드 조각을 사용하는 데 필요한 가져오기를 보여줍니다.

    import { Workbook } from "igniteui-angular-excel";
    import { Worksheet } from "igniteui-angular-excel";
    import { WorkbookFormat } from "igniteui-angular-excel";
    import { Color } from "igniteui-angular-core";
    
    import { CustomFilterCondition } from "igniteui-angular-excel";
    import { ExcelComparisonOperator } from "igniteui-angular-excel";
    import { FormatConditionTextOperator } from "igniteui-angular-excel";
    import { OrderedSortCondition } from "igniteui-angular-excel";
    import { RelativeIndex } from "igniteui-angular-excel";
    import { SortDirection } from "igniteui-angular-excel";
    import { WorkbookColorInfo } from "igniteui-angular-excel";
    

    Configuring the Gridlines

    눈금선은 워크시트의 셀을 시각적으로 구분하는 데 사용됩니다. 눈금선을 표시하거나 숨길 수 있으며 색상도 변경할 수 있습니다.

    You can show or hide the gridlines using the showGridlines property of the displayOptions of the worksheet. The following code demonstrates how you can hide the gridlines in your worksheet:

    var workbook = new Workbook(WorkbookFormat.Excel2007);
    var worksheet = workbook.worksheets().add("Sheet1");
    
    worksheet.displayOptions.showGridlines = false;
    

    You can configure the gridlines' color using the gridlineColor property of the displayOptions of the worksheet. The following code demonstrates how you can change the gridlines in your worksheet to be red:

    var workbook = new Workbook(WorkbookFormat.Excel2007);
    var worksheet = workbook.worksheets().add("Sheet1");
    
    worksheet.displayOptions.gridlineColor = "Red";
    

    Configuring the Headers

    열과 행 머리글은 열과 행을 시각적으로 식별하는 데 사용됩니다. 또한 현재 선택된 셀이나 셀 영역을 시각적으로 강조하는 데에도 사용됩니다.

    You can show or hide the column and row headers using the showRowAndColumnHeaders property of the displayOptions of the worksheet. The following code demonstrates how you can hide the row and column headers:

    var workbook = new Workbook(WorkbookFormat.Excel2007);
    var worksheet = workbook.worksheets().add("Sheet1");
    
    worksheet.displayOptions.showRowAndColumnHeaders = false;
    

    Configuring Editing of the Worksheet

    By default, the worksheet objects that you save will be editable. You can disable editing of a worksheet by protecting it using the worksheet object's protect method. This method has a lot of nullable bool arguments that determine which pieces are protected, and one of these options is to allow editing of objects, which if set to false will prevent editing of the worksheet.

    다음 코드는 워크시트에서 편집을 비활성화하는 방법을 보여줍니다.

    var workbook = new Workbook(WorkbookFormat.Excel2007);
    var worksheet = workbook.worksheets().add("Sheet1");
    
    worksheet.protect();
    

    You can also use the worksheet object's protect method to protect a worksheet against structural changes.

    When protection is set, you can set the cellFormat object's locked property on individual cells, rows, merged cell regions, or columns to override the worksheet object's protection on those objects. For example, if you need all cells of a worksheet to be read-only except for the cells of one column, you can protect the worksheet and then set the cellFormat object's locked property to false on a specific WorksheetColumn object. This will allow your users to edit cells within the column while disabling editing of the other cells in the worksheet.

    다음 코드는 이를 수행하는 방법을 보여줍니다.

    var workbook = new Workbook(WorkbookFormat.Excel2007);
    var worksheet = workbook.worksheets().add("Sheet1");
    
    worksheet.protect();
    worksheet.columns(0).cellFormat.locked = false;
    

    Filtering Worksheet Regions

    Filtering is done by setting a filter condition on a worksheet's WorksheetFilterSettings which can be retrieved from the worksheet object's filterSettings property. Filter conditions are only reapplied when they're added, removed, modified, or when the reapplyFilters method is called on the worksheet. They are not constantly evaluated as data within the region changes.

    You can specify the region to apply the filter by using the setRegion method on the WorksheetFilterSettings object.

    다음은 워크시트에 필터를 추가하는 데 사용할 수 있는 방법 및 설명 목록입니다.

    방법 설명
    applyAverageFilter 데이터가 전체 데이터 범위의 평균보다 낮거나 높은지 여부에 따라 데이터를 필터링할 수 있는 필터를 나타냅니다.
    applyDatePeriodFilter 월 또는 임의 분기의 날짜를 필터링할 수 있는 필터를 나타냅니다.
    applyFillFilter 배경 채우기를 기준으로 셀을 필터링하는 필터를 나타냅니다. 이 필터는 단일 CellFill을 지정합니다. 이 채우기가 있는 셀은 데이터 범위에 표시됩니다. 다른 모든 셀은 숨겨집니다.
    ApplyFixedValuesFilter 표시가 허용되는 특정 고정 값을 기반으로 셀을 필터링할 수 있는 필터를 나타냅니다.
    applyFontColorFilter 글꼴 색상을 기준으로 셀을 필터링하는 필터를 나타냅니다. 이 필터는 단일 색상을 지정합니다. 이 색상 글꼴이 있는 셀은 데이터 범위에 표시됩니다. 다른 모든 셀은 숨겨집니다.
    applyIconFilter 조건부 서식 아이콘을 기준으로 셀을 필터링할 수 있는 필터를 나타냅니다.
    applyRelativeDateRangeFilter 필터가 적용된 시점을 기준으로 날짜를 기준으로 날짜 셀을 필터링할 수 있는 필터를 나타냅니다.
    applyTopOrBottomFilter 정렬된 값의 위쪽 또는 아래쪽 셀을 필터링할 수 있는 필터를 나타냅니다.
    applyYearToDateFilter 날짜가 현재 연도의 시작과 필터가 평가되는 시간 사이에 발생하는 경우 날짜 셀에서 필터링할 수 있는 필터를 나타냅니다.
    applyCustomFilter 하나 또는 두 개의 사용자 정의 조건을 기반으로 데이터를 필터링할 수 있는 필터를 나타냅니다. 이러한 두 필터 조건은 논리적 "and" 또는 논리적 "or" 연산과 결합될 수 있습니다.

    워크시트 영역에 필터를 추가하는 예로 다음 코드 조각을 사용할 수 있습니다.

    var workbook = new Workbook(WorkbookFormat.Excel2007);
    var worksheet = workbook.worksheets().add("Sheet1");
    
    worksheet.filterSettings.setRegion("Sheet1!A1:A10");
    worksheet.filterSettings.applyAverageFilter(0, AverageFilterType.AboveAverage);
    

    Freezing and Splitting Panes

    창 고정 기능을 사용하면 워크시트 상단의 행이나 왼쪽 열을 고정할 수 있습니다. 고정된 행과 열은 사용자가 스크롤하는 동안 항상 표시됩니다. 고정된 행과 열은 제거할 수 없는 단일 실선으로 워크시트의 나머지 부분과 구분됩니다.

    In order to enable pane freezing, you need to set the panesAreFrozen property of the worksheet object's displayOptions to true. You can then specify the rows or columns to freeze by using the FrozenRows and FrozenColumns properties of the display options frozenPaneSettings, respectively.

    또한 하단 창의 첫 번째 행이나 오른쪽 창의 첫 번째 열을 각각 속성FirstRowInBottomPane으로FirstColumnInRightPane 지정할 수 있습니다.

    다음 코드 조각은 워크시트에서 고정 창 기능을 사용하는 방법을 보여줍니다.

    var workbook = new Workbook(WorkbookFormat.Excel2007);
    var worksheet = workbook.worksheets().add("Sheet1");
    
    worksheet.displayOptions.panesAreFrozen = true;
    
    worksheet.displayOptions.frozenPaneSettings.frozenRows = 3;
    worksheet.displayOptions.frozenPaneSettings.frozenColumns = 1;
    
    worksheet.displayOptions.frozenPaneSettings.firstColumnInRightPane = 2;
    worksheet.displayOptions.frozenPaneSettings.firstRowInBottomPane = 6;
    

    Setting the Worksheet Zoom Level

    You can change the zoom level for each worksheet independently using the MagnificationInNormalView property on the worksheet object's displayOptions. This property takes a value between 10 and 400 and represents the percentage of zoom that you wish to apply.

    다음 코드는 이를 수행하는 방법을 보여줍니다.

    var workbook = new Workbook(WorkbookFormat.Excel2007);
    var worksheet = workbook.worksheets().add("Sheet1");
    
    worksheet.displayOptions.magnificationInNormalView = 300;
    

    Worksheet Level Sorting

    정렬은 열이나 행의 워크시트 수준 개체에 정렬 조건을 설정하여 수행됩니다. 열이나 행을 오름차순이나 내림차순으로 정렬할 수 있습니다.

    This is done by specifying a region and sort type to the worksheet object's WorksheetSortSettings that can be retrieved using the sortSettings property of the sheet.

    The sort conditions in a sheet are only reapplied when sort conditions are added, removed, modified, or when the reapplySortConditions method is called on the worksheet. Columns or rows will be sorted within the region. "Rows" is the default sort type.

    다음 코드 조각은 워크시트의 셀 영역에 정렬을 적용하는 방법을 보여줍니다.

    var workbook = new Workbook(WorkbookFormat.Excel2007);
    var worksheet = workbook.worksheets().add("Sheet1");
    
    worksheet.sortSettings.sortConditions().addItem(new RelativeIndex(0), new OrderedSortCondition(SortDirection.Ascending));
    

    Worksheet Protection

    You can protect a worksheet by calling the protect method on the worksheet object. This method exposes many nullable bool parameters that allow you to restrict or allow the following user operations:

    • 셀 편집.
    • 도형, 메모, 차트 또는 기타 컨트롤과 같은 개체 편집.
    • 시나리오 편집.
    • 데이터 필터링.
    • 셀 서식 지정.
    • 열 삽입, 삭제 및 서식 지정
    • 행 삽입, 삭제 및 서식 지정
    • 하이퍼링크 삽입.
    • 데이터 정렬.
    • 피벗 테이블의 활용.

    You can remove worksheet protection by calling the unprotect method on the worksheet object.

    다음 코드 조각은 위에 나열된 모든 사용자 작업을 보호하는 방법을 보여줍니다.

    var workbook = new Workbook(WorkbookFormat.Excel2007);
    var worksheet = workbook.worksheets().add("Sheet1");
    
    worksheet.protect();
    

    Worksheet Conditional Formatting

    You can configure the conditional formatting of a worksheet object by using the many "Add" methods exposed on the conditionalFormats collection of that worksheet. The first parameter of these "Add" methods is the string region of the worksheet that you would like to apply the conditional format to.

    Many of the conditional formats that you can add to your worksheet have a cellFormat property that determines the way that the WorksheetCell elements should look when the condition in that conditional format holds true. For example, you can use the properties attached to this cellFormat property such as fill and font to determine the background and font settings of your cells under a particular conditional format, respectively.

    There are a few conditional formats that do not have a cellFormat property, as their visualization on the worksheet cell behaves differently. These conditional formats are the DataBarConditionalFormat, ColorScaleConditionalFormat, and IconSetConditionalFormat.

    When loading a pre-existing workbook from Excel, the formats will be preserved when that workbook is loaded. The same is true for when you save the workbook out to an Excel file.

    다음 코드 예제에서는 워크시트에서 조건부 서식을 사용하는 방법을 보여줍니다.

    var workbook = new Workbook(WorkbookFormat.Excel2007);
    var worksheet = workbook.worksheets().add("Sheet1");
    
    var color = new Color();
    color.colorString = "Red";
    
    var format = worksheet.conditionalFormats().addAverageCondition("A1:A10", FormatConditionAboveBelow.AboveAverage);
    format.cellFormat.font.colorInfo = new WorkbookColorInfo(color);
    

    API References