@@ -1209,6 +1209,53 @@ public void testTableInHeaderFooter() {
12091209 }
12101210 }
12111211
1212+ @ Test
1213+ public void testNewTableWithPartialColumnWidth () {
1214+ try {
1215+ OdfTextDocument document =
1216+ OdfTextDocument .loadDocument (
1217+ ResourceUtilities .getAbsoluteInputPath (mOdtTestFileName + ".odt" ));
1218+
1219+ // Create a new table with 1 row, 3 columns, 1 header row, 3 header columns
1220+ OdfTable myTable = OdfTable .newTable (document , 1 , 3 , 1 , 3 );
1221+ Assert .assertNotNull (myTable );
1222+ Assert .assertEquals (1 , myTable .getRowCount ());
1223+ Assert .assertEquals (3 , myTable .getColumnCount ());
1224+ Assert .assertEquals (1 , myTable .getHeaderRowCount ());
1225+ Assert .assertEquals (3 , myTable .getHeaderColumnCount ());
1226+
1227+ // Only set the width for the first 2 columns
1228+ for (int column = 0 ; column < 2 ; column ++) {
1229+ myTable .getColumnByIndex (column ).setWidth (20 );
1230+ }
1231+
1232+ // Verify the widths were set correctly
1233+ Assert .assertEquals (20 , myTable .getColumnByIndex (0 ).getWidth ());
1234+ Assert .assertEquals (20 , myTable .getColumnByIndex (1 ).getWidth ());
1235+
1236+ // Save and reload to verify persistence
1237+ String outputFileName = "TestNewTableWithPartialColumnWidth.odt" ;
1238+ document .save (ResourceUtilities .getTestOutputFile (outputFileName ));
1239+ document .close ();
1240+
1241+ // Reload and verify the table and column widths survived the round-trip
1242+ document =
1243+ OdfTextDocument .loadDocument (
1244+ ResourceUtilities .getAbsoluteOutputPath (outputFileName ));
1245+ List <OdfTable > tableList = document .getTableList (true );
1246+ OdfTable reloadedTable = tableList .get (tableList .size () - 1 );
1247+ Assert .assertNotNull (reloadedTable );
1248+ Assert .assertEquals (1 , reloadedTable .getRowCount ());
1249+ Assert .assertEquals (3 , reloadedTable .getColumnCount ());
1250+ Assert .assertEquals (20 , reloadedTable .getColumnByIndex (0 ).getWidth ());
1251+ Assert .assertEquals (20 , reloadedTable .getColumnByIndex (1 ).getWidth ());
1252+ document .close ();
1253+ } catch (Exception e ) {
1254+ LOG .log (Level .SEVERE , null , e );
1255+ Assert .fail (e .getMessage ());
1256+ }
1257+ }
1258+
12121259 private Map <String , StyleMasterPageElement > getMasterPages (OdfDocument doc ) throws Exception {
12131260
12141261 OdfStylesDom stylesDoc = doc .getStylesDom ();
0 commit comments