From commits-return-12279-apmail-poi-commits-archive=poi.apache.org@poi.apache.org Fri Apr 26 07:48:29 2019 Return-Path: X-Original-To: apmail-poi-commits-archive@minotaur.apache.org Delivered-To: apmail-poi-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by minotaur.apache.org (Postfix) with SMTP id E6C7019E7B for ; Fri, 26 Apr 2019 07:48:28 +0000 (UTC) Received: (qmail 79888 invoked by uid 500); 26 Apr 2019 07:48:28 -0000 Delivered-To: apmail-poi-commits-archive@poi.apache.org Received: (qmail 79854 invoked by uid 500); 26 Apr 2019 07:48:28 -0000 Mailing-List: contact commits-help@poi.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@poi.apache.org Delivered-To: mailing list commits@poi.apache.org Received: (qmail 79845 invoked by uid 99); 26 Apr 2019 07:48:28 -0000 Received: from Unknown (HELO svn01-us-west.apache.org) (209.188.14.144) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 26 Apr 2019 07:48:28 +0000 Received: from svn01-us-west.apache.org (localhost [127.0.0.1]) by svn01-us-west.apache.org (ASF Mail Server at svn01-us-west.apache.org) with ESMTP id 138723A0168 for ; Fri, 26 Apr 2019 07:48:26 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1858179 - in /poi/trunk/src/ooxml: java/org/apache/poi/xssf/usermodel/XSSFSheet.java java/org/apache/poi/xssf/usermodel/XSSFTable.java testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java Date: Fri, 26 Apr 2019 07:48:26 -0000 To: commits@poi.apache.org From: fanningpj@apache.org X-Mailer: svnmailer-1.0.9 Message-Id: <20190426074827.138723A0168@svn01-us-west.apache.org> Author: fanningpj Date: Fri Apr 26 07:48:26 2019 New Revision: 1858179 URL: http://svn.apache.org/viewvc?rev=1858179&view=rev Log: [bug-62906] ensure table display name is always set Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java?rev=1858179&r1=1858178&r2=1858179&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java Fri Apr 26 07:48:26 2019 @@ -4140,6 +4140,10 @@ public class XSSFSheet extends POIXMLDoc table.setArea(tableArea); } + // Bug 62906: Must set a display name; can be overridden using setDisplayName + final String displayName = "Table" + tableNumber; + table.setDisplayName(displayName); + return table; } Modified: poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java?rev=1858179&r1=1858178&r2=1858179&view=diff ============================================================================== --- poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java (original) +++ poi/trunk/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFTable.java Fri Apr 26 07:48:26 2019 @@ -432,6 +432,9 @@ public class XSSFTable extends POIXMLDoc * @param name to use */ public void setDisplayName(String name) { + if (name == null || name.isEmpty()) { + throw new IllegalArgumentException("Display name must not be null or empty"); + } ctTable.setDisplayName(name); } Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java?rev=1858179&r1=1858178&r2=1858179&view=diff ============================================================================== --- poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java (original) +++ poi/trunk/src/ooxml/testcases/org/apache/poi/xssf/usermodel/TestXSSFTable.java Fri Apr 26 07:48:26 2019 @@ -171,7 +171,7 @@ public final class TestXSSFTable { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx")) { XSSFTable table = wb.getTable("\\_Prime.1"); assertEquals(0, table.getStartColIndex()); - } + } } @Test @@ -229,17 +229,13 @@ public final class TestXSSFTable { assertEquals(3, table.getColumnCount()); } } - + @Test public void getAndSetDisplayName() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("StructuredReferences.xlsx")) { XSSFTable table = wb.getTable("\\_Prime.1"); assertEquals("\\_Prime.1", table.getDisplayName()); - - table.setDisplayName(null); - assertNull(table.getDisplayName()); - assertEquals("\\_Prime.1", table.getName()); // name and display name are different - + table.setDisplayName("Display name"); assertEquals("Display name", table.getDisplayName()); assertEquals("\\_Prime.1", table.getName()); // name and display name are different @@ -253,6 +249,8 @@ public final class TestXSSFTable { try (XSSFWorkbook wb = new XSSFWorkbook()) { XSSFSheet sh = wb.createSheet(); XSSFTable table = sh.createTable(); + assertNotNull(table.getDisplayName()); + assertNotNull(table.getCTTable().getDisplayName()); CTTable ctTable = table.getCTTable(); ctTable.setRef("B2:E8"); @@ -299,7 +297,7 @@ public final class TestXSSFTable { IOUtils.closeQuietly(wb); } } - + @Test public void testGetDataRowCount() throws IOException { try (XSSFWorkbook wb = new XSSFWorkbook()) { @@ -318,7 +316,7 @@ public final class TestXSSFTable { IOUtils.closeQuietly(wb); } } - + @Test public void testSetDataRowCount() throws IOException { try (XSSFWorkbook wb = new XSSFWorkbook()) { @@ -358,6 +356,8 @@ public final class TestXSSFTable { XSSFTable table1 = sheet.createTable(reference1); assertEquals("A1:C3", table1.getCTTable().getRef()); + assertNotNull(table1.getDisplayName()); + assertNotNull(table1.getCTTable().getDisplayName()); assertEquals(1, table1.getCTTable().getTableColumns().getTableColumnArray(0).getId()); assertEquals(2, table1.getCTTable().getTableColumns().getTableColumnArray(1).getId()); @@ -413,7 +413,7 @@ public final class TestXSSFTable { assertEquals(2, table.getRowCount()); } } - + @Test public void testCreateColumn() throws IOException { try (XSSFWorkbook wb = new XSSFWorkbook()) { @@ -460,7 +460,7 @@ public final class TestXSSFTable { table.createColumn("Column 3", 3); // out of bounds } } - + @Test public void testDifferentHeaderTypes() throws IOException { try (XSSFWorkbook wb = XSSFTestDataSamples.openSampleWorkbook("TablesWithDifferentHeaders.xlsx")) { @@ -492,7 +492,7 @@ public final class TestXSSFTable { assertEquals("Column2", t.getCTTable().getTableColumns().getTableColumnArray(1).getName()); } } - + /** * See https://stackoverflow.com/questions/44407111/apache-poi-cant-format-filled-cells-as-numeric */ @@ -546,4 +546,45 @@ public final class TestXSSFTable { IOUtils.closeQuietly(wb2); } } + + @Test + public void testSetDisplayName() throws IOException { + try (XSSFWorkbook wb = new XSSFWorkbook()) { + XSSFSheet sheet = wb.createSheet(); + + AreaReference reference1 = wb.getCreationHelper().createAreaReference( + new CellReference(0, 0), new CellReference(2, 2)); + + XSSFTable table1 = sheet.createTable(reference1); + table1.setDisplayName("TableTest"); + assertEquals("TableTest", table1.getDisplayName()); + assertEquals("TableTest", table1.getCTTable().getDisplayName()); + } + } + + @Test(expected = IllegalArgumentException.class) + public void testSetDisplayNameNull() throws IOException { + try (XSSFWorkbook wb = new XSSFWorkbook()) { + XSSFSheet sheet = wb.createSheet(); + + AreaReference reference1 = wb.getCreationHelper().createAreaReference( + new CellReference(0, 0), new CellReference(2, 2)); + + XSSFTable table1 = sheet.createTable(reference1); + table1.setDisplayName(null); + } + } + + @Test(expected = IllegalArgumentException.class) + public void testSetDisplayNameEmpty() throws IOException { + try (XSSFWorkbook wb = new XSSFWorkbook()) { + XSSFSheet sheet = wb.createSheet(); + + AreaReference reference1 = wb.getCreationHelper().createAreaReference( + new CellReference(0, 0), new CellReference(2, 2)); + + XSSFTable table1 = sheet.createTable(reference1); + table1.setDisplayName(""); + } + } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org For additional commands, e-mail: commits-help@poi.apache.org