Example usage for org.apache.poi.xwpf.usermodel XWPFRun isStrikeThrough

List of usage examples for org.apache.poi.xwpf.usermodel XWPFRun isStrikeThrough

Introduction

In this page you can find the example usage for org.apache.poi.xwpf.usermodel XWPFRun isStrikeThrough.

Prototype

@Override
public boolean isStrikeThrough() 

Source Link

Document

Specifies that the contents of this run shall be displayed with a single horizontal line through the center of the line.

Usage

From source file:offishell.word.WordHeleper.java

License:MIT License

/**
 * <p>/*w  w  w  .  ja  va 2  s  .  co m*/
 * Helper method to clone {@link XWPFRun}.
 * </p>
 * 
 * @param in
 * @param out
 * @param model
 */
public static void copy(XWPFRun in, XWPFRun out, UnaryOperator<String> converter) {
    // copy
    out.setBold(in.isBold());
    out.setCapitalized(in.isCapitalized());
    out.setCharacterSpacing(in.getCharacterSpacing());
    out.setColor(in.getColor());
    out.setDoubleStrikethrough(in.isDoubleStrikeThrough());
    out.setEmbossed(in.isEmbossed());
    out.setFontFamily(in.getFontFamily());
    out.setFontSize(in.getFontSize());
    out.setImprinted(in.isImprinted());
    out.setItalic(in.isItalic());
    out.setKerning(in.getKerning());
    out.setShadow(in.isShadowed());
    out.setSmallCaps(in.isSmallCaps());
    out.setStrikeThrough(in.isStrikeThrough());
    out.setVerticalAlignment(out.getVerticalAlignment().toString());
    out.setTextPosition(in.getTextPosition());
    out.setUnderline(in.getUnderline());

    // copy context
    CTR inCTR = in.getCTR();
    CTRPr inPR = inCTR.getRPr();
    CTR outCTR = out.getCTR();
    CTRPr outPR = outCTR.isSetRPr() ? outCTR.getRPr() : outCTR.addNewRPr();
    outPR.set(inCTR.getRPr());
    out.setVerticalAlignment(
            inPR == null || inPR.getVertAlign() == null ? "baseline" : inPR.getVertAlign().toString());

    // // copy tab
    // CTEmpty[] tabs = inCTR.getTabArray();
    //
    // if (tabs.length != 0) {
    // out.addTab();
    // }
    outCTR.setAnnotationRefArray(inCTR.getAnnotationRefList().toArray(CTEmpty[]::new));
    outCTR.setBrArray(inCTR.getBrList().toArray(CTBr[]::new));
    outCTR.setCommentReferenceArray(inCTR.getCommentReferenceList().toArray(CTMarkup[]::new));
    outCTR.setContinuationSeparatorArray(inCTR.getContinuationSeparatorList().toArray(CTEmpty[]::new));
    outCTR.setCrArray(inCTR.getCrList().toArray(CTEmpty[]::new));
    outCTR.setDelInstrTextArray(inCTR.getDelInstrTextList().toArray(CTText[]::new));
    outCTR.setDrawingArray(inCTR.getDrawingList().toArray(CTDrawing[]::new));
    outCTR.setEndnoteRefArray(inCTR.getEndnoteRefList().toArray(CTEmpty[]::new));
    outCTR.setFldCharArray(inCTR.getFldCharList().toArray(CTFldChar[]::new));
    outCTR.setFootnoteRefArray(inCTR.getFootnoteRefList().toArray(CTEmpty[]::new));
    outCTR.setInstrTextArray(inCTR.getInstrTextList().toArray(CTText[]::new));
    outCTR.setLastRenderedPageBreakArray(inCTR.getLastRenderedPageBreakList().toArray(CTEmpty[]::new));
    outCTR.setObjectArray(inCTR.getObjectList().toArray(CTObject[]::new));
    outCTR.setPictArray(inCTR.getPictList().toArray(CTPicture[]::new));
    outCTR.setPtabArray(inCTR.getPtabList().toArray(CTPTab[]::new));
    outCTR.setSymArray(inCTR.getSymList().toArray(CTSym[]::new));
    outCTR.setTabArray(inCTR.getTabList().toArray(CTEmpty[]::new));

    // copy image
    for (XWPFPicture inPicture : in.getEmbeddedPictures()) {
        try {
            XWPFPictureData inData = inPicture.getPictureData();
            String outId = out.getDocument().addPictureData(new ByteArrayInputStream(inData.getData()),
                    inData.getPictureType());

            select(CTBlip.class, outCTR).to(blip -> blip.setEmbed(outId));
        } catch (Exception e) {
            throw I.quiet(e);
        }
    }

    // copy text
    write(out, converter.apply(in.text()));
}

From source file:org.obeonetwork.m2doc.generator.test.TableClientProcessorWithStyleTest.java

License:Open Source License

@Test
@Override/* ww w.j  ava 2 s .c o  m*/
public void testWithoutAnyParameter() throws ProviderException {
    super.testWithoutAnyParameter();

    // Check styles
    List<XWPFTable> tables = doc.getTables();
    XWPFTable table = tables.get(0);

    // First Row (header)
    XWPFTableRow row = table.getRow(0);

    // Header => no style
    XWPFTableCell cell = row.getCell(1);
    XWPFParagraph cellParagraph = cell.getParagraphs().get(0);
    XWPFRun cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // Header => no style
    cell = row.getCell(2);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // First row
    row = table.getRow(1);

    // first row, row header => no style
    cell = row.getCell(0);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // first row, first cell => cell style
    cell = row.getCell(1);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertEquals(CELL_BG_COLOR, cell.getColor().toUpperCase());
    assertEquals(CELL_FG_COLOR, cellRun.getColor().toUpperCase());
    assertEquals(CELL_FONT_SIZE, cellRun.getFontSize());
    assertTrue(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.SINGLE, cellRun.getUnderline());

    // first row, second cell => row style
    cell = row.getCell(2);
    cellParagraph = cell.getParagraphs().get(0);
    assertEquals(ROW_BG_COLOR, cell.getColor().toUpperCase());
    assertTrue(cellParagraph.getRuns().isEmpty());

    // Second row
    row = table.getRow(2);

    // second row, row header => no style
    cell = row.getCell(0);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // second row, first cell => column style
    cell = row.getCell(1);
    cellParagraph = cell.getParagraphs().get(0);
    assertEquals(COL_BG_COLOR, cell.getColor().toUpperCase());
    assertTrue(cellParagraph.getRuns().isEmpty());

    // second row, second cell => cell style
    cell = row.getCell(2);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertEquals(CELL_BG_COLOR, cell.getColor().toUpperCase());
    assertEquals(CELL_FG_COLOR, cellRun.getColor().toUpperCase());
    assertEquals(CELL_FONT_SIZE, cellRun.getFontSize());
    assertTrue(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.SINGLE, cellRun.getUnderline());
}

From source file:org.obeonetwork.m2doc.tests.generator.TableClientProcessorWithStyleTests.java

License:Open Source License

@Test
@Override/*from  www. jav  a2  s.c o  m*/
public void testWithoutAnyParameter() throws ProviderException {
    super.testWithoutAnyParameter();

    // Check styles
    List<XWPFTable> tables = doc.getTables();
    XWPFTable table = tables.get(0);

    // First Row (header)
    XWPFTableRow row = table.getRow(0);

    // Header => col 1 has "column style"
    XWPFTableCell cell = row.getCell(1);
    XWPFParagraph cellParagraph = cell.getParagraphs().get(0);
    XWPFRun cellRun = cellParagraph.getRuns().get(0);
    assertEquals(COL_BG_COLOR, cell.getColor().toUpperCase());
    assertEquals(COL_FG_COLOR, cellRun.getColor().toUpperCase());
    assertEquals(COL_FONT_SIZE, cellRun.getFontSize());
    assertTrue(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // Header => no style
    cell = row.getCell(2);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // First row
    row = table.getRow(1);

    // first row, row header => no style
    cell = row.getCell(0);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // first row, first cell => cell style
    cell = row.getCell(1);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertEquals(ROW_BG_COLOR, cell.getColor().toUpperCase());
    assertEquals(ROW_FG_COLOR, cellRun.getColor().toUpperCase());
    assertEquals(ROW_FONT_SIZE, cellRun.getFontSize());
    assertFalse(cellRun.isBold());
    assertTrue(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // first row, second cell => no style
    cell = row.getCell(2);
    cellParagraph = cell.getParagraphs().get(0);
    assertNull(cell.getColor());
    cellRun = cellParagraph.getRuns().get(0);
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // Second row
    row = table.getRow(2);

    // second row, row header => no style
    cell = row.getCell(0);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertNull(cell.getColor());
    assertNull(cellRun.getColor());
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // second row, first cell => no style
    cell = row.getCell(1);
    cellParagraph = cell.getParagraphs().get(0);
    assertNull(cell.getColor());
    cellRun = cellParagraph.getRuns().get(0);
    assertFalse(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.NONE, cellRun.getUnderline());

    // second row, second cell => cell style
    cell = row.getCell(2);
    cellParagraph = cell.getParagraphs().get(0);
    cellRun = cellParagraph.getRuns().get(0);
    assertEquals(CELL_BG_COLOR, cell.getColor().toUpperCase());
    assertEquals(CELL_FG_COLOR, cellRun.getColor().toUpperCase());
    assertEquals(CELL_FONT_SIZE, cellRun.getFontSize());
    assertTrue(cellRun.isBold());
    assertFalse(cellRun.isItalic());
    assertFalse(cellRun.isStrikeThrough());
    assertEquals(UnderlinePatterns.SINGLE, cellRun.getUnderline());
}