# PivotGrid 내보내기

## Content

**PivotGrid**는 **FlexGrid**를 확장하므로, 일반 **FlexGrid**처럼 XLSX와 PDF로 내보낼 수 있습니다:

## Excel(XLSX)로 내보내기

엑셀로 내보내는 것은 간단합니다. **wijmo.grid.xlsx** 모듈을 사용하여 **FlexGridXlsxConverter.save()** 함수를 통해 이 작업을 수행할 수 있습니다. 그러나 이 과정에서는 **wijmo.xlsx** 모듈도 필요합니다.

> wijmo.xlsx 는 jszip에 의존합니다. 해당 스크립트도 프로젝트에 포함되어 있어야 합니다.

```javascript
// Excel export
import * as wjGridXlsx from '@mescius/wijmo.grid.xlsx';

// PDF Export
import * as wjPdf from '@mescius/wijmo.pdf';
import * as wjGridPdf from '@mescius/wijmo.grid.pdf';

document.getElementById('xlsx').addEventListener('click', function() {

    // create book with current view
    var book = wjGridXlsx.FlexGridXlsxConverter.save(pivotGrid, {
        includeColumnHeaders: true,
        includeRowHeaders: true
    );
    book.sheets[0].name = 'PivotGrid';
    
    // save the book
    book.save('PivotGrid.xlsx');
});
```

## PDF로 내보내기

PDF로 내보내려면 **wijmo.grid.pdf** 모듈을 사용하시면 됩니다. 엑셀 내보내기와 유사하게, **wijmo.grid.pdf** 모듈은 **wijmo.pdf**에 의존합니다. **FlexGridPdfConverter** 클래스에는 grid 인스턴스, 파일 이름, 문서 설정을 구성하는 JSON 객체를 받는 **export()** 함수가 있습니다.

다음은 예제입니다.

```javascript
document.getElementById('pdf').addEventListener('click', function() {
    wjGridPdf.FlexGridPdfConverter.export(pivotGrid, 'PivotGrid.pdf', {
        maxPages: 10,
        scaleMode: wjGridPdf.ScaleMode.PageWidth,
        documentOptions: {
            compress: true,
            header: { 
                declarative: { text: '\t&[Page] of &[Pages]' }
            },
            footer: { 
                declarative: { text: '\t&[Page] of &[Pages]' }
            },
            info: { author: 'MESCIUS', title: 'PivotGrid' }
        },
    	styles: {
            cellStyle: {
                backgroundColor: '#ffffff',
                borderColor: '#c6c6c6'
            },
	    	altCellStyle: { backgroundColor: '#f9f9f9' },
	    	groupCellStyle: { backgroundColor: '#dddddd' },
    		headerCellStyle: { backgroundColor: '#eaeaea' }
        }
    });
});
```

## PDF 내보내기에 컨텐츠 추가하기

경우에 따라 내보낸 PDF 문서에 추가 콘텐츠를 추가하고 싶을 수 있는데 **wijmo.pdf** 모듈을 사용하면 이를 구현할 수 있습니다. **PdfDocument**를 생성하고 \*\*draw()\*\*와 같은 함수를 사용하여 추가 콘텐츠를 추가할 수 있습니다.
예제:

```javascript
document.getElementById('pdfdoc').addEventListener('click', function() {

    // create the document
    var doc = new wjPdf.PdfDocument({
        compress: true, 
        header: { declarative: { text: '\t&[Page]\\&[Pages]' } },
        ended: function (sender, args) {
            wjPdf.saveBlob(args.blob, 'PivotGridDoc.pdf');
        }
    });
    
    // add some content
    doc.drawText('This is a PivotGrid control:');

    // add the grid (400pt wide)
    wjGridPdf.FlexGridPdfConverter.draw(pivotGrid, doc, 400);
    
    // finish document
		doc.end();
	});
```

[PivotGrid 내보내기 데모](https://demo.mescius.co.kr/wijmo/learn-wijmo/OLAP/PivotGrid/Export/Excel,PDF,CSV/purejs)를 참고해주세요.