Bug 49940: Apply patch to avoid XmlValueDisconnectedException when
saving a file twice and enable reproducing unit test git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1535938 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
780aec8ad2
commit
5644fcbaa0
@ -39,22 +39,7 @@ import org.apache.poi.xssf.usermodel.extensions.XSSFCellBorder;
|
|||||||
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
|
import org.apache.poi.xssf.usermodel.extensions.XSSFCellFill;
|
||||||
import org.apache.xmlbeans.XmlException;
|
import org.apache.xmlbeans.XmlException;
|
||||||
import org.apache.xmlbeans.XmlOptions;
|
import org.apache.xmlbeans.XmlOptions;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorder;
|
import org.openxmlformats.schemas.spreadsheetml.x2006.main.*;
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTBorders;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellStyleXfs;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTCellXfs;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxf;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTDxfs;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFill;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFills;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFont;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTFonts;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTNumFmt;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTNumFmts;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTStylesheet;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.CTXf;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.STPatternType;
|
|
||||||
import org.openxmlformats.schemas.spreadsheetml.x2006.main.StyleSheetDocument;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -367,7 +352,7 @@ public class StylesTable extends POIXMLDocumentPart {
|
|||||||
// Work on the current one
|
// Work on the current one
|
||||||
// Need to do this, as we don't handle
|
// Need to do this, as we don't handle
|
||||||
// all the possible entries yet
|
// all the possible entries yet
|
||||||
CTStylesheet styleSheet = doc.getStyleSheet();
|
CTStylesheet styleSheet = doc.getStyleSheet();
|
||||||
|
|
||||||
// Formats
|
// Formats
|
||||||
CTNumFmts formats = CTNumFmts.Factory.newInstance();
|
CTNumFmts formats = CTNumFmts.Factory.newInstance();
|
||||||
@ -381,7 +366,10 @@ public class StylesTable extends POIXMLDocumentPart {
|
|||||||
|
|
||||||
int idx;
|
int idx;
|
||||||
// Fonts
|
// Fonts
|
||||||
CTFonts ctFonts = CTFonts.Factory.newInstance();
|
CTFonts ctFonts = styleSheet.getFonts();
|
||||||
|
if (ctFonts == null) {
|
||||||
|
ctFonts = CTFonts.Factory.newInstance();
|
||||||
|
}
|
||||||
ctFonts.setCount(fonts.size());
|
ctFonts.setCount(fonts.size());
|
||||||
CTFont[] ctfnt = new CTFont[fonts.size()];
|
CTFont[] ctfnt = new CTFont[fonts.size()];
|
||||||
idx = 0;
|
idx = 0;
|
||||||
@ -390,7 +378,10 @@ public class StylesTable extends POIXMLDocumentPart {
|
|||||||
styleSheet.setFonts(ctFonts);
|
styleSheet.setFonts(ctFonts);
|
||||||
|
|
||||||
// Fills
|
// Fills
|
||||||
CTFills ctFills = CTFills.Factory.newInstance();
|
CTFills ctFills = styleSheet.getFills();
|
||||||
|
if (ctFills == null) {
|
||||||
|
ctFills = CTFills.Factory.newInstance();
|
||||||
|
}
|
||||||
ctFills.setCount(fills.size());
|
ctFills.setCount(fills.size());
|
||||||
CTFill[] ctf = new CTFill[fills.size()];
|
CTFill[] ctf = new CTFill[fills.size()];
|
||||||
idx = 0;
|
idx = 0;
|
||||||
@ -399,7 +390,10 @@ public class StylesTable extends POIXMLDocumentPart {
|
|||||||
styleSheet.setFills(ctFills);
|
styleSheet.setFills(ctFills);
|
||||||
|
|
||||||
// Borders
|
// Borders
|
||||||
CTBorders ctBorders = CTBorders.Factory.newInstance();
|
CTBorders ctBorders = styleSheet.getBorders();
|
||||||
|
if (ctBorders == null) {
|
||||||
|
ctBorders = CTBorders.Factory.newInstance();
|
||||||
|
}
|
||||||
ctBorders.setCount(borders.size());
|
ctBorders.setCount(borders.size());
|
||||||
CTBorder[] ctb = new CTBorder[borders.size()];
|
CTBorder[] ctb = new CTBorder[borders.size()];
|
||||||
idx = 0;
|
idx = 0;
|
||||||
@ -409,7 +403,10 @@ public class StylesTable extends POIXMLDocumentPart {
|
|||||||
|
|
||||||
// Xfs
|
// Xfs
|
||||||
if(xfs.size() > 0) {
|
if(xfs.size() > 0) {
|
||||||
CTCellXfs ctXfs = CTCellXfs.Factory.newInstance();
|
CTCellXfs ctXfs = styleSheet.getCellXfs();
|
||||||
|
if (ctXfs == null) {
|
||||||
|
ctXfs = CTCellXfs.Factory.newInstance();
|
||||||
|
}
|
||||||
ctXfs.setCount(xfs.size());
|
ctXfs.setCount(xfs.size());
|
||||||
ctXfs.setXfArray(
|
ctXfs.setXfArray(
|
||||||
xfs.toArray(new CTXf[xfs.size()])
|
xfs.toArray(new CTXf[xfs.size()])
|
||||||
@ -419,7 +416,10 @@ public class StylesTable extends POIXMLDocumentPart {
|
|||||||
|
|
||||||
// Style xfs
|
// Style xfs
|
||||||
if(styleXfs.size() > 0) {
|
if(styleXfs.size() > 0) {
|
||||||
CTCellStyleXfs ctSXfs = CTCellStyleXfs.Factory.newInstance();
|
CTCellStyleXfs ctSXfs = styleSheet.getCellStyleXfs();
|
||||||
|
if (ctSXfs == null) {
|
||||||
|
ctSXfs = CTCellStyleXfs.Factory.newInstance();
|
||||||
|
}
|
||||||
ctSXfs.setCount(styleXfs.size());
|
ctSXfs.setCount(styleXfs.size());
|
||||||
ctSXfs.setXfArray(
|
ctSXfs.setXfArray(
|
||||||
styleXfs.toArray(new CTXf[styleXfs.size()])
|
styleXfs.toArray(new CTXf[styleXfs.size()])
|
||||||
@ -429,7 +429,10 @@ public class StylesTable extends POIXMLDocumentPart {
|
|||||||
|
|
||||||
// Style dxfs
|
// Style dxfs
|
||||||
if(dxfs.size() > 0) {
|
if(dxfs.size() > 0) {
|
||||||
CTDxfs ctDxfs = CTDxfs.Factory.newInstance();
|
CTDxfs ctDxfs = styleSheet.getDxfs();
|
||||||
|
if (ctDxfs == null) {
|
||||||
|
ctDxfs = CTDxfs.Factory.newInstance();
|
||||||
|
}
|
||||||
ctDxfs.setCount(dxfs.size());
|
ctDxfs.setCount(dxfs.size());
|
||||||
ctDxfs.setDxfArray(dxfs.toArray(new CTDxf[dxfs.size()])
|
ctDxfs.setDxfArray(dxfs.toArray(new CTDxf[dxfs.size()])
|
||||||
);
|
);
|
||||||
|
@ -35,24 +35,7 @@ import org.apache.poi.ss.formula.WorkbookEvaluator;
|
|||||||
import org.apache.poi.ss.formula.eval.ErrorEval;
|
import org.apache.poi.ss.formula.eval.ErrorEval;
|
||||||
import org.apache.poi.ss.formula.eval.ValueEval;
|
import org.apache.poi.ss.formula.eval.ValueEval;
|
||||||
import org.apache.poi.ss.formula.functions.Function;
|
import org.apache.poi.ss.formula.functions.Function;
|
||||||
import org.apache.poi.ss.usermodel.BaseTestBugzillaIssues;
|
import org.apache.poi.ss.usermodel.*;
|
||||||
import org.apache.poi.ss.usermodel.Cell;
|
|
||||||
import org.apache.poi.ss.usermodel.CellStyle;
|
|
||||||
import org.apache.poi.ss.usermodel.CellValue;
|
|
||||||
import org.apache.poi.ss.usermodel.ClientAnchor;
|
|
||||||
import org.apache.poi.ss.usermodel.Comment;
|
|
||||||
import org.apache.poi.ss.usermodel.CreationHelper;
|
|
||||||
import org.apache.poi.ss.usermodel.DataFormatter;
|
|
||||||
import org.apache.poi.ss.usermodel.Drawing;
|
|
||||||
import org.apache.poi.ss.usermodel.Font;
|
|
||||||
import org.apache.poi.ss.usermodel.FormulaError;
|
|
||||||
import org.apache.poi.ss.usermodel.FormulaEvaluator;
|
|
||||||
import org.apache.poi.ss.usermodel.IndexedColors;
|
|
||||||
import org.apache.poi.ss.usermodel.Name;
|
|
||||||
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.ss.util.AreaReference;
|
import org.apache.poi.ss.util.AreaReference;
|
||||||
import org.apache.poi.ss.util.CellReference;
|
import org.apache.poi.ss.util.CellReference;
|
||||||
import org.apache.poi.xssf.XSSFITestDataProvider;
|
import org.apache.poi.xssf.XSSFITestDataProvider;
|
||||||
@ -181,7 +164,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
* read the file despite the naughtyness
|
* read the file despite the naughtyness
|
||||||
*/
|
*/
|
||||||
public void test49020() throws Exception {
|
public void test49020() throws Exception {
|
||||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("BrNotClosed.xlsx");
|
/*XSSFWorkbook wb =*/ XSSFTestDataSamples.openSampleWorkbook("BrNotClosed.xlsx");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -326,9 +309,9 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
assertEquals(startingFonts+1, wb.getNumberOfFonts());
|
assertEquals(startingFonts+1, wb.getNumberOfFonts());
|
||||||
|
|
||||||
// Get two more, unchanged
|
// Get two more, unchanged
|
||||||
Font b = wb.createFont();
|
/*Font b =*/ wb.createFont();
|
||||||
assertEquals(startingFonts+2, wb.getNumberOfFonts());
|
assertEquals(startingFonts+2, wb.getNumberOfFonts());
|
||||||
Font c = wb.createFont();
|
/*Font c =*/ wb.createFont();
|
||||||
assertEquals(startingFonts+3, wb.getNumberOfFonts());
|
assertEquals(startingFonts+3, wb.getNumberOfFonts());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -550,9 +533,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Repeatedly writing the same file which has styles
|
* Repeatedly writing the same file which has styles
|
||||||
* TODO Currently failing
|
|
||||||
*/
|
*/
|
||||||
public void DISABLEDtest49940() throws Exception {
|
public void test49940() throws Exception {
|
||||||
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("styles.xlsx");
|
XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("styles.xlsx");
|
||||||
assertEquals(3, wb.getNumberOfSheets());
|
assertEquals(3, wb.getNumberOfSheets());
|
||||||
assertEquals(10, wb.getStylesSource().getNumCellStyles());
|
assertEquals(10, wb.getStylesSource().getNumCellStyles());
|
||||||
@ -1004,7 +986,8 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
* Setting repeating rows and columns shouldn't break
|
* Setting repeating rows and columns shouldn't break
|
||||||
* any print settings that were there before
|
* any print settings that were there before
|
||||||
*/
|
*/
|
||||||
public void test49253() throws Exception {
|
@SuppressWarnings("deprecation")
|
||||||
|
public void test49253() throws Exception {
|
||||||
XSSFWorkbook wb1 = new XSSFWorkbook();
|
XSSFWorkbook wb1 = new XSSFWorkbook();
|
||||||
XSSFWorkbook wb2 = new XSSFWorkbook();
|
XSSFWorkbook wb2 = new XSSFWorkbook();
|
||||||
|
|
||||||
@ -1342,7 +1325,7 @@ public final class TestXSSFBugs extends BaseTestBugzillaIssues {
|
|||||||
assertEquals(259.0, a1Value, 0.0);
|
assertEquals(259.0, a1Value, 0.0);
|
||||||
|
|
||||||
// KY: SUM(B1: IZ1)
|
// KY: SUM(B1: IZ1)
|
||||||
double ky1Value =
|
/*double ky1Value =*/
|
||||||
evaluator.evaluate(workbook.getSheetAt(0).getRow(0).getCell(310)).getNumberValue();
|
evaluator.evaluate(workbook.getSheetAt(0).getRow(0).getCell(310)).getNumberValue();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
|
Loading…
Reference in New Issue
Block a user