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

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

Introduction

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

Prototype

@Override
public boolean isBold() 

Source Link

Document

Whether the bold property shall be applied to all non-complex script characters in the contents of this run when displayed in a document

Usage

From source file:apachepoitest.DocumentPropertyChecker.java

public static Boolean checkIfRunHasProperty(XWPFRun r, String property, String value) {
    try {/*  w  ww .  j av a  2s  . co  m*/
        switch (property) {
        case "COLOR":
            return r.getColor().equals(value);
        case "FONT FAMILY":
            return r.getFontFamily().equalsIgnoreCase(value);
        case "FONT SIZE":
            return r.getFontSize() == Integer.parseInt(value);
        case "BOLD":
            return r.isBold() == Boolean.valueOf(value);
        case "ITALIC":
            return r.isItalic() == Boolean.valueOf(value);
        case "STRIKETHROUGH":
            return r.isStrike() == Boolean.valueOf(value);
        default:
            System.out.println("Property " + property + " does not exist!");
            return false;
        }
    } catch (NullPointerException e) {
        return false;
    }
}

From source file:apachepoitest.DocumentPropertyEnumerator.java

public static void showParagraphElementProperties(List<XWPFRun> rl) {
    System.out.println("\nELEMENTS: ");
    int counter = 1;
    for (XWPFRun r : rl) {
        if (r.toString().trim().length() > 0) {
            System.out.println("#" + counter++ + ": " + r.toString());
        } else {/*w ww.j  a va 2s.co  m*/
            //Ignore spaces, uncomment to display spaces and comment out "continue"
            //System.out.println("#" + counter++ + ": <SPACE>");
            continue;
        }
        if (r.getColor() != null) {
            System.out.println("COLOR: " + r.getColor());
        }
        if (r.getFontFamily() != null) {
            System.out.println("FONT: " + r.getFontFamily());
        }
        if (r.getFontSize() > 0) {
            System.out.println("FONT SIZE: " + r.getFontSize());
        }
        if (r.getPictureText().length() > 0) {
            System.out.println("PIC TEXT: " + r.getPictureText());
        }
        if (r.getTextPosition() > 0) {
            System.out.println("TEXT POS: " + r.getTextPosition());
        }
        if (r.isBold()) {
            System.out.println("BOLD: " + r.isBold());
        }
        if (r.isItalic()) {
            System.out.println("ITALIC: " + r.isItalic());
        }
        if (r.isStrike()) {
            System.out.println("STRIKETHROUGH: " + r.isStrike());
        }
        if (!r.getUnderline().toString().equals("NONE")) {
            System.out.println("UNDERLINE: " + r.getUnderline().toString());
        }
        if (!r.getSubscript().toString().equals("BASELINE")) {
            System.out.println("Subscript: " + r.getSubscript().toString());
        }
        System.out.println("");
    }
}

From source file:com.deepoove.poi.resolver.TemplateResolver.java

License:Apache License

private static void styleRun(XWPFRun destRun, XWPFRun srcRun) {
    if (null == destRun || null == srcRun)
        return;//from   w ww. j a  v  a  2 s. c  o m
    destRun.setBold(srcRun.isBold());
    destRun.setColor(srcRun.getColor());
    destRun.setFontFamily(srcRun.getFontFamily());
    int fontSize = srcRun.getFontSize();
    if (-1 != fontSize)
        destRun.setFontSize(fontSize);
    destRun.setItalic(srcRun.isItalic());
    destRun.setStrike(srcRun.isStrike());
    destRun.setUnderline(srcRun.getUnderline());
}

From source file:com.maxl.java.aips2sqlite.PseudoExpertInfo.java

License:Open Source License

/**
 * Extracts all the important information from the pseudo "Fachinfo" file
 * @param pseudo_info_file//w w w . ja va  2  s . c  o  m
 */
public boolean extractInfo(int idx, FileInputStream pseudo_info_file) {
    mMedi = new MedicalInformations.MedicalInformation();

    mSectionContent = new ArrayList<String>();
    mSectionTitles = new ArrayList<String>();
    mBarCodes = new ArrayList<String>();
    m_list_of_packages = new ArrayList<String>();

    String mediTitle = "";
    String mediAuthor = "";
    String mediPseudoTag = "";
    String mediHtmlContent = "";

    StringBuilder content = new StringBuilder();

    try {
        // Read in docx file
        XWPFDocument docx = new XWPFDocument(pseudo_info_file);
        // Get iterator through all paragraphs
        Iterator<XWPFParagraph> para = docx.getParagraphsIterator();

        // Pre-process input stream to extract paragraph titles
        boolean goodToGo = false;
        while (para.hasNext()) {
            List<XWPFRun> runs = para.next().getRuns();
            if (!runs.isEmpty()) {
                for (XWPFRun r : runs) {
                    // bold and italics identifies section title!
                    if (r.isBold()) { // && r.isItalic()) {
                        String pText = r.getParagraph().getText();
                        // These are the first chapter titles (DE and FR)
                        if (pText.equals("Zusammensetzung") || pText.equals("Composition"))
                            goodToGo = true;
                        if (goodToGo == true)
                            mSectionTitles.add(pText);
                    }
                }
            }
        }
        // Add "nil" at the end
        mSectionTitles.add("nil");

        if (mLanguage.equals("de") && !mSectionTitles.get(0).equals("Zusammensetzung"))
            return false;
        if (mLanguage.equals("fr") && !mSectionTitles.get(0).equals("Composition"))
            return false;

        // Reset iterator
        para = docx.getParagraphsIterator();

        // Init list for section content 
        for (int i = 0; i < mSectionTitles.size(); ++i)
            mSectionContent.add(i, "");

        // Get title
        if (para.hasNext())
            mediTitle = para.next().getParagraphText();
        // Get author while using "Medizinprodukt" as tag
        String prevParaText = "";
        while (para.hasNext()) {
            String paraText = para.next().getParagraphText();
            // If this word is not found, then no pseudo FI will be produced
            if (paraText.equals("Medizinprodukt") || paraText.equals("Dispositif mdical")) {
                mediPseudoTag = paraText;
                mediAuthor = prevParaText;
                break;
            }
            prevParaText = paraText;
        }

        // Get section titles + sections + ean codes
        boolean isSectionPackungen = false;
        int numSection = 0;
        // Init with section1 and title
        String sectionId_str = "";
        String sectionTitle_str = "";
        mEanCodes_str = "";
        mSectionIds_str = "section1,";
        mSectionTitles_str = mediTitle + ",";
        m_pack_info_str = "";
        // This is the EAN code pattern
        Pattern pattern = Pattern.compile("^[0-9]{13}");
        // Loop through it, identifying medication title, author, section titles and corresponding titles
        while (para.hasNext()) {
            String paraText = para.next().getParagraphText();
            if (paraText.equals(mSectionTitles.get(numSection))) {
                // ->> Get section title
                isSectionPackungen = false;
                // Get section title
                if (numSection < mSectionTitles.size())
                    numSection++;
                // Section "Packungen" is special
                if (paraText.equals("Packungen") || paraText.equals("Prsentation")) {
                    isSectionPackungen = true;
                }
                // Close previous div
                if (numSection > 1)
                    content.append("</div>");
                // Create html
                sectionId_str = "section" + (numSection + 1); // section1 is reserved for the MonTitle
                sectionTitle_str = mSectionTitles.get(numSection - 1);
                content.append("<div class=\"paragraph\" id=\"" + sectionId_str + "\">");
                content.append("<div class=\"absTitle\">" + sectionTitle_str + "</div>");
                // Generate section id string
                mSectionIds_str += (sectionId_str + ",");
                // Generate titles string
                mSectionTitles_str += (sectionTitle_str + ";");
            } else {
                // ->> Get section content
                String s = mSectionContent.get(numSection - 1);
                mSectionContent.set(numSection - 1, s + paraText + " ");
                // Create html
                content.append("<p class=\"spacing1\">" + paraText + "</p>");
                // Extract EAN codes and start positions
                Matcher matcher = pattern.matcher(paraText);
                while (matcher.find()) {
                    String eanCode = matcher.group();
                    mEanCodes_str += (eanCode + ", ");
                    if (!eanCode.isEmpty()) {
                        String pup = "";
                        String efp = "";
                        String fep = "";
                        String fap = "";
                        String vat = "";
                        String size = "";
                        String units = "";
                        String swissmedic_cat = "";
                        String pharma_code = "";
                        int visible = 0xff;
                        int has_free_samples = 0x00; // by default no free samples
                        // Exctract fep and fap pricing information
                        // FAP = Fabrikabgabepreis = EFP?
                        // FEP = Fachhandelseinkaufspreis
                        // EFP = FAP < FEP < PUP                     
                        if (m_map_products != null && eanCode != null && m_map_products.containsKey(eanCode)) {
                            Product product = m_map_products.get(eanCode);
                            if (product.efp > 0.0f)
                                efp = String.format("CHF %.2f", product.efp);
                            if (product.pp > 0.0f)
                                pup = String.format("CHF %.2f", product.pp);
                            if (product.fap > 0.0f)
                                fap = String.format("CHF %.2f", product.fap);
                            if (product.fep > 0.0f)
                                fep = String.format("CHF %.2f", product.fep);
                            if (product.vat > 0.0f)
                                vat = String.format("%.2f", product.vat);
                            if (product.size != null && !product.size.isEmpty())
                                size = product.size;
                            if (product.units != null && product.units.length > 0)
                                units = product.units[0];
                            if (product.swissmedic_cat != null && !product.swissmedic_cat.isEmpty())
                                swissmedic_cat = product.swissmedic_cat;
                            if (product.pharmacode != null && !product.pharmacode.isEmpty())
                                pharma_code = product.pharmacode;
                            visible = product.visible;
                            has_free_samples = product.free_sample;
                        }
                        m_list_of_packages.add(mediTitle.toUpperCase() + ", " + units + ", " + size + "|" + size
                                + "|" + units + "|" + efp + "|" + pup + "|" + fap + "|" + fep + "|" + vat + "|"
                                + swissmedic_cat + ",,|" + eanCode + "|" + pharma_code + "|" + visible + "|"
                                + has_free_samples + "\n");
                        // Generate bar codes
                        BarCode bc = new BarCode();
                        String barcodeImg64 = bc.encode(eanCode);
                        mBarCodes.add("<p class=\"spacing1\">" + barcodeImg64 + "</p>");
                        content.append(barcodeImg64);
                    }
                }
                // Generate section Packungen for search result
                if (isSectionPackungen)
                    m_pack_info_str += (paraText + "\n");
            }
        }
        /*
        // Add chapter "Barcodes"
        content.append("<p class=\"paragraph\"></p><div class=\"absTitle\">" + "Barcodes" + "</div>");
        for (String bcode : mBarCodes)
           content.append(bcode);
        */
        // Remove last comma from mEanCodes_str
        if (!mEanCodes_str.isEmpty())
            mEanCodes_str = mEanCodes_str.substring(0, mEanCodes_str.length() - 2);
        // Remove last \n from mSectionPackungen_str
        if (!m_pack_info_str.isEmpty())
            m_pack_info_str = m_pack_info_str.substring(0, m_pack_info_str.length() - 1);

        // Set title, autor
        mMedi.setTitle(mediTitle);
        mMedi.setAuthHolder(mediAuthor);
        mMedi.setAtcCode("PSEUDO");
        mMedi.setSubstances(mediTitle);

        System.out.println(idx + " - " + mediTitle + ": " + mEanCodes_str);

        // Close previous div + monographie div
        content.append("</div></div>");
        String title = "<div class=\"MonTitle\" id=\"section1\">" + mediTitle + "</div>";
        String author = "<div class=\"ownerCompany\"><div style=\"text-align: right;\">" + mediAuthor
                + "</div></div>";
        // Set "Medizinprodukt" label
        String pseudo = "<p class=\"spacing1\">" + mediPseudoTag + "</p>";
        // Set medi content         
        mediHtmlContent = "<html><head></head><body><div id=\"monographie\">" + title + author + pseudo
                + content.toString() + "</div></body></html>";

        // Generate clean html file
        Document doc = Jsoup.parse(mediHtmlContent);
        doc.outputSettings().escapeMode(EscapeMode.xhtml);
        doc.outputSettings().charset("UTF-8");
        doc.outputSettings().prettyPrint(true);
        doc.outputSettings().indentAmount(1);
        mediHtmlContent = doc.html();

        // Set html content
        mMedi.setContent(mediHtmlContent);

        // Add to DB
        addToDB();

        return true;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
}

From source file:mj.ocraptor.extraction.tika.parser.microsoft.ooxml.XWPFWordExtractorDecorator.java

License:Apache License

private TmpFormatting processRun(XWPFRun run, XWPFParagraph paragraph, XHTMLContentHandler xhtml,
        TmpFormatting tfmtg) throws SAXException, XmlException, IOException {
    // True if we are currently in the named style tag:
    if (run.isBold() != tfmtg.isBold()) {
        if (tfmtg.isItalic()) {
            xhtml.endElement("i");
            tfmtg.setItalic(false);/*from   w  ww.j  av  a 2  s.c  o  m*/
        }
        if (run.isBold()) {
            xhtml.startElement("b");
        } else {
            xhtml.endElement("b");
        }
        tfmtg.setBold(run.isBold());
    }

    if (run.isItalic() != tfmtg.isItalic()) {
        if (run.isItalic()) {
            xhtml.startElement("i");
        } else {
            xhtml.endElement("i");
        }
        tfmtg.setItalic(run.isItalic());
    }

    boolean addedHREF = false;
    if (run instanceof XWPFHyperlinkRun) {
        XWPFHyperlinkRun linkRun = (XWPFHyperlinkRun) run;
        XWPFHyperlink link = linkRun.getHyperlink(document);
        if (link != null && link.getURL() != null) {
            xhtml.startElement("a", "href", link.getURL());
            addedHREF = true;
        } else if (linkRun.getAnchor() != null && linkRun.getAnchor().length() > 0) {
            xhtml.startElement("a", "href", "#" + linkRun.getAnchor());
            addedHREF = true;
        }
    }

    xhtml.characters(run.toString());

    // If we have any pictures, output them
    for (XWPFPicture picture : run.getEmbeddedPictures()) {
        if (paragraph.getDocument() != null) {
            XWPFPictureData data = picture.getPictureData();
            if (data != null) {
                AttributesImpl attr = new AttributesImpl();

                attr.addAttribute("", "src", "src", "CDATA", "embedded:" + data.getFileName());
                attr.addAttribute("", "alt", "alt", "CDATA", picture.getDescription());

                xhtml.startElement("img", attr);
                xhtml.endElement("img");
            }
        }
    }

    if (addedHREF) {
        xhtml.endElement("a");
    }

    return tfmtg;
}

From source file:offishell.msoffice.WordTestHelper.java

License:MIT License

/**
 * <p>//from  w  w  w.ja  va 2s . co m
 * Assertion helper.
 * </p>
 * 
 * @param para
 * @param value
 */
public default void checkRun(XWPFRun run, Assertion value) {
    assert value.of(run.text());
    assert value.of(run.getFontFamily());
    assert value.of(run.getFontSize());
    assert value.of(run.isBold());
    assert value.of(run.isCapitalized());
    assert value.of(run.isDoubleStrikeThrough());
    assert value.of(run.isEmbossed());
    assert value.of(run.isHighlighted());
    assert value.of(run.isImprinted());
}

From source file:offishell.word.WordHeleper.java

License:MIT License

/**
 * <p>// w w w  . ja  v a  2 s  .c o 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.articleEditor.insertContent.POIDocxReader.java

License:Apache License

protected void processRun(XWPFRun run) throws BadLocationException {
    charAttrs = new SimpleAttributeSet();

    if (run.getFontSize() > 0) {
        int size = run.getFontSize();
        StyleConstants.setFontSize(charAttrs, size);
    }//from  www  .ja  v a2 s.c  om
    StyleConstants.setBold(charAttrs, run.isBold());
    StyleConstants.setItalic(charAttrs, run.isItalic());
    StyleConstants.setStrikeThrough(charAttrs, run.isStrike());
    boolean underlined = run.getUnderline() != UnderlinePatterns.NONE;
    StyleConstants.setUnderline(charAttrs, underlined);
    VerticalAlign verticalAlignment = run.getSubscript();
    if (verticalAlignment == VerticalAlign.SUBSCRIPT) {
        StyleConstants.setSubscript(parAttrs, true);
    } else if (verticalAlignment == VerticalAlign.SUPERSCRIPT) {
        StyleConstants.setSuperscript(parAttrs, true);
    } else {
        StyleConstants.setSubscript(parAttrs, false);
        StyleConstants.setSuperscript(parAttrs, false);
    }
    if (run.getFontFamily() != null) {
        StyleConstants.setFontFamily(charAttrs, run.getFontFamily());
    }
    if (run.getColor() != null) {
        String name = run.getColor();
        if (!name.toLowerCase().equals("auto")) {
            Color color = Color.decode("#" + name);
            StyleConstants.setForeground(charAttrs, color);
        }
    }

    // Not working
    if (run.getCTR().getRPr() != null && run.getCTR().getRPr().getHighlight() != null) {
        STHighlightColor.Enum colorEnum = run.getCTR().getRPr().getHighlight().getVal();
        Color color = decodeHighlightName(colorEnum);
        StyleConstants.setBackground(charAttrs, color);
    }

    for (XWPFPicture picture : run.getEmbeddedPictures()) {
        processPicture(picture);
    }
    String text = run.toString();
    document.insertString(currentOffset, text, charAttrs);
    currentOffset += text.length();
}

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

License:Open Source License

@Test
@Override/* w w w . j a v a 2  s. com*/
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/* ww  w  .  j a  v  a2s  .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());
}