csv charset fix

master
yixian 5 years ago
parent 3b6db8dff5
commit 4c975e8485

@ -43,6 +43,7 @@ import net.sf.jasperreports.engine.export.ooxml.JRXlsxExporter;
import net.sf.jasperreports.export.*;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.QuoteMode;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.lang3.StringUtils;
@ -1542,11 +1543,13 @@ public class TradeLogServiceImpl implements TradeLogService {
String[] title = {"order Id", "Client Order Id", "Transaction Time", "Channel", "Gateway", "Exchange Rate", "Transaction Type", "Currency",
"Input Amount", "Total Amount", "Clearing Amount", "Surcharge Rate", "Settle Amount", "Surcharge", "GST", "Remark", "Dev No", "Company Name", "Short Name", "Settlement Date"};
CSVFormat format = CSVFormat.DEFAULT.withFirstRecordAsHeader().withHeader(title);
response.setCharacterEncoding("UTF-8");
response.setContentType("application/octet-stream;");
response.addHeader("Content-Disposition",
"attachment; filename=" + "Merchant_Settlement_Info_" + begin + "_" + end + ".csv");
try (PrintWriter writer = response.getWriter();
CSVPrinter printer = new CSVPrinter(writer, format)) {
printer.printRecord((Object[]) title);
JSONObject clearDetailTotal = transactionMapper.getClearDetailTotal(params);

@ -0,0 +1,29 @@
package au.com.royalpay.payment.manage.valid;
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVPrinter;
import org.apache.commons.csv.QuoteMode;
import org.junit.Test;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.StandardCharsets;
/**
* Create by davep at 2019-12-24 15:15
*/
public class CSVTest {
@Test
public void test() throws IOException {
File file = File.createTempFile("csvtest",".csv");
FileWriter writer = new FileWriter(file);
CSVFormat format = CSVFormat.DEFAULT.withFirstRecordAsHeader().withHeader("title", "标题1", "abc");//.withQuoteMode(QuoteMode.ALL_NON_NULL);
CSVPrinter printer = new CSVPrinter(writer, format);
printer.printRecord("test", "订单1234", "hello");
writer.flush();
System.out.println(file.getAbsolutePath());
}
}
Loading…
Cancel
Save