Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/354.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错误_Java_Excel_Apache Poi - Fatal编程技术网

Java 当下拉列表值包含带Apache POI的连字符(-)时出现Excel错误

Java 当下拉列表值包含带Apache POI的连字符(-)时出现Excel错误,java,excel,apache-poi,Java,Excel,Apache Poi,我使用ApachePOI在excel工作表的某些列中添加了下拉列表。当其中一个下拉值包含字符连字符-,然后打开excel工作表时,会出现错误-我们发现Text.xlsx中的某些内容存在问题 没有连字符,一切正常。 我创建下拉列表的代码与此问题提到的公认解决方案相同- 请提出一些解决方案。下面的代码对我来说很好: DataValidation dataValidation = null; DataValidationConstraint constraint = n

我使用ApachePOI在excel工作表的某些列中添加了下拉列表。当其中一个下拉值包含字符连字符-,然后打开excel工作表时,会出现错误-我们发现Text.xlsx中的某些内容存在问题

没有连字符,一切正常。 我创建下拉列表的代码与此问题提到的公认解决方案相同-


请提出一些解决方案。

下面的代码对我来说很好:

        DataValidation dataValidation = null;
        DataValidationConstraint constraint = null;
        DataValidationHelper validationHelper = null;

         XSSFWorkbook wb = new XSSFWorkbook();
         XSSFSheet sheet1=(XSSFSheet) wb.createSheet("sheet1");


            validationHelper=new XSSFDataValidationHelper(sheet1);
            CellRangeAddressList addressList = new  CellRangeAddressList(0,5,0,0);
            constraint =validationHelper.createExplicitListConstraint(new String[]{"SELECT","10-11", "20", "30"});
            dataValidation = validationHelper.createValidation(constraint, addressList);
            dataValidation.setSuppressDropDownArrow(true);      
            sheet1.addValidationData(dataValidation);

            FileOutputStream fileOut = new FileOutputStream("c:\\temp\\abhishek.xlsx");
            wb.write(fileOut);
            fileOut.close();
            wb.close();
输出:


@如果答案对你有效,请接受。逗号呢?对我来说,这是分裂成下一行。