Untitled

mail@pastecode.io avatar
unknown
java
a month ago
3.0 kB
4
Indexable
Never
public static byte[] generatePaymentReportDownloadExcel(List<PaymentReportDto> paymentReportDtoList) throws IOException {
        try(Workbook workbook = new XSSFWorkbook()){
            Sheet sheet = workbook.createSheet();
            Row headerRow = sheet.createRow(0);
            String[] headers = {"Agent Ref Id","Retailer Phone Number","Amount","Created Ts","Order Item Ids","Order Type","Brand Name","Payment Id","Payment Mode","Payment Status","Payment Type","Quotes Id","Request Date","Response Date","Provider Payment Id","Transaction Id","Transaction Type","Updated Ts","Parent Order Id","Provider Reference Id"};
            for(int i=0;i<headers.length;i++){
                headerRow.createCell(i).setCellValue(headers[i]);
            }
            int rowIndex = 1;

            for(PaymentReportDto paymentReportDto:paymentReportDtoList){
                Row dataRow = sheet.createRow(rowIndex++);
                dataRow.createCell(0).setCellValue(paymentReportDto.getAgentRefId());
                dataRow.createCell(1).setCellValue(paymentReportDto.getRetailerPhoneNumber());
                dataRow.createCell(2).setCellValue(paymentReportDto.getAmount());
                dataRow.createCell(3).setCellValue(paymentReportDto.getCreatedTs());
                dataRow.createCell(4).setCellValue(paymentReportDto.getOrderItemIds());
                dataRow.createCell(5).setCellValue(paymentReportDto.getOrderType());
                dataRow.createCell(6).setCellValue(paymentReportDto.getBrandName());
                dataRow.createCell(7).setCellValue(paymentReportDto.getPaymentId());
                dataRow.createCell(8).setCellValue(paymentReportDto.getPaymentMode());
                dataRow.createCell(9).setCellValue(paymentReportDto.getPaymentStatus());
                dataRow.createCell(10).setCellValue(paymentReportDto.getPaymentType());
                dataRow.createCell(11).setCellValue(paymentReportDto.getQuotesIds());
                dataRow.createCell(12).setCellValue(paymentReportDto.getRequestDate());
                dataRow.createCell(13).setCellValue(paymentReportDto.getResponseDate());
                dataRow.createCell(14).setCellValue(paymentReportDto.getProviderPaymentId());
                dataRow.createCell(15).setCellValue(paymentReportDto.getTransactionId());
                dataRow.createCell(16).setCellValue(paymentReportDto.getPaymentType());
                dataRow.createCell(17).setCellValue(paymentReportDto.getUpdatedTs());
                dataRow.createCell(18).setCellValue(paymentReportDto.getParentOrderId());
                dataRow.createCell(19).setCellValue(paymentReportDto.getProviderReferenceId());
            }
            ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
            workbook.write(outputStream);
            return  outputStream.toByteArray();
        } catch (IOException e){
            e.printStackTrace();
            throw new RuntimeException("Failed to generate Excel file.");
        }
    }
Leave a Comment