我想用csv格式编写一些数据并使用Excel打开它.Below是我试图实现它的代码,
public void writeOutput(String fileName,Map<String){
try {
String jsonData="{"adjustments":[{"adjustmentType":"RENEWAL_OPTION_AMORTIZING_RENEWAL","rate":0.0400},{"adjustmentType":"AMORTIZATION_TERM_LESS_THAN_25_YEARS","rate":-0.0800}],"errorTypes":[],"premiumTaxs":[{"taxType":"STATE_TAX","taxPercent":1.3,"taxAmount":null,"taxJurisdictionName":"Florida"}],"renewalPremiums":[{"rate":0.8100,"rateDurationMonths":168,"sequence":1}],"totalInitialRate":0.8100,"rateName":"Standard National Monthly Non Refundable BPMI Rates","rateCardId":"NABM_NR","ratingInfoBaseRate":0.8500,"optimumPricing":false,"miPricingVO":null,"addressMatchCode":null}";
String dataID = "MyNewDataID";
OutputStreamWriter writer = new OutputStreamWriter(
new FileOutputStream(System.getProperty("user.dir")
+ "\\test\\" + fileName + ".csv", true),"UTF-8");
BufferedWriter fbw = new BufferedWriter(writer);
fbw.write(dataID + "," + jsonData);
fbw.newLine();
fbw.close();
}catch (Exception e) {
System.out.println(e.getCause());
System.out.println(e.getStackTrace());
}
}
当执行上面的代码并且当我使用Excel打开csv文件时,所有数据(以逗号分隔)都显示在不同的单元格中 - 我期望单元格A1中的String dataID和B1中的jsonData。请帮助我 - 我该如何做到这一点。
注意:我尝试使用不同的分隔符,但它不起作用。
谢谢, 麦克