You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@poi.apache.org by bu...@apache.org on 2014/05/29 09:39:41 UTC
[Bug 56574] New: Excel file crashes while opening XLSX.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56574
Bug ID: 56574
Summary: Excel file crashes while opening XLSX.
Product: POI
Version: 3.10
Hardware: All
Status: NEW
Severity: major
Priority: P2
Component: POI Overall
Assignee: dev@poi.apache.org
Reporter: ranganath.196@scii.in
Created attachment 31676
--> https://issues.apache.org/bugzilla/attachment.cgi?id=31676&action=edit
Above description is achived in this file.
Step 1 : Create ".xlsx" file write any formula at A1 cell like "=Today()".
Step 2 : Drag "A1" Cell up to "A20" and save the file.
Step 3 : Through POI refer saved excel file and
remove formula by using (cell.setFormula(null)) and write data to sheet
containing formulas, write starts from Cells "A1" to "A10".
Step 4 : Execute your java program.
Step 5 : Try to open excel file, its giving error "Excel found unreadable
content.". After opening below formulas cells formula and styles are
overwriting to written style.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 56574] Excel file crashes while opening XLSX.
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56574
--- Comment #2 from Ranganath <ra...@scii.in> ---
(In reply to Dominik Stadler from comment #1)
> Can you provide the actual code that you use? Preferably as self-contained
> unit test so we can incorporate the steps into our test-suite and avoid the
Below is the code I am using to remove formula from excel file.
Row row = sheet.getRow(1);
if (row == null){
row = sheet.createRow(1);
}
Cell cell = row.getCell(1);
if(cell == null){
cell = row.createCell(1);
} else {
/** Code to remove formula from cell **/
if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
cell.setCellFormula(null);
cell.getCellStyle().setDataFormat((short) 0);
}
/** End **/
}
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 56574] Excel file crashes while opening XLSX.
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56574
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEEDINFO |NEW
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 56574] Excel file crashes while opening XLSX.
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56574
--- Comment #3 from Ranganath <ra...@scii.in> ---
Below is the entire code I used for above bug
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFFormulaEvaluator;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelFormulaDrag {
public static Workbook workbook07;
public static Map<String, Object[]> data;
public void setData() {
//This data needs to be written (Object[])
data = new TreeMap<String, Object[]>();
data.put("1", new Object[] {"ID", "NAME", "LASTNAME"});
data.put("2", new Object[] {2, "Amit", "Shukla"});
data.put("3", new Object[] {1, "Lokesh", "Gupta"});
data.put("4", new Object[] {4, "John", "Adwards"});
data.put("5", new Object[] {2, "Brian", "Schultz"});
}
public void format2007() throws IOException {
XSSFSheet sheet = (XSSFSheet) workbook07.getSheet("Emp");
if(sheet == null){
sheet = (XSSFSheet) workbook07.createSheet("Emp");
}
Set<String> keyset = data.keySet();
int rownum = 1;
for (String key : keyset)
{
Row row = sheet.createRow(rownum++);
this.writeToSheet(row, key);
}
}
public void writeToSheet(Row row, String key){
Object [] objArr = data.get(key);
int cellnum = 0;
for (Object obj : objArr)
{
Cell cell = row.getCell(cellnum);
if(cell == null){
cell = row.createCell(cellnum);
} else {
if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
if(cell.getCellType() == Cell.CELL_TYPE_FORMULA) {
cell.setCellFormula(null);
cell.getCellStyle().setDataFormat((short) 0);
}
}
}
if(obj instanceof String) {
cell.setCellValue((String)obj);
} else if(obj instanceof Integer) {
cell.setCellValue((Integer)obj);
}
XSSFFormulaEvaluator.evaluateAllFormulaCells((XSSFWorkbook)
workbook07);
workbook07.getCreationHelper().createFormulaEvaluator().evaluateAll();
cellnum++;
}
}
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
try {
ExcelFormulaDrag excelFormulaDrag = new ExcelFormulaDrag();
excelFormulaDrag.setData();
workbook07 = new XSSFWorkbook(new
FileInputStream("D:\\testing7.xlsx"));
excelFormulaDrag.format2007();
FileOutputStream out = new FileOutputStream(new
File("D:\\testing4.xlsx"));
workbook07.write(out);
out.close();
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
In .xlsx file in cell A1 type '=TODAY()' and drag up to A20, and refer same to
above code and execute.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 56574] Excel file crashes while opening XLSX.
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56574
Ranganath <ra...@scii.in> changed:
What |Removed |Added
----------------------------------------------------------------------------
OS| |All
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org
[Bug 56574] Excel file crashes while opening XLSX.
Posted by bu...@apache.org.
https://issues.apache.org/bugzilla/show_bug.cgi?id=56574
Dominik Stadler <do...@gmx.at> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |NEEDINFO
--- Comment #1 from Dominik Stadler <do...@gmx.at> ---
Can you provide the actual code that you use? Preferably as self-contained unit
test so we can incorporate the steps into our test-suite and avoid the
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@poi.apache.org
For additional commands, e-mail: dev-help@poi.apache.org