Hello, I have the following problem with XSSF. Given a .xlsx file containing a formula cell (file is attached). This cell should be cleared and then the workbook is saved to a new .xlsx file, When I open the new .xlsx file with Microsoft Excel 2007 I get an error message:
Removed records: formula from /xl/calcChain.xml part (calculation properties)
Here is the code:
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.poi.ss.usermodel.Cell;
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.xssf.usermodel.XSSFWorkbook;
public class Main {
public static void main(String[] args) {
try {
Workbook wb = new XSSFWorkbook(new FileInputStream("test.xlsx"));
Sheet sheet = wb.getSheetAt(0);
// removing numeric cell works
Row row = sheet.getRow(2);
Cell cell = row.getCell(0);
row.removeCell(cell);
// removing formula cell does not work
row = sheet.getRow(3);
cell = row.getCell(0);
//row.removeCell(cell);
// setting to blank cell does not work
//cell.setCellType(Cell.CELL_TYPE_BLANK);
//cell.setCellValue((String) null);
// setting to a new cell
//row.createCell(0).setCellValue("");
FileOutputStream out = new FileOutputStream("test_out.xlsx");
wb.write(out);
out.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
I'm using Apache-POI 3.7-beta2
Thank you for your help,
Bettina
--
Vorstand/Board of Management:
Dr. Bernd Finkbeiner, Dr. Roland Niemeier,
Dr. Arno Steitz, Dr. Ingrid Zech
Vorsitzender des Aufsichtsrats/ Chairman of the Supervisory Board: Michel Lepert Sitz/Registered Office: Tuebingen Registergericht/Registration Court: StuttgartRegisternummer/Commercial Register No.: HRB 382196
test.xlsx
Description: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
--------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
