Lines 22-33
Link Here
|
22 |
import static org.junit.Assert.*; |
22 |
import static org.junit.Assert.*; |
23 |
|
23 |
|
24 |
import java.io.IOException; |
24 |
import java.io.IOException; |
|
|
25 |
import java.util.Calendar; |
26 |
import java.util.Date; |
27 |
import java.util.GregorianCalendar; |
25 |
import java.util.Iterator; |
28 |
import java.util.Iterator; |
26 |
|
29 |
|
27 |
import org.apache.poi.hssf.util.PaneInformation; |
30 |
import org.apache.poi.hssf.util.PaneInformation; |
28 |
import org.apache.poi.ss.ITestDataProvider; |
31 |
import org.apache.poi.ss.ITestDataProvider; |
29 |
import org.apache.poi.ss.SpreadsheetVersion; |
32 |
import org.apache.poi.ss.SpreadsheetVersion; |
30 |
import org.apache.poi.ss.util.CellRangeAddress; |
33 |
import org.apache.poi.ss.util.CellRangeAddress; |
|
|
34 |
import org.apache.poi.ss.util.CellReference; |
35 |
import org.apache.poi.ss.util.CellUtil; |
31 |
import org.junit.Rule; |
36 |
import org.junit.Rule; |
32 |
import org.junit.Test; |
37 |
import org.junit.Test; |
33 |
import org.junit.rules.ExpectedException; |
38 |
import org.junit.rules.ExpectedException; |
Lines 348-354
Link Here
|
348 |
region = sheet.getMergedRegion(0); |
353 |
region = sheet.getMergedRegion(0); |
349 |
assertEquals("Merged region not moved over to row 2", 2, region.getFirstRow()); |
354 |
assertEquals("Merged region not moved over to row 2", 2, region.getFirstRow()); |
350 |
} |
355 |
} |
|
|
356 |
|
357 |
protected void baseTestCopyOneRow(String copyRowsTestWorkbook) throws IOException { |
358 |
final double FLOAT_PRECISION = 1e-9; |
359 |
final Workbook workbook = _testDataProvider.openSampleWorkbook(copyRowsTestWorkbook); |
360 |
final Sheet sheet = workbook.getSheetAt(0); |
361 |
final CellCopyPolicy defaultCopyPolicy = new CellCopyPolicy(); |
362 |
sheet.copyRows(1, 1, 6, defaultCopyPolicy); |
351 |
|
363 |
|
|
|
364 |
final Row srcRow = sheet.getRow(1); |
365 |
final Row destRow = sheet.getRow(6); |
366 |
int col = 0; |
367 |
Cell cell; |
368 |
|
369 |
cell = CellUtil.getCell(destRow, col++); |
370 |
assertEquals("Source row ->", cell.getStringCellValue()); |
371 |
|
372 |
// Style |
373 |
cell = CellUtil.getCell(destRow, col++); |
374 |
assertEquals("[Style] B7 cell value", "Red", cell.getStringCellValue()); |
375 |
assertEquals("[Style] B7 cell style", CellUtil.getCell(srcRow, 1).getCellStyle(), cell.getCellStyle()); |
376 |
|
377 |
// Blank |
378 |
cell = CellUtil.getCell(destRow, col++); |
379 |
assertEquals("[Blank] C7 cell type", Cell.CELL_TYPE_BLANK, cell.getCellType()); |
380 |
|
381 |
// Error |
382 |
cell = CellUtil.getCell(destRow, col++); |
383 |
assertEquals("[Error] D7 cell type", Cell.CELL_TYPE_ERROR, cell.getCellType()); |
384 |
final FormulaError error = FormulaError.forInt(cell.getErrorCellValue()); |
385 |
assertEquals("[Error] D7 cell value", FormulaError.NA, error); //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here |
386 |
|
387 |
// Date |
388 |
cell = CellUtil.getCell(destRow, col++); |
389 |
assertEquals("[Date] E7 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType()); |
390 |
final Date date = new GregorianCalendar(2000, Calendar.JANUARY, 1).getTime(); |
391 |
assertEquals("[Date] E7 cell value", date, cell.getDateCellValue()); |
392 |
|
393 |
// Boolean |
394 |
cell = CellUtil.getCell(destRow, col++); |
395 |
assertEquals("[Boolean] F7 cell type", Cell.CELL_TYPE_BOOLEAN, cell.getCellType()); |
396 |
assertEquals("[Boolean] F7 cell value", true, cell.getBooleanCellValue()); |
397 |
|
398 |
// String |
399 |
cell = CellUtil.getCell(destRow, col++); |
400 |
assertEquals("[String] G7 cell type", Cell.CELL_TYPE_STRING, cell.getCellType()); |
401 |
assertEquals("[String] G7 cell value", "Hello", cell.getStringCellValue()); |
402 |
|
403 |
// Int |
404 |
cell = CellUtil.getCell(destRow, col++); |
405 |
assertEquals("[Int] H7 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType()); |
406 |
assertEquals("[Int] H7 cell value", 15, (int) cell.getNumericCellValue()); |
407 |
|
408 |
// Float |
409 |
cell = CellUtil.getCell(destRow, col++); |
410 |
assertEquals("[Float] I7 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType()); |
411 |
assertEquals("[Float] I7 cell value", 12.5, cell.getNumericCellValue(), FLOAT_PRECISION); |
412 |
|
413 |
// Cell Formula |
414 |
cell = CellUtil.getCell(destRow, col++); |
415 |
assertEquals("J7", new CellReference(cell).formatAsString()); |
416 |
assertEquals("[Cell Formula] J7 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
417 |
assertEquals("[Cell Formula] J7 cell formula", "5+2", cell.getCellFormula()); |
418 |
System.out.println("Cell formula evaluation currently unsupported"); |
419 |
//assertEquals("[Cell Formula] J7 cell value", 7.0, cell.getNumericCellValue(), FLOAT_PRECISION); |
420 |
|
421 |
// Cell Formula with Reference |
422 |
// Formula row references should be adjusted by destRowNum-srcRowNum |
423 |
cell = CellUtil.getCell(destRow, col++); |
424 |
assertEquals("K7", new CellReference(cell).formatAsString()); |
425 |
assertEquals("[Cell Formula with Reference] K7 cell type", |
426 |
Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
427 |
assertEquals("[Cell Formula with Reference] K7 cell formula", |
428 |
"J7+H$2", cell.getCellFormula()); |
429 |
//assertEquals("[Cell Formula with Reference] J7 cell value", |
430 |
// 22.0, cell.getNumericCellValue(), FLOAT_PRECISION); |
431 |
|
432 |
// Cell Formula with Reference spanning multiple rows |
433 |
cell = CellUtil.getCell(destRow, col++); |
434 |
assertEquals("[Cell Formula with Reference spanning multiple rows] L7 cell type", |
435 |
Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
436 |
assertEquals("[Cell Formula with Reference spanning multiple rows] L7 cell formula", |
437 |
"G7&\" \"&G8", cell.getCellFormula()); |
438 |
//assertEquals("[Cell Formula with Reference spanning multiple rows] L7 cell value", |
439 |
// "World ", cell.getStringCellValue()); |
440 |
|
441 |
// Cell Formula with Reference spanning multiple rows |
442 |
cell = CellUtil.getCell(destRow, col++); |
443 |
assertEquals("[Cell Formula with Area Reference] M7 cell type", |
444 |
Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
445 |
assertEquals("[Cell Formula with Area Reference] M7 cell formula", |
446 |
"SUM(H7:I8)", cell.getCellFormula()); |
447 |
//assertEquals("[Cell Formula with Area Reference] M7 cell value", |
448 |
// "75", cell.getStringCellValue()); |
449 |
|
450 |
// Array Formula |
451 |
cell = CellUtil.getCell(destRow, col++); |
452 |
System.out.println("Array formulas currently unsupported"); |
453 |
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula() |
454 |
/* |
455 |
assertEquals("[Array Formula] N7 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
456 |
assertEquals("[Array Formula] N7 cell formula", "{SUM(H7:J7*{1,2,3})}", cell.getCellFormula()); |
457 |
*/ |
458 |
// Formula should be evaluated |
459 |
//assertEquals("[Array Formula] N7 cell value", 61.0, cell.getNumericCellValue(), FLOAT_PRECISION); |
460 |
|
461 |
// Data Format |
462 |
cell = CellUtil.getCell(destRow, col++); |
463 |
assertEquals("[Data Format] O7 cell type;", Cell.CELL_TYPE_NUMERIC, cell.getCellType()); |
464 |
assertEquals("[Data Format] O7 cell value", 100.20, cell.getNumericCellValue(), FLOAT_PRECISION); |
465 |
//FIXME: currently fails |
466 |
final String moneyFormat = "\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)"; |
467 |
assertEquals("[Data Format] O7 data format", moneyFormat, cell.getCellStyle().getDataFormatString()); |
468 |
|
469 |
// Merged |
470 |
cell = CellUtil.getCell(destRow, col); |
471 |
assertEquals("[Merged] P7:Q7 cell value", |
472 |
"Merged cells", cell.getStringCellValue()); |
473 |
assertTrue("[Merged] P7:Q7 merged region", |
474 |
sheet.getMergedRegions().contains(CellRangeAddress.valueOf("P7:Q7"))); |
475 |
|
476 |
// Merged across multiple rows |
477 |
// Microsoft Excel 2013 does not copy a merged region unless all rows of |
478 |
// the source merged region are selected |
479 |
// POI's behavior should match this behavior |
480 |
col += 2; |
481 |
cell = CellUtil.getCell(destRow, col); |
482 |
// Note: this behavior deviates from Microsoft Excel, |
483 |
// which will not overwrite a cell in destination row if merged region extends beyond the copied row. |
484 |
// The Excel way would require: |
485 |
//assertEquals("[Merged across multiple rows] R7:S8 merged region", "Should NOT be overwritten", cell.getStringCellValue()); |
486 |
//assertFalse("[Merged across multiple rows] R7:S8 merged region", |
487 |
// sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R7:S8"))); |
488 |
// As currently implemented, cell value is copied but merged region is not copied |
489 |
assertEquals("[Merged across multiple rows] R7:S8 cell value", |
490 |
"Merged cells across multiple rows", cell.getStringCellValue()); |
491 |
assertFalse("[Merged across multiple rows] R7:S7 merged region (one row)", |
492 |
sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R7:S7"))); //shouldn't do 1-row merge |
493 |
assertFalse("[Merged across multiple rows] R7:S8 merged region", |
494 |
sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R7:S8"))); //shouldn't do 2-row merge |
495 |
|
496 |
// Make sure other rows are blank (off-by-one errors) |
497 |
assertNull(sheet.getRow(5)); |
498 |
assertNull(sheet.getRow(7)); |
499 |
} |
500 |
|
501 |
public void baseTestCopyMultipleRows(String copyRowsTestWorkbook) throws IOException { |
502 |
final double FLOAT_PRECISION = 1e-9; |
503 |
final Workbook workbook = _testDataProvider.openSampleWorkbook(copyRowsTestWorkbook); |
504 |
final Sheet sheet = workbook.getSheetAt(0); |
505 |
final CellCopyPolicy defaultCopyPolicy = new CellCopyPolicy(); |
506 |
sheet.copyRows(0, 3, 8, defaultCopyPolicy); |
507 |
|
508 |
final Row srcHeaderRow = sheet.getRow(0); |
509 |
final Row srcRow1 = sheet.getRow(1); |
510 |
final Row srcRow2 = sheet.getRow(2); |
511 |
final Row srcRow3 = sheet.getRow(3); |
512 |
final Row destHeaderRow = sheet.getRow(8); |
513 |
final Row destRow1 = sheet.getRow(9); |
514 |
final Row destRow2 = sheet.getRow(10); |
515 |
final Row destRow3 = sheet.getRow(11); |
516 |
int col = 0; |
517 |
Cell cell; |
518 |
|
519 |
// Header row should be copied |
520 |
assertNotNull(destHeaderRow); |
521 |
|
522 |
// Data rows |
523 |
cell = CellUtil.getCell(destRow1, col); |
524 |
assertEquals("Source row ->", cell.getStringCellValue()); |
525 |
|
526 |
// Style |
527 |
col++; |
528 |
cell = CellUtil.getCell(destRow1, col); |
529 |
assertEquals("[Style] B10 cell value", "Red", cell.getStringCellValue()); |
530 |
assertEquals("[Style] B10 cell style", CellUtil.getCell(srcRow1, 1).getCellStyle(), cell.getCellStyle()); |
531 |
|
532 |
cell = CellUtil.getCell(destRow2, col); |
533 |
assertEquals("[Style] B11 cell value", "Blue", cell.getStringCellValue()); |
534 |
assertEquals("[Style] B11 cell style", CellUtil.getCell(srcRow2, 1).getCellStyle(), cell.getCellStyle()); |
535 |
|
536 |
// Blank |
537 |
col++; |
538 |
cell = CellUtil.getCell(destRow1, col); |
539 |
assertEquals("[Blank] C10 cell type", Cell.CELL_TYPE_BLANK, cell.getCellType()); |
540 |
|
541 |
cell = CellUtil.getCell(destRow2, col); |
542 |
assertEquals("[Blank] C11 cell type", Cell.CELL_TYPE_BLANK, cell.getCellType()); |
543 |
|
544 |
// Error |
545 |
col++; |
546 |
cell = CellUtil.getCell(destRow1, col); |
547 |
assertEquals("[Error] D10 cell type", Cell.CELL_TYPE_ERROR, cell.getCellType()); |
548 |
FormulaError error = FormulaError.forInt(cell.getErrorCellValue()); |
549 |
assertEquals("[Error] D10 cell value", FormulaError.NA, error); //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here |
550 |
|
551 |
cell = CellUtil.getCell(destRow2, col); |
552 |
assertEquals("[Error] D11 cell type", Cell.CELL_TYPE_ERROR, cell.getCellType()); |
553 |
error = FormulaError.forInt(cell.getErrorCellValue()); |
554 |
assertEquals("[Error] D11 cell value", FormulaError.NAME, error); //FIXME: XSSFCell and HSSFCell expose different interfaces. getErrorCellString would be helpful here |
555 |
|
556 |
// Date |
557 |
col++; |
558 |
cell = CellUtil.getCell(destRow1, col); |
559 |
assertEquals("[Date] E10 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType()); |
560 |
Date date = new GregorianCalendar(2000, Calendar.JANUARY, 1).getTime(); |
561 |
assertEquals("[Date] E10 cell value", date, cell.getDateCellValue()); |
562 |
|
563 |
cell = CellUtil.getCell(destRow2, col); |
564 |
assertEquals("[Date] E11 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType()); |
565 |
date = new GregorianCalendar(2000, Calendar.JANUARY, 2).getTime(); |
566 |
assertEquals("[Date] E11 cell value", date, cell.getDateCellValue()); |
567 |
|
568 |
// Boolean |
569 |
col++; |
570 |
cell = CellUtil.getCell(destRow1, col); |
571 |
assertEquals("[Boolean] F10 cell type", Cell.CELL_TYPE_BOOLEAN, cell.getCellType()); |
572 |
assertEquals("[Boolean] F10 cell value", true, cell.getBooleanCellValue()); |
573 |
|
574 |
cell = CellUtil.getCell(destRow2, col); |
575 |
assertEquals("[Boolean] F11 cell type", Cell.CELL_TYPE_BOOLEAN, cell.getCellType()); |
576 |
assertEquals("[Boolean] F11 cell value", false, cell.getBooleanCellValue()); |
577 |
|
578 |
// String |
579 |
col++; |
580 |
cell = CellUtil.getCell(destRow1, col); |
581 |
assertEquals("[String] G10 cell type", Cell.CELL_TYPE_STRING, cell.getCellType()); |
582 |
assertEquals("[String] G10 cell value", "Hello", cell.getStringCellValue()); |
583 |
|
584 |
cell = CellUtil.getCell(destRow2, col); |
585 |
assertEquals("[String] G11 cell type", Cell.CELL_TYPE_STRING, cell.getCellType()); |
586 |
assertEquals("[String] G11 cell value", "World", cell.getStringCellValue()); |
587 |
|
588 |
// Int |
589 |
col++; |
590 |
cell = CellUtil.getCell(destRow1, col); |
591 |
assertEquals("[Int] H10 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType()); |
592 |
assertEquals("[Int] H10 cell value", 15, (int) cell.getNumericCellValue()); |
593 |
|
594 |
cell = CellUtil.getCell(destRow2, col); |
595 |
assertEquals("[Int] H11 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType()); |
596 |
assertEquals("[Int] H11 cell value", 42, (int) cell.getNumericCellValue()); |
597 |
|
598 |
// Float |
599 |
col++; |
600 |
cell = CellUtil.getCell(destRow1, col); |
601 |
assertEquals("[Float] I10 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType()); |
602 |
assertEquals("[Float] I10 cell value", 12.5, cell.getNumericCellValue(), FLOAT_PRECISION); |
603 |
|
604 |
cell = CellUtil.getCell(destRow2, col); |
605 |
assertEquals("[Float] I11 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType()); |
606 |
assertEquals("[Float] I11 cell value", 5.5, cell.getNumericCellValue(), FLOAT_PRECISION); |
607 |
|
608 |
// Cell Formula |
609 |
col++; |
610 |
cell = CellUtil.getCell(destRow1, col); |
611 |
assertEquals("[Cell Formula] J10 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
612 |
assertEquals("[Cell Formula] J10 cell formula", "5+2", cell.getCellFormula()); |
613 |
// FIXME: formula evaluation |
614 |
System.out.println("Cell formula evaluation currently unsupported"); |
615 |
//assertEquals(7.0, cell.getNumericCellValue(), FLOAT_PRECISION); |
616 |
|
617 |
cell = CellUtil.getCell(destRow2, col); |
618 |
assertEquals("[Cell Formula] J11 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
619 |
assertEquals("[Cell Formula] J11 cell formula", "6+18", cell.getCellFormula()); |
620 |
// FIXME: formula evaluation |
621 |
//assertEquals("[Cell Formula] J11 cell formula result", 24.0, cell.getNumericCellValue(), FLOAT_PRECISION); |
622 |
|
623 |
// Cell Formula with Reference |
624 |
col++; |
625 |
// Formula row references should be adjusted by destRowNum-srcRowNum |
626 |
cell = CellUtil.getCell(destRow1, col); |
627 |
assertEquals("[Cell Formula with Reference] K10 cell type", |
628 |
Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
629 |
assertEquals("[Cell Formula with Reference] K10 cell formula", |
630 |
"J10+H$2", cell.getCellFormula()); |
631 |
// FIXME: formula evaluation |
632 |
//assertEquals("[Cell Formula with Reference] K10 cell formula result", |
633 |
// 22.0, cell.getNumericCellValue(), FLOAT_PRECISION); |
634 |
|
635 |
cell = CellUtil.getCell(destRow2, col); |
636 |
assertEquals("[Cell Formula with Reference] K11 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
637 |
assertEquals("[Cell Formula with Reference] K11 cell formula", "J11+H$2", cell.getCellFormula()); |
638 |
// FIXME: formula evaluation |
639 |
//assertEquals("[Cell Formula with Reference] K11 cell formula result", |
640 |
// 39.0, cell.getNumericCellValue(), FLOAT_PRECISION); |
641 |
|
642 |
// Cell Formula with Reference spanning multiple rows |
643 |
col++; |
644 |
cell = CellUtil.getCell(destRow1, col); |
645 |
assertEquals("[Cell Formula with Reference spanning multiple rows] L10 cell type", |
646 |
Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
647 |
assertEquals("[Cell Formula with Reference spanning multiple rows] L10 cell formula", |
648 |
"G10&\" \"&G11", cell.getCellFormula()); |
649 |
// FIXME: Formula should be evaluated |
650 |
//assertEquals("[Cell Formula with Reference spanning multiple rows] L11 cell formula result", |
651 |
// "Hello World", cell.getStringCellValue()); |
652 |
|
653 |
cell = CellUtil.getCell(destRow2, col); |
654 |
assertEquals("[Cell Formula with Reference spanning multiple rows] L11 cell type", |
655 |
Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
656 |
assertEquals("[Cell Formula with Reference spanning multiple rows] L11 cell formula", |
657 |
"G11&\" \"&G12", cell.getCellFormula()); |
658 |
// FIXME: Formula should be evaluated |
659 |
//assertEquals("[Cell Formula with Reference spanning multiple rows] L11 cell formula result", |
660 |
// "World ", cell.getStringCellValue()); |
661 |
|
662 |
// Cell Formula with Area Reference |
663 |
col++; |
664 |
cell = CellUtil.getCell(destRow1, col); |
665 |
assertEquals("[Cell Formula with Area Reference] M10 cell type", |
666 |
Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
667 |
assertEquals("[Cell Formula with Area Reference] M10 cell formula", |
668 |
"SUM(H10:I11)", cell.getCellFormula()); |
669 |
// FIXME: Formula should be evaluated |
670 |
//assertEquals("[Cell Formula with Area Reference] M10 cell formula result", |
671 |
// "Hello World", cell.getStringCellValue()); |
672 |
|
673 |
cell = CellUtil.getCell(destRow2, col); |
674 |
assertEquals("[Cell Formula with Area Reference] M11 cell type", |
675 |
Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
676 |
assertEquals("[Cell Formula with Area Reference] M11 cell formula", |
677 |
"SUM($H$3:I10)", cell.getCellFormula()); //Also acceptable: SUM($H10:I$3), but this AreaReference isn't in ascending order |
678 |
// FIXME: Formula should be evaluated |
679 |
//assertEquals("[Cell Formula with Area Reference] M11 cell formula result", |
680 |
// "World ", cell.getStringCellValue()); |
681 |
|
682 |
// Array Formula |
683 |
col++; |
684 |
cell = CellUtil.getCell(destRow1, col); |
685 |
System.out.println("Array formulas currently unsupported"); |
686 |
/* |
687 |
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula() |
688 |
assertEquals("[Array Formula] N10 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
689 |
assertEquals("[Array Formula] N10 cell formula", "{SUM(H10:J10*{1,2,3})}", cell.getCellFormula()); |
690 |
// FIXME: Formula should be evaluated |
691 |
assertEquals("[Array Formula] N10 cell formula result", 61.0, cell.getNumericCellValue(), FLOAT_PRECISION); |
692 |
|
693 |
cell = CellUtil.getCell(destRow2, col); |
694 |
// FIXME: Array Formula set with Sheet.setArrayFormula() instead of cell.setFormula() |
695 |
assertEquals("[Array Formula] N11 cell type", Cell.CELL_TYPE_FORMULA, cell.getCellType()); |
696 |
assertEquals("[Array Formula] N11 cell formula", "{SUM(H11:J11*{1,2,3})}", cell.getCellFormula()); |
697 |
// FIXME: Formula should be evaluated |
698 |
assertEquals("[Array Formula] N11 cell formula result", 125.0, cell.getNumericCellValue(), FLOAT_PRECISION); |
699 |
*/ |
700 |
|
701 |
// Data Format |
702 |
col++; |
703 |
cell = CellUtil.getCell(destRow2, col); |
704 |
assertEquals("[Data Format] O10 cell type", Cell.CELL_TYPE_NUMERIC, cell.getCellType()); |
705 |
assertEquals("[Data Format] O10 cell value", 100.20, cell.getNumericCellValue(), FLOAT_PRECISION); |
706 |
final String moneyFormat = "\"$\"#,##0.00_);[Red]\\(\"$\"#,##0.00\\)"; |
707 |
assertEquals("[Data Format] O10 cell data format", moneyFormat, cell.getCellStyle().getDataFormatString()); |
708 |
|
709 |
// Merged |
710 |
col++; |
711 |
cell = CellUtil.getCell(destRow1, col); |
712 |
assertEquals("[Merged] P10:Q10 cell value", |
713 |
"Merged cells", cell.getStringCellValue()); |
714 |
assertTrue("[Merged] P10:Q10 merged region", |
715 |
sheet.getMergedRegions().contains(CellRangeAddress.valueOf("P10:Q10"))); |
716 |
|
717 |
cell = CellUtil.getCell(destRow2, col); |
718 |
assertEquals("[Merged] P11:Q11 cell value", "Merged cells", cell.getStringCellValue()); |
719 |
assertTrue("[Merged] P11:Q11 merged region", |
720 |
sheet.getMergedRegions().contains(CellRangeAddress.valueOf("P11:Q11"))); |
721 |
|
722 |
// Should Q10/Q11 be checked? |
723 |
|
724 |
// Merged across multiple rows |
725 |
// Microsoft Excel 2013 does not copy a merged region unless all rows of |
726 |
// the source merged region are selected |
727 |
// POI's behavior should match this behavior |
728 |
col += 2; |
729 |
cell = CellUtil.getCell(destRow1, col); |
730 |
assertEquals("[Merged across multiple rows] R10:S11 cell value", |
731 |
"Merged cells across multiple rows", cell.getStringCellValue()); |
732 |
assertTrue("[Merged across multiple rows] R10:S11 merged region", |
733 |
sheet.getMergedRegions().contains(CellRangeAddress.valueOf("R10:S11"))); |
734 |
|
735 |
// Row 3 (zero-based) was empty, so Row 11 (zero-based) should be empty too. |
736 |
if (srcRow3 == null) { |
737 |
assertNull("Row 3 was empty, so Row 11 should be empty", destRow3); |
738 |
} |
739 |
|
740 |
// Make sure other rows are blank (off-by-one errors) |
741 |
assertNull("Off-by-one lower edge case", sheet.getRow(7)); //one row above destHeaderRow |
742 |
assertNull("Off-by-one upper edge case", sheet.getRow(12)); //one row below destRow3 |
743 |
} |
744 |
|
352 |
/** |
745 |
/** |
353 |
* Tests the display of gridlines, formulas, and rowcolheadings. |
746 |
* Tests the display of gridlines, formulas, and rowcolheadings. |
354 |
* @author Shawn Laubach (slaubach at apache dot org) |
747 |
* @author Shawn Laubach (slaubach at apache dot org) |
Lines 996-999
Link Here
|
996 |
|
1389 |
|
997 |
wb.close(); |
1390 |
wb.close(); |
998 |
} |
1391 |
} |
|
|
1392 |
|
1393 |
|
999 |
} |
1394 |
} |