View | Details | Raw Unified | Return to bug 56468
Collapse All | Expand All

(-)src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java (+11 lines)
Lines 1307-1313 Link Here
1307
                i++;
1307
                i++;
1308
            }
1308
            }
1309
            names.setDefinedNameArray(nr);
1309
            names.setDefinedNameArray(nr);
1310
            if(workbook.isSetDefinedNames()) {
1311
                workbook.unsetDefinedNames();
1312
            }
1310
            workbook.setDefinedNames(names);
1313
            workbook.setDefinedNames(names);
1314
            
1315
            // Re-process the named ranges
1316
            namedRanges = new ArrayList<XSSFName>();
1317
            if(workbook.isSetDefinedNames()) {
1318
                for(CTDefinedName ctName : workbook.getDefinedNames().getDefinedNameArray()) {
1319
                    namedRanges.add(new XSSFName(ctName, this));
1320
                }
1321
            }
1311
        } else {
1322
        } else {
1312
            if(workbook.isSetDefinedNames()) {
1323
            if(workbook.isSetDefinedNames()) {
1313
                workbook.unsetDefinedNames();
1324
                workbook.unsetDefinedNames();
(-)src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestMultipleWrites.java (+77 lines)
Line 0 Link Here
1
/* ====================================================================
2
 Licensed to the Apache Software Foundation (ASF) under one or more
3
 contributor license agreements.  See the NOTICE file distributed with
4
 this work for additional information regarding copyright ownership.
5
 The ASF licenses this file to You under the Apache License, Version 2.0
6
 (the "License"); you may not use this file except in compliance with
7
 the License.  You may obtain a copy of the License at
8
9
 http://www.apache.org/licenses/LICENSE-2.0
10
11
 Unless required by applicable law or agreed to in writing, software
12
 distributed under the License is distributed on an "AS IS" BASIS,
13
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 See the License for the specific language governing permissions and
15
 limitations under the License.
16
 ==================================================================== */
17
package org.apache.poi.xssf.usermodel;
18
19
import static org.junit.Assert.assertEquals;
20
import org.junit.Test;
21
import java.io.BufferedReader;
22
import java.io.ByteArrayInputStream;
23
import java.io.ByteArrayOutputStream;
24
import java.io.InputStream;
25
import junit.framework.TestCase;
26
27
import org.apache.poi.ss.util.CellRangeAddress;
28
import org.apache.poi.xssf.usermodel.*;
29
30
public class TestMultipleWrites extends TestCase
31
{
32
    // Assert that multiple writes of a workbook output the same result.
33
    public void testMultipleWritesResultInSameWorkbookWritten() throws Exception {
34
        XSSFWorkbook wb = new XSSFWorkbook();
35
        XSSFSheet sheet = wb.createSheet();
36
        XSSFRow row = sheet.createRow(0);
37
        XSSFCell cell = row.createCell(0);
38
        cell.setCellValue("Hi");
39
        
40
        // Ensure an entry for the XSSFName collection so that is tested too.
41
        sheet.setRepeatingRows(new CellRangeAddress(0, 0, 0, 0));
42
43
        ByteArrayOutputStream baos = null;
44
        ByteArrayOutputStream baos2 = null;
45
        InputStream is = null;
46
        InputStream is2 = null;
47
        try {
48
            baos = new ByteArrayOutputStream(8192);
49
            wb.write(baos);
50
            is = new ByteArrayInputStream(baos.toByteArray());
51
52
            baos2 = new ByteArrayOutputStream(8192);
53
            wb.write(baos2);
54
            is2 = new ByteArrayInputStream(baos2.toByteArray());
55
            
56
            // Files are the same size
57
            assertEquals(baos.size(), baos2.size());
58
            
59
            // Files are a binary match
60
            int i1;
61
            int i2;
62
            while (((i1 = is.read()) != -1)&&((i2 = is2.read()) != -1)) {
63
                assertEquals(i1, i2);
64
            }
65
        }
66
        finally {
67
            if(baos!=null)
68
                baos.close();
69
            if(baos2!=null)
70
                baos2.close();
71
            if(is!=null)
72
                is.close();
73
            if(is2!=null)
74
                is2.close();
75
        }
76
    }
77
}

Return to bug 56468