Excel / CSV - 将键值转换为csv

时间:2016-03-16 12:10:51

标签: excel csv export-to-csv

我在Excel中有一列有以下记录:

  

{Property1 =选择加入,Property2 =选择退出,Property3 =选择退出}
  {Property1 =选择加入,Property2 =选择退出,Property3 =选择退出}
  {Property1 = opt-in,Property2 = opt-in,Property3 = opt-in}

有没有办法将其转换为csv或三个单独的列

  

Property1,Properyty2,Property3
  选择退出,选择退出,选择加入   选择加入,选择加入,选择加入   选择退出,选择退出,选择加入

2 个答案:

答案 0 :(得分:2)

为了示范,请将列标题标签放入右侧的一些未使用的单元格中,并在第一个标准公式的正下方使用此标准公式。

=TRIM(LEFT(SUBSTITUTE(SUBSTITUTE(REPLACE($A1,1,SEARCH(C$1,$A1)+LEN(C$1),""),"}",","),",",REPT(" ",LEN($A1))), LEN($A1)))

向右和向下填充。

excel_split_json

答案 1 :(得分:1)

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;

public class ExcelReader {

    public void excel(String input) {
        // TODO Auto-generated method stub
        try {

            String S = "C:/Users/DELL/Desktop/workspace_luna/ecel dataload/"
                    + input;
            String S1 = "C:/Users/DELL/Desktop/workspace_luna/ecel dataload/"
                    + input.substring(0, input.indexOf('.')) + ".xls";
            File f = new File(S);

            @SuppressWarnings("resource")
            OutputStream os = (OutputStream) new FileOutputStream(f);

            String encoding = "UTF8";
            OutputStreamWriter osw = new OutputStreamWriter(os, encoding);

            BufferedWriter bw = new BufferedWriter(osw);

            File f2 = new File(S1);

            Workbook w = Workbook.getWorkbook(f2);

            for (int sheet = 0; sheet < w.getNumberOfSheets(); sheet++) {
                Sheet s = w.getSheet(sheet);



                Cell[] row = null;


                for (int i = 0; i < s.getRows(); i++) {


                    row = s.getRow(i);

                    if (row.length > 0) {

                        bw.write(row[0].getContents());
                        for (int j = 1; j < row.length; j++) {
                            bw.write("||");

                            bw.write(row[j].getContents());
                        }
                    }

                    bw.newLine();
                }
            }
            bw.flush();
            bw.close();
        } catch (UnsupportedEncodingException e) {
            System.err.println(e.toString());
        } catch (IOException e) {
            System.err.println(e.toString());
        } catch (Exception e) {
            System.err.println(e.toString());
        }
    }

}