清洁Excel表(替换文本)

时间:2018-08-13 10:35:57

标签: java excel apache apache-poi xls

我有一个程序,可以从网站上抓取表格并将其放入xls表中。但是,大多数数据必须是数字,某些单元格可能包含257,2x,ȻC,KL1等。我无法找出一种简单的方法用“”替换多余的字符,因为显然Apache POI并没有允许这个吗? 那么,您如何建议我这样做? 预先感谢。

int kansio = 1;
    Document doc3 = Jsoup.connect("https://ravit.is.fi/paivanravit/").get();
    Element table2 = doc3.select("table").get(5);
    Elements links2 = table2.select("a[href]"); // a with href
    for (Element link3 : links2) {
        int asd1 = 1;
        new File("C:\\sheets\\lahto-" + kansio).mkdir();
        Document doc2 = Jsoup.connect("https://ravit.is.fi/paivanravit/" + link3.attr("href")).get();
        Elements links = doc2.select("[href*=hevoset]");
        for (Element link2 : links) {

            try {

                Document doc = Jsoup.connect("https://ravit.is.fi/" + link2.attr("href")).get();
                String filename = "C:\\sheets\\lahto-" + kansio + "/" + asd1 + ".xls";
                HSSFWorkbook workbook = new HSSFWorkbook();
                HSSFSheet sheet = workbook.createSheet("FirstSheet");
                for (Element asd : doc.select("#valittu_public > table > tbody > tr > td > form > table > tbody")) {
                    int rownum = 0;
                    for (Element row : asd.select("tr")) {
                        HSSFRow exlrow = sheet.createRow(rownum++);
                        int cellnum = 0;
                        for (Element tds : row.select("td")) {
                            StringUtils.isNumeric("");
                            HSSFCell cell = exlrow.createCell(cellnum++);
                            cell.setCellValue(tds.text());    
                        }
                    }
                }
            sheet.shiftRows(2 ,500 ,-1);
            int ttt = 1;
            while (ttt < 500) {
                sheet.shiftRows(ttt ,500 ,-1);
                ttt++;
            }
        FileOutputStream fileOut = new FileOutputStream(filename);
        workbook.write(fileOut);
        fileOut.close();
        workbook.close();
        asd1++;

        } catch ( Exception ex ) {
        System.out.println(ex);
        }
        }
        kansio++;
        }

0 个答案:

没有答案