将.xltx转换为.xlsx

时间:2015-10-13 06:14:20

标签: java excel apache-poi

我正在阅读.xltx,我想导出.xlsx。

protected static final String ruta = ResourcesPathEnum.ROOT.getId() + "plantillas" + File.separator;    
public static final String CONTENT_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";

protected abstract Workbook xlsx() throws FileNotFoundException, IOException;   
/**
 * Genera excel
 * 
 * @return  InputStream
 */
public InputStream getFile() {
    try { 
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            xlsx().write(bos);
        } finally {
            bos.close();
        }
        return new ByteArrayInputStream(bos.toByteArray());
    } catch (FileNotFoundException e) {
        Logger.error(e.getMessage());
    } catch (IOException e) {
        Logger.error(e.getMessage());
    }
    return null;
}

public StreamedContent getFile() {
    ControllerReportSuceso aux = new ControllerReportSuceso(suceso, sucesosAvionWrapper);
    return new DefaultStreamedContent(aux.getFile(), ControllerReportSuceso.CONTENT_TYPE, "parte suceso: " + suceso.getEntidad().getNumeroOrden() + ".xlsx");
}

导出时,.xlsx在打开文件时总是给我一个错误, Excel无法打开文件,因为格式或扩展名不正确。如果我将扩展名更改为.xls,我可以打开它。

我正在使用POI 3.12。

1 个答案:

答案 0 :(得分:0)

IP = [('192.168.1.1'),
      ('192.168.1.1'),
      ('192.168.1.2'),
      ('192.168.1.3')]
dfIP = pd.DataFrame(IP, columns=['IP'])
dfIPdup = dfIP[dfIP.duplicated()]

#logic is we got the duplicate and now add a column and mention 'duplicate' or unique
相关问题