I am getting the following exception while trying to write an .xlsx
file using Apache POI: org.apache.xmlbeans.impl.values.XmlValueDisconnectedException>
This seems to be indeed a bug in XSSFSheet.createRow(int index). As long as the bug is not fixed, using this class as a workaround should do the trick :
import java.util.Iterator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
public class PoiHacks
{
// Fix of XSSFSheet.createRow(int index)
public static Row createRow(Sheet sheet, int index) {
Row row = sheet.getRow(index);
if(row==null) return sheet.createRow(index);
Iterator it = row.iterator();
while(it.hasNext()) {
it.next();
it.remove();
}
return row;
}
}
Use :
PoiHacks.createRow(sheet, 0);