ASF Bugzilla – Attachment 31599 Details for
Bug 56468
[PATCH] Writing a workbook more than once corrupts the file
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for XmlValueDisconnectedException
XSSFWorkbook.java.patch (text/plain), 4.34 KB, created by
scott.paffrath
on 2014-05-06 23:11:10 UTC
(
hide
)
Description:
Patch for XmlValueDisconnectedException
Filename:
MIME Type:
Creator:
scott.paffrath
Created:
2014-05-06 23:11:10 UTC
Size:
4.34 KB
patch
obsolete
>Index: src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java >=================================================================== >--- src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (revision 1592771) >+++ src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (working copy) >@@ -1307,7 +1307,18 @@ > i++; > } > names.setDefinedNameArray(nr); >+ if(workbook.isSetDefinedNames()) { >+ workbook.unsetDefinedNames(); >+ } > workbook.setDefinedNames(names); >+ >+ // Re-process the named ranges >+ namedRanges = new ArrayList<XSSFName>(); >+ if(workbook.isSetDefinedNames()) { >+ for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameArray()) { >+ namedRanges.add(new XSSFName(ctName, this)); >+ } >+ } > } else { > if(workbook.isSetDefinedNames()) { > workbook.unsetDefinedNames(); >Index: src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultipleWrites.java >=================================================================== >--- src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultipleWrites.java (revision 0) >+++ src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultipleWrites.java (working copy) >@@ -0,0 +1,77 @@ >+/* ==================================================================== >+ Licensed to the Apache Software Foundation (ASF) under one or more >+ contributor license agreements. See the NOTICE file distributed with >+ this work for additional information regarding copyright ownership. >+ The ASF licenses this file to You under the Apache License, Version 2.0 >+ (the "License"); you may not use this file except in compliance with >+ the License. You may obtain a copy of the License at >+ >+ http://www.apache.org/licenses/LICENSE-2.0 >+ >+ Unless required by applicable law or agreed to in writing, software >+ distributed under the License is distributed on an "AS IS" BASIS, >+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. >+ See the License for the specific language governing permissions and >+ limitations under the License. >+ ==================================================================== */ >+package org.apache.poi.xssf.usermodel; >+ >+import static org.junit.Assert.assertEquals; >+import org.junit.Test; >+import java.io.BufferedReader; >+import java.io.ByteArrayInputStream; >+import java.io.ByteArrayOutputStream; >+import java.io.InputStream; >+import junit.framework.TestCase; >+ >+import org.apache.poi.ss.util.CellRangeAddress; >+import org.apache.poi.xssf.usermodel.*; >+ >+public class TestMultipleWrites extends TestCase >+{ >+ // Assert that multiple writes of a workbook output the same result. >+ public void testMultipleWritesResultInSameWorkbookWritten() throws Exception { >+ XSSFWorkbook wb = new XSSFWorkbook(); >+ XSSFSheet sheet = wb.createSheet(); >+ XSSFRow row = sheet.createRow(0); >+ XSSFCell cell = row.createCell(0); >+ cell.setCellValue("Hi"); >+ >+ // Ensure an entry for the XSSFName collection so that is tested too. >+ sheet.setRepeatingRows(new CellRangeAddress(0, 0, 0, 0)); >+ >+ ByteArrayOutputStream baos = null; >+ ByteArrayOutputStream baos2 = null; >+ InputStream is = null; >+ InputStream is2 = null; >+ try { >+ baos = new ByteArrayOutputStream(8192); >+ wb.write(baos); >+ is = new ByteArrayInputStream(baos.toByteArray()); >+ >+ baos2 = new ByteArrayOutputStream(8192); >+ wb.write(baos2); >+ is2 = new ByteArrayInputStream(baos2.toByteArray()); >+ >+ // Files are the same size >+ assertEquals(baos.size(), baos2.size()); >+ >+ // Files are a binary match >+ int i1; >+ int i2; >+ while (((i1 = is.read()) != -1)&&((i2 = is2.read()) != -1)) { >+ assertEquals(i1, i2); >+ } >+ } >+ finally { >+ if(baos!=null) >+ baos.close(); >+ if(baos2!=null) >+ baos2.close(); >+ if(is!=null) >+ is.close(); >+ if(is2!=null) >+ is2.close(); >+ } >+ } >+}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 56468
:
31567
|
31576
|
31577
|
31578
|
31579
|
31581
|
31594
| 31599