Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/mongodb/12.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 Apache POI-Excel在xx.xlsx中发现无法读取的内容_Java_Excel_Apache Poi - Fatal编程技术网

Java Apache POI-Excel在xx.xlsx中发现无法读取的内容

Java Apache POI-Excel在xx.xlsx中发现无法读取的内容,java,excel,apache-poi,Java,Excel,Apache Poi,我试图从列表中创建一个excel文件,创建excel并将数据添加到其中,但是,在恢复内容之前。当我试图打开excel文件时,它说,“excel在xx.xlsx中发现了不可读的内容” 下面是我的代码: public static String createExcel( List<Localization> locs, String location,

我试图从列表中创建一个excel文件,创建excel并将数据添加到其中,但是,在恢复内容之前。当我试图打开excel文件时,它说,“excel在xx.xlsx中发现了不可读的内容”

下面是我的代码:

public static String createExcel( List<Localization> locs,
                                      String location,
                                      String revision,
                                      String[] columnTitles ) {

    int columns = columnTitles.length;
    FileOutputStream outputStream;
    File file = null;
    try {
        file = new File( "localization.xlsx" );
        outputStream = new FileOutputStream( file );
        XSSFWorkbook wb = new XSSFWorkbook();
   wb.getPackage().getPackageProperties().setRevisionProperty( revision );

        // create an editable cell style
        CellStyle unlockedCellStyle = wb.createCellStyle();
        unlockedCellStyle.setLocked( false );

        XSSFSheet sheet = wb.createSheet();
        sheet.lockFormatCells( false );
        sheet.lockFormatColumns( false );
        sheet.lockFormatRows( false );
        sheet.lockInsertRows( false );
        // lock the sheet for editing
        sheet.protectSheet( "password" );

        for ( int i = 0; i <= locs.size(); i++ ) {
            Row row = sheet.createRow( i );
            for ( int j = 0; j < columns; j++ ) {
                if ( i == 0 ) {
                    row.createCell( j ).setCellValue( columnTitles[j] );
                }

                else {
                    switch(j){
                        case 0:
                            row.createCell( j ).setCellValue( locs.get( i - 1 ).getId() );
                            break;
                        case 1:
                            row.createCell( j ).setCellValue( locs.get( i - 1 ).getEntityId() );
                            row.getCell( j ).setCellStyle( unlockedCellStyle );
                            break;
                        case 2:
                            row.createCell( j ).setCellValue( locs.get( i - 1 ).getValue() );
                            row.getCell( j ).setCellStyle( unlockedCellStyle );
                            break;
                        case 3:
                            row.createCell( j ).setCellValue( locs.get( i - 1 ).getLanguage().getLanguageCode() );
                            row.getCell( j ).setCellStyle( unlockedCellStyle );
                            break;
                        case 4:
                            row.createCell( j ).setCellValue( locs.get( i - 1 ).getCountry().getCountryCode() );
                            row.getCell( j ).setCellStyle( unlockedCellStyle );
                            break;
                    }
                }
            }
        }
        wb.write( outputStream );
        outputStream.close();
        wb.close();
        // file.delete();
    } catch ( Exception e ) {
        log.error( e.getMessage() );
    }
    if ( file != null )
        return file.getAbsolutePath().toString();
    else
        return null;
}
公共静态字符串createExcel(列出LOC、,
字符串位置,
字符串修订,
字符串[]列标题){
int columns=columnTitles.length;
FileOutputStream输出流;
File=null;
试一试{
文件=新文件(“本地化.xlsx”);
outputStream=新文件outputStream(文件);
XSSF工作簿wb=新XSSF工作簿();
wb.getPackage().getPackageProperties().setRevisionProperty(修订版);
//创建可编辑的单元样式
CellStyle unlockedCellStyle=wb.createCellStyle();
unlockedCellStyle.setLocked(假);
XSSFSheet sheet=wb.createSheet();
表1.1-1单元格(假);
表1.2列(假);
表1.2行(假);
表1.lockInsertRows(假);
//锁定图纸以进行编辑
表。保护表(“密码”);
对于(inti=0;i),Office OpenXML文档的

因此,Ecma Office Open XML文件格式标准对
修订版
属性规定:

“修订号。[示例:此值可能表示修订号 保存或修订的数量,前提是应用程序在每次 修订。结束示例]”


这意味着
revision
属性只能是一个整数值,因为它表示文档的保存或修订频率。

您使用的是什么版本的Apache POI?如果不是最新版本,升级时会发生什么?
wb.getPackage().getPackageProperties().setRevisionProperty(修订版)
例如,这里的
修订版是什么?它应该是一个单一的数字。请参阅@Axel Richter..我正在为修订版设置一个浮点值。@gameOne:如果只使用整数会发生什么情况?“修订版号。[示例:此值可能表示保存或修订的数量,前提是应用程序在每次修订后都会更新它。结束示例]“这听起来不像浮动。保存了1.234次?@AxelRichter请将其作为答案,以便我可以访问。浮动修订是问题所在