Excel去除重复数据

【问题】

I have an excel file with following data (dummy)

I am reading this file and storing the result in a Set so that duplicates can be removed and I only get unique list. Below is the what I tried:

FileInputStream file = new FileInputStream(new File(“C:\\Users\\harshita.sethi\\Desktop\\ALLOT010T_Input_Keywords.xls”));

HSSFWorkbook w = new HSSFWorkbook(file);

HSSFSheet sheet = w.getSheetAt(0);

int totalrows = sheet.getLastRowNum();

System.out.println(sheet.getRow(0).getPhysicalNumberOfCells());

String[][] data = new String[totalrows+1][sheet.getRow(0).getPhysicalNumberOfCells()];

Set<String[]> keySet = new HashSet<>();

for (int i = 0; i <= totalrows; i++) {

    for (int j = 0; j < sheet.getRow(0).getPhysicalNumberOfCells(); j++) {

        HSSFCell cell = sheet.getRow(i).getCell(j);

        // writing keywords from excel into a hashmap

        data[i][j]=cell.getRichStringCellValue().getString();

    }

    keySet.add(data[i]);

}

Iterator<String[]> iterator = keySet.iterator();

System.out.println(“Output Set is as below”);

while(iterator.hasNext()){

    String[] next = iterator.next();

    System.out.println(next[0] + “\t”+ next[1] +"\t"+next[2]);

}

The output of this code is as shown below

Output Set is as below

d   b    c

e   b    c

a   b    c

d   b    c

d   b    c

g   b    c

e   b    c

f   b    c

d   b    c

The set didn’t remove the duplicate. What other approach can I used to eliminate these duplicates. Any column can have different or same value. So I cannot remove duplicates based on a particular column

I want the entire row to be unique.

PS: This data is just dummmy. In real scenario I have more columns and any column value can be different which will make the row unique.

【回答】

这是个典型的去重动作,用 SPL 比 Java 要简单得多。

A
1= file(“d:\\data.xlsx”).importxls()
2= A1.group@1(#1,#2,#3)

这段代码可以方便地集成进 Java,参考【Java 如何调用 SPL 脚本​】

执行上述脚本语句即获取结果:

A1:读取 Excel 文件;

A2:获取数据集合并去掉重复数据;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值