package org.apache.poi.ss.tests.util;
+import org.apache.poi.ss.usermodel.RichTextString;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.util.BaseTestCellUtilCopy;
+import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class TestXSSFCellUtilCopy extends BaseTestCellUtilCopy {
protected Workbook createNewWorkbook() {
return new XSSFWorkbook();
}
+
+ @Override
+ protected boolean compareRichText(RichTextString rts1, RichTextString rts2) {
+ if (rts1 instanceof XSSFRichTextString && rts2 instanceof XSSFRichTextString) {
+ XSSFRichTextString xrts1 = (XSSFRichTextString)rts1;
+ XSSFRichTextString xrts2 = (XSSFRichTextString)rts2;
+ return xrts1.getCTRst().xmlText().equals(xrts2.getCTRst().xmlText());
+ } else {
+ return super.compareRichText(rts1, rts2);
+ }
+ }
}
assertEquals(CellType.NUMERIC, destCell.getCellType());
}
+ @Test
+ public final void testCopyCellFrom_CellCopyPolicy_richTextValue() {
+ setUp_testCopyCellFrom_CellCopyPolicy();
+ Workbook wb = srcCell.getSheet().getWorkbook();
+ CreationHelper creationHelper = wb.getCreationHelper();
+ RichTextString rts = creationHelper.createRichTextString("text 123");
+ Font font = wb.createFont();
+ font.setFontHeight((short) 999);
+ font.setFontName("Muriel");
+ rts.applyFont(0, 3, font);
+ srcCell.setCellFormula(null);
+ srcCell.setCellValue(rts);
+
+ // Paste values only
+ final CellCopyPolicy policy = new CellCopyPolicy.Builder().cellFormula(false).build();
+ CellUtil.copyCell(srcCell, destCell, policy, new CellCopyContext());
+ assertEquals(CellType.STRING, destCell.getCellType());
+ assertTrue(compareRichText(rts, destCell.getRichStringCellValue()));
+ }
+
@Test
public final void testCopyCellFrom_CellCopyPolicy_formulaWithUnregisteredUDF() {
setUp_testCopyCellFrom_CellCopyPolicy();
protected abstract Workbook createNewWorkbook();
+ protected boolean compareRichText(RichTextString rts1, RichTextString rts2) {
+ return rts1.getString().equals(rts2.getString());
+ }
}