ReportViewer
양식과 데이터를 이용해 리포트 객체를 만듭니다. 리포트 미리보기를 참고하세요.
생성자
const viewer = new RealReport.ReportViewer (
container: string | HTMLDivElement,
reportForm?: ReportForm,
dataSet?: ReportDataSet,
options?: ReportOptions
)인자
| 이름 | 타입 | 필수여부 | 설명 |
|---|---|---|---|
| container | string | HTMLDivElement | yes | RealReport가 렌더링될 컨테이너, div 엘리멘트 또는 id 문자열 |
| reportForm | ReportForm | no | RealReport 양식 객체 |
| dataSet | ReportDataSet | no | RealReport 데이터 객체 |
| options | ReportOptions | no | 옵션 |
속성
| 이름 | 타입 | Read & Write |
|---|---|---|
| zoom | number | Read & Write |
| pageCount | number | Read |
| page | number | Read & Write |
| reportForm | any | Read & Write |
| dataSet | any | Read & Write |
| reportHtml | string | Read |
| languages | string[] | Read |
zoom
- type:
number - Read & Write
- 리포트 미리보기 컨테이너의 확대/축소 비율
- 예:
0.5= 50% 로 축소
pageCount
- type:
number - Read
- 미리보기 전체 페이지수를 가져옵니다.
page
- type:
number - Read & Write
- 미리보기 현재 페이지를 가져오거나 지정합니다.
reportForm
- type:
Record<string, any> - Read & Write
- 리포트 출력을 위한
JSON형식의 양식 코드
데이터 예시
{
"page": {
"pageHeader": {
"items": [
{
"type": "text",
"text": "리포트 제목",
"styles": {
"fontSize": "25px",
"fontWeight": "bold"
}
}
]
},
"body": {
"items": [
{
"type": "text",
"text": "RealReport는 Javascript를 이용해 간단하게 리포트를 출력 할 수 있습니다.",
"height": "100px"
}
]
}
}
}dataSet
- type:
any - Read & Write
- 리포트 양식에 사용된 데이터들을 가져오거나 지정합니다.
reportHtml
- type:
any - Read
- 미리보기 페이지들을 html 코드로 가져옵니다.
languages
- type:
string[] - Read
- 다국어 설정에서 추가한 언어 목록을 가져옵니다.
함수
| 이름 | 설명 |
|---|---|
| open | 리포트 열기 |
| preview | 미리보기 실행 |
| 보고서 출력 | |
| first | 첫 번째 페이지로 이동 |
| prev | 이전 페이지로 이동 |
| next | 다음 페이지로 이동 |
| last | 마지막 페이지로 이동 |
| zoomIn | 확대 |
| zoomOut | 축소 |
open
리포트 폼 데이터를 반환하는 API 주소를 제공하거나, JSON 형태의 리포트 폼 데이터를 전달받아 이를 미리보기합니다.
ReportViewer.open(
source: string | ReportForm,
options?: PreviewOptions & { preview?: boolean }
): void;// API 주소 전달
viewer.open('http://report.json');
// 직접 JSON 데이터 전달
viewer.open({
report: {
// ...
},
page: {
// ...
},
//...
});
// open 사용과 동시에 미리보기 하지 않을 경우
viewer.open('http://report.json', {
preview: false,
});
// preview 옵션 사용
viewer.open('http://report.json', {
paging: true,
language: 'ko',
});preview
reportForm의 양식에 dataSet의 데이터를 매핑하여 완성된 리포트를 컨테이너에 미리보기 합니다. 미리보기 함수인 preview()에는 PreviewOptions 타입의 인자를 넘겨줍니다.
// 동기 방식으로 미리보기
viewer.preview();
// 비동기 방식으로 미리보기
viewer.preview({ async: true, pageMark: false, noscroll: true });미리보기가 되어있는 컨테이너를 인쇄합니다.
미리보기가 되어있지 않은 경우 ReportViewer 객체에 설정되어있는
reportForm dataSet 정보로 인쇄를 진행합니다.
viewer.print();getHtml
미리보기 페이지들을 HTML 형식의 코드로 가져옵니다. 이 함수의 결과는 reportHtml 속성의 값과 동일한 결과를 돌려줍니다.
const previewHtml = viewer.getHtml();first
미리보기에서 맨 처음 페이지로 이동
viewer.first();prev
미리보기에서 이전 페이지로 이동
viewer.prev();next
미리보기에서 다음 페이지로 이동
viewer.next();last
미리보기에서 마지막 페이지로 이동
viewer.last();zoomIn
미리보기 페이지를 scale의 배율로 확대
- scale: 확대 비율, 기본값은 0.1 (10%)
ReportViewer.zoomIn(scale: number): void;viewer.zoomIn();
viewer.zoomIn(0.2);zoomOut
미리보기 페이지를 scale의 배율로 축소
- scale: 축소 비율, 기본값은 0.1 (10%)
ReportViewer.zoomOut(scale: number): void;viewer.zoomOut();
viewer.zoomOut(0.3);fitToHeight
미리보기 페이지를 컨테이너의 높이에 맞게 조정
ReportViewer.fitToHeight(): void;viewer.fitToHeight();fitToPage
미리보기 한 페이지를 컨테이너의 높이와 너비에 맞게 조정
ReportViewer.fitToPage(): void;viewer.fitToPage();fitToWidth
미리보기 페이지를 컨테이너의 너비에 맞게 조정
ReportViewer.fitToWidth(): void;viewer.fitToWidth();exportPdf
미리보기 페이지들을 PDF 형식의 파일로 내보내기 합니다.
- options: PdfExportOptions
ReportViewer.exportPdf(options: PdfExportOptions): Promise<void>;2가지 이상의 폰트를 PDF에 적용하는 기능은 v1.10.9 버전부터 지원합니다.
const NotoSansbase64Fonts = await Promise.all([
base64convert('../fonts/NotoSans.otf'),
base64convert('../fonts/NotoSansBold.otf'),
]);
const NanumGothicbase64Fonts = await Promise.all([
base64convert('../fonts/NanumGothic.otf'),
base64convert('../fonts/NanumGothicBold.otf'),
]);
const fonts = [
{
name: 'NotoSans',
content: NotoSansbase64Fonts[0],
style: 'normal',
weight: 'normal',
},
{
name: 'NotoSans',
content: NotoSansbase64Fonts[1],
style: 'normal',
weight: 'bold',
},
{
name: 'NanumGothic',
content: NanumGothicbase64Fonts[0],
style: 'normal',
weight: 'normal',
},
{
name: 'NanumGothic',
content: NanumGothicbase64Fonts[1],
style: 'normal',
weight: 'bold',
},
];
viewer.exportPdf({
fonts,
filename: 'sample-pdf-filename.pdf',
preview: false,
});시트 리포트에서는 추후 지원 될 예정입니다.
exportPdfBlob
미리보기 페이지들을 PDF로 변환 후 Blob 형식의 데이터로 반환합니다.
- options: PDFExportBlobOptions
ReportViewer.exportPdfBlob(options: PDFExportBlobOptions): Promise<Blob>;2가지 이상의 폰트를 PDF에 적용하는 기능은 v1.10.9 버전부터 지원합니다.
const NotoSansbase64Fonts = await Promise.all([
base64convert('../fonts/NotoSans.otf'),
base64convert('../fonts/NotoSansBold.otf'),
]);
const NanumGothicbase64Fonts = await Promise.all([
base64convert('../fonts/NanumGothic.otf'),
base64convert('../fonts/NanumGothicBold.otf'),
]);
const fonts = [
{
name: 'NotoSans',
content: NotoSansbase64Fonts[0],
style: 'normal',
weight: 'normal',
},
{
name: 'NotoSans',
content: NotoSansbase64Fonts[1],
style: 'normal',
weight: 'bold',
},
{
name: 'NanumGothic',
content: NanumGothicbase64Fonts[0],
style: 'normal',
weight: 'normal',
},
{
name: 'NanumGothic',
content: NanumGothicbase64Fonts[1],
style: 'normal',
weight: 'bold',
},
];
viewer.exportPdfBlob({
fonts: fonts,
});시트 리포트에서는 추후 지원 될 예정입니다.
exportImage
미리보기 페이지들을 png, jpeg, jpg, gif, tif, tiff 형식의 이미지 파일로 내보내기 합니다.
- imageOptions: ImageExportOptions
ReportViewer.exportImage(imageOptions?: ImageExportOptions): Promise<void>;viewer.exportImage({ type: 'png' });
viewer.exportImage({ type: 'png', fileName: 'sample-report.png' });exportImageBlob
미리보기 페이지들을 png, jpeg, jpg, gif, tif, tiff 형식의 이미지로 변환 후 Blob 데이터를 반환합니다.
- imageOptions: ImageExportBlobOptions
ReportViewer.exportImageBlob(imageOptions?: ImageExportBlobOptions): Promise<Blob>;viewer
.exportImageBlob({
type: 'png',
})
.then((blob) => {
console.log(blob);
});exportDocument
미리보기 페이지들을 hwp, docx, pptx, excel 형식의 파일로 내보내기 합니다.
- documentOptions: DocumentExportOptions
ReportViewer.exportDocument(documentOptions?: DocExportOptions): Promise<void>;viewer.exportDocument({ type: 'hwp' });일반 리포트, 이메일 리포트에서는 hwp, docx, pptx 형식을 지원합니다.
시트 리포트에서는 excel 형식을 지원합니다.
exportDocumentBlob
미리보기 페이지들을 hwp, docx, pptx, excel 형식의 문서로 변환 후 Blob 데이터를 반환합니다.
- documentOptions: DocumentExportBlobOptions
ReportViewer.exportDocumentBlob(documentOptions?: DocExportOptions): Promise<Blob>;viewer
.exportDocumentBlob({
type: 'hwp',
})
.then((blob) => {
console.log(blob);
});일반 리포트, 이메일 리포트에서는 hwp, docx, pptx 형식을 지원합니다.
시트 리포트에서는 excel 형식을 지원합니다.
exportDocumentsFromData
데이터를 기준으로 양식을 여러개의 hwp, docx 형식의 문서로 변환후 압축된 하나의 파일로 다운로드합니다.
- documentOptions: DocumentsExportFromDataOptions
ReportViewer.exportDocumentsFromData(
documentOptions: DocumentsExportFromDataOptions
): Promise<void>;viewer.exportDocumentsFromData({
fileName: 'sample',
reportForm: ReportViewer.reportForm,
dataSets: [
{
master: {
type: 'band',
values: [{ key: '1', name: '홍길동' }],
},
detail: {
type: 'band',
values: [
{ key: '1', item: '사과', price: 1000 },
{ key: '1', item: '바나나', price: 2000 },
],
},
},
{
master: {
type: 'band',
values: [{ key: '2', name: '김철수' }],
},
detail: {
type: 'band',
values: [
{ key: '2', item: '홍시', price: 4000 },
],
},
},
],
type: 'hwp',
});