팡이네

파이프를 변수에 넣어 동적으로 적용시키고자 할 때 사용

 

dynamic-pipe.ts

import { Injector, Pipe, PipeTransform } from '@angular/core';
import { NumberZeroPipe } from './number-zero.pipe';
import { StringZeroPipe } from './string-zero.pipe';

@Pipe({
    name: 'dynamicPipe'
})
export class DynamicPipe implements PipeTransform {

    public constructor(
        private injector: Injector
    ) {
    }

    transform(value: any, pipeToken: any, pipeArgs: any[]): any {
        // 사용할 pipe 선언
        const MAP = {
            'number0': NumberZeroPipe,
            'string0': StringZeroPipe,
        }

        if (pipeToken && MAP.hasOwnProperty(pipeToken)) {
            var pipeClass = MAP[pipeToken];
            var pipe = this.injector.get(pipeClass);
            if (Array.isArray(pipeArgs)) {
                return pipe.transform(value, ...pipeArgs);
            } else {
                return pipe.transform(value, pipeArgs);
            }
        }
        else {
            return value;
        }
    }
}

HTML

<ul>
    <li *ngFor="let item of list">
        {{ item.data | dynamicPipe: item.pipe : item.pipeOptions }}
    </li>
</ul>

TS

this.list = [
	{ data: 1000000.12345, pipe: 'number0', pipeOptions: 'limit: 2' },
	{ data: 2000000.12345, pipe: 'number0', pipeOptions: 'limit: 2' },
];

출처

http:// https://stackoverflow.com/questions/36564976/dynamic-pipe-in-angular-2/46910713#46910713

이름 정의 (엑셀: 수식 > 이름관리자)

HSSFWorkbook wb = new HSSFWorkbook();

//참조 sheet 생성
HSSFSheet sheet = workbook.createSheet("감면");
//참조 데이터 생성
...

//userName 이라는 이름 정의
String name = "userName";

HSSFName namedCell = wb.createName();
namedCell.setNameName(name);
namedCell.setRefersToFormula("감면!$A$11:$A$35");   //감면 sheet 해당 범위에 참조 데이터 존재
//또는
namedCell.setRefersToFormula("'감면'!$A$11:$A$35");

//이미 이름이 정의되어 있는 엑셀인 경우
FileInputStream file = new FileInputStream(new File("already.xlsx"));
HSSFWorkbook workbook = new HSSFWorkbook(file);
HSSFName namedCell = wb.getName(name);
...

 

이름 적용

//String name = "userName";
HSSFSheet sheet = workbook.createSheet("Test");
...
//CellRangeAddressList(시작 row index, 종료 row index, 시작 column index, 종료 column index);
//범위 설정 (1 ~ 10행, B열)
CellRangeAddressList addressList = new CellRangeAddressList(0, 9, 1, 1);

//데이터 유효성 검사 추가(엑셀: 데이터 > 데이터 유효성 검사)
DVConstraint dvConstraint = DVConstraint.createFormulaListConstraint(name);
DataValidation dataValidation = new HSSFDataValidation(addressList, dvConstraint);

dataValidation.setEmptyCellAllowed(false);      //공백무시
dataValidation.setShowPromptBox(false);         //설명 미표시
dataValidation.setSuppressDropDownArrow(false); //셀 선택 시 드롭다운 목록 미표시

sheet.addValidationData(dataValidation);

출처

https://kkani.tistory.com/entry/poi-HSSF-%EC%82%AC%EC%9A%A9%EC%8B%9C-Excel-DropDownListBox-%EC%82%AC%EC%9A%A9-%EC%98%88%EC%A0%9C

'Java' 카테고리의 다른 글

List 다중 컬럼 정렬  (0) 2021.05.21
날짜 관련 유틸리티  (0) 2018.10.23
JDK 8 인스톨 없이 설치하기  (0) 2018.10.20
사진 이미지 크기 변경 후 Base64 문자열 변환  (0) 2018.04.26
POI, Excel 셀 생성  (0) 2015.06.30

.html

tr 태그는 포커스가 가능한 태그가 아니기 때문에 tabindex 속성 필요

...
<tr #trOrder tabindex="0">
    <td>...</td>
</tr>
...

.ts

import { ElementRef, QueryList, ViewChildren } from '@angular/core';
...
@ViewChildren('trOrder') trList: QueryList<ElementRef>;
...
setFocus(index) {
    this.trList.get(index).nativeElement.focus();
}