1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 package fvt.uno.sc.data; 22 23 import static org.junit.Assert.*; 24 25 import org.junit.After; 26 import org.junit.AfterClass; 27 import org.junit.Before; 28 import org.junit.BeforeClass; 29 import org.junit.Ignore; 30 import org.junit.Test; 31 import org.openoffice.test.common.Testspace; 32 import org.openoffice.test.uno.UnoApp; 33 34 import testlib.uno.SCUtil; 35 36 import com.sun.star.beans.XPropertySet; 37 import com.sun.star.lang.XComponent; 38 import com.sun.star.sheet.FilterOperator; 39 import com.sun.star.sheet.TableFilterField; 40 import com.sun.star.sheet.XCellAddressable; 41 import com.sun.star.sheet.XSheetFilterDescriptor; 42 import com.sun.star.sheet.XSheetFilterable; 43 import com.sun.star.sheet.XSpreadsheet; 44 import com.sun.star.sheet.XSpreadsheetDocument; 45 import com.sun.star.table.CellAddress; 46 import com.sun.star.table.CellRangeAddress; 47 import com.sun.star.table.TableOrientation; 48 import com.sun.star.table.XCell; 49 import com.sun.star.table.XCellRange; 50 import com.sun.star.table.XColumnRowRange; 51 import com.sun.star.table.XTableRows; 52 import com.sun.star.text.XTextDocument; 53 import com.sun.star.uno.UnoRuntime; 54 55 public class StandardFilterOption { 56 private static final UnoApp app = new UnoApp(); 57 58 UnoApp unoApp = new UnoApp(); 59 XSpreadsheetDocument scDocument = null; 60 XComponent scComponent = null; 61 private String filename = "FilterTest.xls"; 62 63 @Before 64 public void setUpDocument() throws Exception { 65 unoApp.start(); 66 } 67 68 @After 69 public void tearDownDocument() { 70 unoApp.close(); 71 unoApp.closeDocument(scComponent); 72 73 } 74 75 @BeforeClass 76 public static void setUpConnection() throws Exception { 77 78 } 79 80 @AfterClass 81 public static void tearDownConnection() throws InterruptedException, Exception { 82 83 } 84 85 @Test 86 public void testStandardFilterForString() throws Exception { 87 // Prepare test data 88 String sample = Testspace.prepareData(filename); 89 // Open document 90 scDocument = SCUtil.openFile(sample, unoApp); 91 // Get cell range 92 XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument)); 93 94 // Set filter property and filter the cell range 95 XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime.queryInterface(XSheetFilterable.class, xdataRange.getCellRangeByName("A1:F6")); 96 XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor(true); 97 TableFilterField[] aFilterFields = new TableFilterField[1]; 98 aFilterFields[0] = new TableFilterField(); 99 aFilterFields[0].Field = 0; 100 aFilterFields[0].IsNumeric = false; 101 aFilterFields[0].Operator = FilterOperator.EQUAL; 102 aFilterFields[0].StringValue = "Tom"; 103 xFilterDesc.setFilterFields(aFilterFields); 104 XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFilterDesc); 105 xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true)); 106 xFilter.filter(xFilterDesc); 107 108 // Verify filter result 109 XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6")); 110 XTableRows Rows = ColRowRange.getRows(); 111 for (int i = 0; i < Rows.getCount() - 1; i++) { 112 Object aRowObj = Rows.getByIndex(i); 113 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 114 if (i == 0 | i == 5) { 115 assertTrue("Verify row is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible")); 116 } else 117 assertFalse("Verify row is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible")); 118 } 119 120 // Save and reload the document 121 SCUtil.save(scDocument); 122 SCUtil.closeFile(scDocument); 123 scDocument = SCUtil.openFile(sample, unoApp); 124 125 // Verify the result agains 126 xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument)); 127 ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6")); 128 Rows = ColRowRange.getRows(); 129 for (int i = 0; i < Rows.getCount() - 1; i++) { 130 Object aRowObj = Rows.getByIndex(i); 131 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 132 if (i == 0 | i == 5) { 133 assertTrue("Verify row is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible")); 134 } else 135 assertFalse("Verify row is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible")); 136 } 137 138 } 139 140 @Test 141 public void testStandardFilterOptionCaseSensitive() throws Exception { 142 // Prepare test data 143 String sample = Testspace.prepareData(filename); 144 // Open document 145 scDocument = SCUtil.openFile(sample, unoApp); 146 // Get cell range 147 XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument)); 148 149 // Set filter property and filter the cell range 150 XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime.queryInterface(XSheetFilterable.class, xdataRange.getCellRangeByName("A1:F6")); 151 XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor(true); 152 TableFilterField[] aFilterFields = new TableFilterField[1]; 153 aFilterFields[0] = new TableFilterField(); 154 aFilterFields[0].Field = 5; 155 aFilterFields[0].IsNumeric = false; 156 aFilterFields[0].Operator = FilterOperator.EQUAL; 157 aFilterFields[0].StringValue = "No"; 158 xFilterDesc.setFilterFields(aFilterFields); 159 XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFilterDesc); 160 xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true)); 161 xFilterProp.setPropertyValue("IsCaseSensitive", false); 162 xFilter.filter(xFilterDesc); 163 164 // Verify filter result 165 XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6")); 166 XTableRows Rows = ColRowRange.getRows(); 167 for (int i = 0; i < Rows.getCount() - 1; i++) { 168 Object aRowObj = Rows.getByIndex(i); 169 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 170 if (i == 0 | i == 1 | i == 5) { 171 assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible")); 172 } else 173 assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible")); 174 } 175 176 // Change to CaseSenstive 177 xFilterProp.setPropertyValue("IsCaseSensitive", true); 178 xFilter.filter(xFilterDesc); 179 180 // Verify result 181 for (int i = 0; i < Rows.getCount() - 1; i++) { 182 Object aRowObj = Rows.getByIndex(i); 183 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 184 if (i == 0 | i == 5) { 185 assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible")); 186 } else 187 assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible")); 188 } 189 190 // Save and reload the document 191 SCUtil.save(scDocument); 192 SCUtil.closeFile(scDocument); 193 scDocument = SCUtil.openFile(sample, unoApp); 194 195 // Verify the result again 196 xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument)); 197 ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6")); 198 Rows = ColRowRange.getRows(); 199 for (int i = 0; i < Rows.getCount() - 1; i++) { 200 Object aRowObj = Rows.getByIndex(i); 201 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 202 if (i == 0 | i == 5) { 203 assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible")); 204 } else 205 assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible")); 206 } 207 } 208 209 @Test 210 public void testStandardFilterOptionContainsHeader() throws Exception { 211 // Prepare test data 212 String sample = Testspace.prepareData(filename); 213 // Open document 214 scDocument = SCUtil.openFile(sample, unoApp); 215 // Get cell range 216 XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument)); 217 218 // Set filter property and filter the cell range 219 XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime.queryInterface(XSheetFilterable.class, xdataRange.getCellRangeByName("A1:F6")); 220 XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor(true); 221 TableFilterField[] aFilterFields = new TableFilterField[1]; 222 aFilterFields[0] = new TableFilterField(); 223 aFilterFields[0].Field = 2; 224 aFilterFields[0].IsNumeric = true; 225 aFilterFields[0].Operator = FilterOperator.LESS; 226 aFilterFields[0].NumericValue = 44; 227 xFilterDesc.setFilterFields(aFilterFields); 228 XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFilterDesc); 229 xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true)); 230 xFilter.filter(xFilterDesc); 231 232 // Verify filter result 233 XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6")); 234 XTableRows Rows = ColRowRange.getRows(); 235 for (int i = 0; i < Rows.getCount() - 1; i++) { 236 Object aRowObj = Rows.getByIndex(i); 237 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 238 if (i == 0 | i == 1 | i == 4) { 239 assertTrue("Expect result should be True", (Boolean) PropSet.getPropertyValue("IsVisible")); 240 } else 241 assertFalse("Expect result should be false", (Boolean) PropSet.getPropertyValue("IsVisible")); 242 } 243 244 // Change to not contain header 245 xFilterProp.setPropertyValue("ContainsHeader", new Boolean(false)); 246 xFilter.filter(xFilterDesc); 247 248 // Verify result 249 for (int i = 0; i < Rows.getCount() - 1; i++) { 250 Object aRowObj = Rows.getByIndex(i); 251 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 252 if (i == 1 | i == 4) { 253 assertTrue("Expect result should be True", (Boolean) PropSet.getPropertyValue("IsVisible")); 254 } else 255 assertFalse("Expect result should be false", (Boolean) PropSet.getPropertyValue("IsVisible")); 256 } 257 258 // Save the document 259 SCUtil.save(scDocument); 260 SCUtil.closeFile(scDocument); 261 scDocument = SCUtil.openFile(sample, unoApp); 262 263 // Verify filter result again 264 xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument)); 265 ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6")); 266 Rows = ColRowRange.getRows(); 267 for (int i = 0; i < Rows.getCount() - 1; i++) { 268 Object aRowObj = Rows.getByIndex(i); 269 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 270 if (i == 1 | i == 4) { 271 assertTrue("Expect result should be True", (Boolean) PropSet.getPropertyValue("IsVisible")); 272 } else 273 assertFalse("Expect result should be false", (Boolean) PropSet.getPropertyValue("IsVisible")); 274 } 275 276 } 277 278 @Test 279 @Ignore("Bug #121017") 280 public void testStandardFilterOptionCopyOutput() throws Exception { 281 // Prepare test data 282 String sample = Testspace.prepareData(filename); 283 // Open document 284 scDocument = SCUtil.openFile(sample, unoApp); 285 // Get cell range 286 XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument)); 287 XSpreadsheet currentSheet = SCUtil.getCurrentSheet(scDocument); 288 // Get the value before filter 289 String[][] souce = SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 5); 290 291 // Copy to cell postion 292 XCell cell = currentSheet.getCellByPosition(7, 7); 293 XCellAddressable xCellAddr = (XCellAddressable) UnoRuntime.queryInterface(XCellAddressable.class, cell); 294 CellAddress copytoAddress = xCellAddr.getCellAddress(); 295 296 // Set filter property and filter the cell range 297 XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime.queryInterface(XSheetFilterable.class, xdataRange.getCellRangeByName("A1:F6")); 298 XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor(true); 299 TableFilterField[] aFilterFields = new TableFilterField[1]; 300 aFilterFields[0] = new TableFilterField(); 301 aFilterFields[0].Field = 3; 302 aFilterFields[0].IsNumeric = true; 303 aFilterFields[0].Operator = FilterOperator.GREATER; 304 aFilterFields[0].NumericValue = 155; 305 xFilterDesc.setFilterFields(aFilterFields); 306 XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFilterDesc); 307 xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true)); 308 xFilterProp.setPropertyValue("CopyOutputData", new Boolean(true)); 309 xFilterProp.setPropertyValue("OutputPosition", copytoAddress); 310 xFilter.filter(xFilterDesc); 311 312 // Verify source range not changed 313 XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6")); 314 XTableRows Rows = ColRowRange.getRows(); 315 for (int i = 0; i < Rows.getCount(); i++) { 316 Object aRowObj = Rows.getByIndex(i); 317 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 318 assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible")); 319 } 320 321 // Get the data after filter 322 String[][] dataafterFilter = SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 5); 323 assertArrayEquals(souce, dataafterFilter); 324 325 // Get the copyto filter result, verify it 326 ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("H8:M10")); 327 for (int i = 0; i < Rows.getCount(); i++) { 328 Object aRowObj = Rows.getByIndex(i); 329 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 330 assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible")); 331 } 332 // Verify the first filter line data 333 assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 0), SCUtil.getTextFromCellRange(currentSheet, 7, 7, 12, 7)); 334 335 // Verify the Second filter line data 336 assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 1, 5, 1), SCUtil.getTextFromCellRange(currentSheet, 7, 8, 12, 8)); 337 338 // Verify the Last filter line data 339 assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 4, 5, 4), SCUtil.getTextFromCellRange(currentSheet, 7, 9, 12, 9)); 340 341 // Save the document 342 SCUtil.save(scDocument); 343 SCUtil.closeFile(scDocument); 344 scDocument = SCUtil.openFile(sample, unoApp); 345 346 // Verify filter result again 347 xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument)); 348 ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6")); 349 Rows = ColRowRange.getRows(); 350 for (int i = 0; i < Rows.getCount(); i++) { 351 Object aRowObj = Rows.getByIndex(i); 352 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 353 assertTrue("Expect should be true", (Boolean) PropSet.getPropertyValue("IsVisible")); 354 } 355 356 // Get the data after filter 357 currentSheet = SCUtil.getCurrentSheet(scDocument); 358 dataafterFilter = SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 5); 359 assertArrayEquals(souce, dataafterFilter); 360 361 // Get the copyto filter result, verify it 362 ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("H8:M10")); 363 for (int i = 0; i < Rows.getCount(); i++) { 364 Object aRowObj = Rows.getByIndex(i); 365 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 366 assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible")); 367 } 368 // Verify the first filter line data 369 assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 0, 5, 0), SCUtil.getTextFromCellRange(currentSheet, 7, 7, 12, 7)); 370 371 // Verify the Second filter line data 372 assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 1, 5, 1), SCUtil.getTextFromCellRange(currentSheet, 7, 8, 12, 8)); 373 374 // Verify the Last filter line data 375 assertArrayEquals(SCUtil.getTextFromCellRange(currentSheet, 0, 4, 5, 4), SCUtil.getTextFromCellRange(currentSheet, 7, 9, 12, 9)); 376 } 377 378 @Test 379 public void testStandardFilterOptionSkipDuplicates() throws Exception { 380 // Prepare test data 381 String sample = Testspace.prepareData(filename); 382 // Open document 383 scDocument = SCUtil.openFile(sample, unoApp); 384 // Get cell range 385 XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument)); 386 387 // Set filter property and filter the cell range 388 XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime.queryInterface(XSheetFilterable.class, xdataRange.getCellRangeByName("A1:E6")); 389 XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor(true); 390 TableFilterField[] aFilterFields = new TableFilterField[1]; 391 aFilterFields[0] = new TableFilterField(); 392 aFilterFields[0].Field = 3; 393 aFilterFields[0].IsNumeric = true; 394 aFilterFields[0].Operator = FilterOperator.GREATER_EQUAL; 395 aFilterFields[0].NumericValue = 155; 396 xFilterDesc.setFilterFields(aFilterFields); 397 XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFilterDesc); 398 xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true)); 399 xFilterProp.setPropertyValue("SkipDuplicates", new Boolean(true)); 400 xFilter.filter(xFilterDesc); 401 402 // Verify filter result 403 XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6")); 404 XTableRows Rows = ColRowRange.getRows(); 405 for (int i = 0; i < Rows.getCount(); i++) { 406 Object aRowObj = Rows.getByIndex(i); 407 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 408 if (i == 2) { 409 assertFalse("Verify row is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible")); 410 } else 411 assertTrue("Verify row is invisible.", (Boolean) PropSet.getPropertyValue("IsVisible")); 412 } 413 414 // Change to skip Dulicates 415 xFilterProp.setPropertyValue("SkipDuplicates", new Boolean(false)); 416 xFilter.filter(xFilterDesc); 417 418 // Verify filter result 419 ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6")); 420 Rows = ColRowRange.getRows(); 421 for (int i = 0; i < Rows.getCount(); i++) { 422 Object aRowObj = Rows.getByIndex(i); 423 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 424 if (i == 2 | i == 6) { 425 assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible")); 426 } else 427 assertTrue("Expect should be True", (Boolean) PropSet.getPropertyValue("IsVisible")); 428 } 429 430 // Save the document 431 SCUtil.save(scDocument); 432 SCUtil.closeFile(scDocument); 433 scDocument = SCUtil.openFile(sample, unoApp); 434 435 // Verify filter result again 436 xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument)); 437 ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:E6")); 438 Rows = ColRowRange.getRows(); 439 for (int i = 0; i < Rows.getCount() - 1; i++) { 440 Object aRowObj = Rows.getByIndex(i); 441 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 442 if (i == 2 | i == 6) { 443 assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible")); 444 } else 445 assertTrue("Expect should be true", (Boolean) PropSet.getPropertyValue("IsVisible")); 446 } 447 448 } 449 450 @Test 451 public void testStandardFilterOptionUseRegularExpressions() throws Exception { 452 // Prepare test data 453 String sample = Testspace.prepareData(filename); 454 // Open document 455 scDocument = SCUtil.openFile(sample, unoApp); 456 // Get cell range 457 XCellRange xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument)); 458 459 // Set filter property and filter the cell range 460 XSheetFilterable xFilter = (XSheetFilterable) UnoRuntime.queryInterface(XSheetFilterable.class, xdataRange.getCellRangeByName("A1:F6")); 461 XSheetFilterDescriptor xFilterDesc = xFilter.createFilterDescriptor(true); 462 TableFilterField[] aFilterFields = new TableFilterField[1]; 463 aFilterFields[0] = new TableFilterField(); 464 aFilterFields[0].Field = 0; 465 aFilterFields[0].IsNumeric = false; 466 aFilterFields[0].Operator = FilterOperator.EQUAL; 467 aFilterFields[0].StringValue = "^.{3}$"; 468 xFilterDesc.setFilterFields(aFilterFields); 469 XPropertySet xFilterProp = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xFilterDesc); 470 xFilterProp.setPropertyValue("ContainsHeader", new Boolean(true)); 471 xFilterProp.setPropertyValue("UseRegularExpressions", new Boolean(true)); 472 xFilter.filter(xFilterDesc); 473 474 // Verify filter result 475 XColumnRowRange ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6")); 476 XTableRows Rows = ColRowRange.getRows(); 477 for (int i = 0; i < Rows.getCount(); i++) { 478 Object aRowObj = Rows.getByIndex(i); 479 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 480 if (i == 2 | i == 4) { 481 assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible")); 482 } else 483 assertTrue("Expect should be true", (Boolean) PropSet.getPropertyValue("IsVisible")); 484 } 485 486 // Save the document 487 SCUtil.save(scDocument); 488 SCUtil.closeFile(scDocument); 489 scDocument = SCUtil.openFile(sample, unoApp); 490 491 // Verify filter result again 492 xdataRange = (XCellRange) UnoRuntime.queryInterface(XCellRange.class, SCUtil.getCurrentSheet(scDocument)); 493 ColRowRange = (XColumnRowRange) UnoRuntime.queryInterface(XColumnRowRange.class, xdataRange.getCellRangeByName("A1:F6")); 494 Rows = ColRowRange.getRows(); 495 for (int i = 0; i < Rows.getCount(); i++) { 496 Object aRowObj = Rows.getByIndex(i); 497 XPropertySet PropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, aRowObj); 498 if (i == 2 | i == 4) { 499 assertFalse("Expect should be false", (Boolean) PropSet.getPropertyValue("IsVisible")); 500 } else 501 assertTrue("Expect should be true", (Boolean) PropSet.getPropertyValue("IsVisible")); 502 } 503 504 } 505 506 } 507