java.lang.IllegalArgumentException: попытка записать строку [1] в диапазоне [0,1], которая уже записана на диск - PullRequest
0 голосов
/ 31 мая 2019

Пока вы скачиваете xlsx, используя apache poi версии 3.15 в Ubuntu, он дает мне:

java.lang.IllegalArgumentException: Attempting to write a row[1] in the range [0,1] that is already written to disk at org.apache.poi.xssf.streaming.SXSSFSheet.createRow(SXSSFSheet.java:133),
at org.apache.poi.xssf.streaming.SXSSFSheet.createRow(SXSSFSheet.java:62)
String fileName = "myDownloads"+".xlsx";
String sourceFolderPath = "/home/user/sampleFile/";
FileInputStream fileInputStream = new 
FileInputStream(sourceFolderPath+"SampleFile.xlsx");
XSSFWorkbook wb_template = new XSSFWorkbook(fileInputStream);
fileInputStream.close();
String destinationFolderPath = "/home/user/downloads";
File dir = new File(destinationFolderPath);
if (!dir.exists()) {
    dir.mkdirs();
}
SXSSFWorkbook workbook = new SXSSFWorkbook(wb_template);
workbook.setCompressTempFiles(true);
SXSSFSheet workSheet = (SXSSFSheet) workbook.getSheetAt(0);
workSheet.setRandomAccessWindowSize(100000);
SXSSFSheet workSheet1 = (SXSSFSheet) workbook.getSheetAt(1);
workSheet1.setRandomAccessWindowSize(100000);
List<Student> studentList = studnetDao.getStudentListByName("kumar");
if(CollectionUtils.isNotEmpty(studentList)) {
    Integer rowIndex = 1;
    for(Student s : studentList) {
        Row row = workSheet.getRow(rowIndex);
        if (row == null) {
            row = workSheet.createRow(rowIndex); 
        }
    }
}
...