Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/399.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 为什么在使用POI编写大型电子表格时超链接停止工作?_Java_Apache Poi - Fatal编程技术网

Java 为什么在使用POI编写大型电子表格时超链接停止工作?

Java 为什么在使用POI编写大型电子表格时超链接停止工作?,java,apache-poi,Java,Apache Poi,我正在使用POI 3.9和SXSSF创建电子表格。当有少量行时,创建超链接是有效的。但是,随着大小的增加,处理时间大大增加,链接无法工作。它适用于700行,但不适用于70000行。尝试打开文件时,出现以下错误: Excel在“out.xlsx”中发现不可读的内容。是否要恢复此工作簿的内容?如果您信任此工作簿的来源,请单击“是” public static void main(String[] args) throws Throwable { Workbook wb = new S

我正在使用POI 3.9和SXSSF创建电子表格。当有少量行时,创建超链接是有效的。但是,随着大小的增加,处理时间大大增加,链接无法工作。它适用于700行,但不适用于70000行。尝试打开文件时,出现以下错误:

Excel在“out.xlsx”中发现不可读的内容。是否要恢复此工作簿的内容?如果您信任此工作簿的来源,请单击“是”

    public static void main(String[] args) throws Throwable {
    Workbook wb = new SXSSFWorkbook(100); // keep 100 rows in memory, exceeding rows will be flushed to disk
    Sheet sh = wb.createSheet();
    for(int rownum = 0; rownum < 70000; rownum++){
        Row row = sh.createRow(rownum);
        for(int cellnum = 0; cellnum < 10; cellnum++){
            Cell cell = row.createCell(cellnum);
            String address = new CellReference(cell).formatAsString();
            cell.setCellValue(address);
            if (address.contains("A"))
                setHyperlink(cell, address);
        }
    }

    FileOutputStream out = new FileOutputStream("C:/temp/sxssf.xlsx");
    wb.write(out);
    out.close();
}

protected static void setHyperlink(Cell cell, String address) {
    Workbook workbook = cell.getSheet().getWorkbook();
    Hyperlink hyperlink = workbook.getCreationHelper()
            .createHyperlink(Hyperlink.LINK_URL);
    String encoded = null;
    try {
        encoded = URLEncoder.encode(address, "UTF-8");
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    hyperlink.setAddress(encoded);
    cell.setHyperlink(hyperlink);
}
publicstaticvoidmain(String[]args)抛出Throwable{
工作簿wb=new SXSSFWorkbook(100);//在内存中保留100行,超过的行将刷新到磁盘
Sheet sh=wb.createSheet();
对于(int-rownum=0;rownum<70000;rownum++){
Row Row=sh.createRow(rownum);
对于(int-cellnum=0;cellnum<10;cellnum++){
Cell Cell=row.createCell(cellnum);
字符串地址=新单元格引用(cell.formataString();
cell.setCellValue(地址);
如果(地址包含(“A”))
设置超链接(单元格、地址);
}
}
FileOutputStream out=新的FileOutputStream(“C:/temp/sxssf.xlsx”);
wb.写(出);
out.close();
}
受保护的静态void setHyperlink(单元格、字符串地址){
工作簿=cell.getSheet().get工作簿();
Hyperlink Hyperlink=工作簿.getCreationHelper()
.createHyperlink(Hyperlink.LINK\uURL);
字符串编码=空;
试一试{
encoded=urlcoder.encode(地址,“UTF-8”);
}捕获(不支持的编码异常e){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
超级链接。设置地址(编码);
cell.setHyperlink(超链接);
}

看起来excel上的超链接最大数量限制为65530。