columns are inversed while exporting to CSV in Angular

时间:2015-06-30 13:26:39

标签: javascript java angularjs export-to-csv

I have implemented the export to CSV with java like this:

CsvMapper mapper = new CsvMapper();
    CsvSchema schema = mapper.schemaFor(OrderCsv.class).withHeader();
    ObjectWriter writer = mapper.writer(schema.withColumnSeparator(';').withLineSeparator("\n"));
    response.setContentType("application/CSV");
    response.setHeader("Content-Disposition", "attachment; filename=\"orders.csv\"");
    OutputStream outputStream;
    try {
        outputStream = response.getOutputStream();
        BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(outputStream, 1024);
        OutputStreamWriter writerOutputStream = new OutputStreamWriter(bufferedOutputStream, "ISO8859_1");

        List<Order> orders = orderDetailsRepository.listOrders(CustomPeriod.parseInput(startDate, endDate), status, null, null, sort, restaurants);

        List<OrderCsv> orderList = new ArrayList<OrderCsv>();
        for (Order order : orders) {
            orderList.add(new OrderCsv(order));
        }
        writer.writeValue(writerOutputStream, orderList);

    } catch (Exception e) {
        throw new ExportCsvException();
    }

This is the AngularJs code:

      orderDetails.export = function () {
      window.open(configuration.apiEndpoint + '/orderdetails/csv?' +
     'startDate='+ $scope.$parent.filters.startdate +
     '&endDate=' + $scope.$parent.filters.enddate +
     '&status=' + orderDetails.selectedStatus +
     '&sort=' + orderDetails.sort[0] +
     '&restaurants=' + $scope.$parent.filters.restaurantIds,
      '_blank', '');
        };

When I export a table in CSV, the columns are inversed.I don't know what it is causing columns to be inversed.Do you have any ideas on how I can resolve this issue? Thanks in advance

  This is my new code after resolving the issue:
                              CsvSchema schema = CsvSchema.builder()
                 .addColumn("orderNumber")
                 .addColumn("restaurantReference")
                 .addColumn("customerReference")
                 .addColumn("totalAmount")
                 .addColumn("orderStatus")
                 .addColumn("Date commande")
                 .addColumn("orderDate")
                 .addColumn("withdrawalPoint")
                 .addColumn("paymentType")
                 .addColumn("offerType")
                 .addColumn("offerReference")
                  .build();
                  ObjectWriter writer=mapper.writer(schema.withColumnSeparator(';').withLineSeparator("\n"));
    final String[] header = new String[] { "Numéro commande",   "Ref   restaurant", "Ref client", "Montant total",
            "statut", "Date commande", "Point de retrait", "Type de paiement", "Type d'offre", "Référence de l'offre" }

0 个答案:

没有答案