Search in sources :

Example 1 with ExcelFile

use of org.devgateway.ocds.persistence.mongo.excel.ExcelFile in project ocvn by devgateway.

the class ExcelGenerator method getExcelDownload.

/**
     * Method that returns a byte array with excel export.
     *
     * @param filter
     * @return
     * @throws IOException
     */
@Cacheable
public byte[] getExcelDownload(final YearFilterPagingRequest filter) throws IOException {
    PageRequest pageRequest = new PageRequest(filter.getPageNumber(), filter.getPageSize(), Sort.Direction.ASC, "id");
    List<Release> releases = mongoTemplate.find(query(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE)).with(pageRequest), Release.class);
    ExcelFile releaseExcelFile = new ReleaseExportFile(releases);
    Workbook workbook = releaseExcelFile.createWorkbook();
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    workbook.write(baos);
    byte[] bytes = baos.toByteArray();
    return bytes;
}
Also used : ReleaseExportFile(org.devgateway.ocds.persistence.mongo.excel.ReleaseExportFile) PageRequest(org.springframework.data.domain.PageRequest) ExcelFile(org.devgateway.ocds.persistence.mongo.excel.ExcelFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Release(org.devgateway.ocds.persistence.mongo.Release) Workbook(org.apache.poi.ss.usermodel.Workbook) Cacheable(org.springframework.cache.annotation.Cacheable)

Aggregations

ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1 Release (org.devgateway.ocds.persistence.mongo.Release)1 ExcelFile (org.devgateway.ocds.persistence.mongo.excel.ExcelFile)1 ReleaseExportFile (org.devgateway.ocds.persistence.mongo.excel.ReleaseExportFile)1 Cacheable (org.springframework.cache.annotation.Cacheable)1 PageRequest (org.springframework.data.domain.PageRequest)1