It's good.
I put the FileOutPutStream outside of the for.
like this:
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Iterator;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.openxml4j.opc.OPCPackage;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.FormulaEvaluator;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class LireEcrire {
/**
* @param args
*/
public static void main(String[] args) {
try {
//pour ouvrir un .xlsx
InputStream is = new FileInputStream("workbook.xlsx");
OPCPackage opc=OPCPackage.open(is);
XSSFWorkbook wb= new XSSFWorkbook(opc);
XSSFSheet sheet = (XSSFSheet)wb.getSheetAt(0);//onglet 0
XSSFRow row = null;
XSSFCell cell = null;
//pour ouvrir un .xlsx
FormulaEvaluator evaluator =
wb.getCreationHelper().createFormulaEvaluator();
evaluator.evaluate(cell);
System.out.println("1");
for(int i=0;i<5;i++){
System.out.println("2");
row = sheet.getRow(i);
System.out.println("4");
cell = row.createCell(i);
cell.setCellType(Cell.CELL_TYPE_STRING);
cell.setCellValue("sisi");
System.out.println(cell.getRowIndex() + ":"+
cell.getColumnIndex() + " -
" + cell + " : "+ cell.getCellType());
}
// Write the output to a file
FileOutputStream fileOut = new
FileOutputStream("workbook.xlsx");
wb.write(fileOut);
fileOut.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvalidFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/error-XmlValueDisconnectedException-tp5508605p5512069.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]