Search in sources :

Example 1 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.

the class InCellLists method multiLevelNumberedListInCell.

/**
     * Insert a multi-level list into a cell.
     *
     * @param workbook A reference to the HSSFWorkbook that 'contains' the
     *                 cell.
     * @param multiLevelListItems An ArrayList whose elements contain instances
     *                            of the MultiLevelListItem class. Each element
     *                            encapsulates the text for the high level item
     *                            along with an ArrayList. Each element of this
     *                            ArrayList encapsulates the text for a lower
     *                            level item.
     * @param cell An instance of the HSSFCell class that encapsulates a
     *             reference to the spreadsheet cell into which the list
     *             will be written.
     * @param highLevelStartingValue A primitive int containing the number
     *                               for the first high level item in the list.
     * @param highLevelIncrement A primitive int containing the value that
     *                           should be used to calculate the number of
     *                           subsequent high level item.
     * @param lowLevelStartingValue A primitive int will containing the number
     *                              for the first low level item associated
     *                              with a high level item.
     * @param lowLevelIncrement A primitive int containing the value that
     *                          should be used to calculate the number of
     *                          subsequent low level item.
     */
public void multiLevelNumberedListInCell(HSSFWorkbook workbook, ArrayList<MultiLevelListItem> multiLevelListItems, HSSFCell cell, int highLevelStartingValue, int highLevelIncrement, int lowLevelStartingValue, int lowLevelIncrement) {
    StringBuilder buffer = new StringBuilder();
    int highLevelItemNumber = highLevelStartingValue;
    // Note that again, an HSSFCellStye object is required and that
    // it's wrap text property should be set to 'true'
    HSSFCellStyle wrapStyle = workbook.createCellStyle();
    wrapStyle.setWrapText(true);
    // Step through the ArrayList of MultilLevelListItem instances.
    for (MultiLevelListItem multiLevelListItem : multiLevelListItems) {
        // For each element in the ArrayList, get the text for the high
        // level list item......
        buffer.append(highLevelItemNumber);
        buffer.append(". ");
        buffer.append(multiLevelListItem.getItemText());
        buffer.append("\n");
        // and then an ArrayList whose elements encapsulate the text
        // for the lower level list items.
        ArrayList<String> lowerLevelItems = multiLevelListItem.getLowerLevelItems();
        if (!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) {
            int lowLevelItemNumber = lowLevelStartingValue;
            for (String item : lowerLevelItems) {
                buffer.append(InCellLists.TAB);
                buffer.append(highLevelItemNumber);
                buffer.append(".");
                buffer.append(lowLevelItemNumber);
                buffer.append(" ");
                buffer.append(item);
                buffer.append("\n");
                lowLevelItemNumber += lowLevelIncrement;
            }
        }
        highLevelItemNumber += highLevelIncrement;
    }
    // The StringBuffer's contents are the source for the contents
    // of the cell.
    cell.setCellValue(new HSSFRichTextString(buffer.toString().trim()));
    cell.setCellStyle(wrapStyle);
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Example 2 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.

the class InCellLists method multiLevelBulletedListInCell.

/**
     * Insert a bulleted multi-level list into a cell.
     *
     * @param workbook A reference to the HSSFWorkbook that 'contains' the
     *                 cell.
     * @param multiLevelListItems An ArrayList whose elements contain instances
     *                            of the MultiLevelListItem class. Each element
     *                            encapsulates the text for the high level item
     *                            along with an ArrayList. Each element of this
     *                            ArrayList encapsulates the text for a lower
     *                            level item.
     * @param cell An instance of the HSSFCell class that encapsulates a
     *             reference to the spreadsheet cell into which the list
     *             will be written.
     */
public void multiLevelBulletedListInCell(HSSFWorkbook workbook, ArrayList<MultiLevelListItem> multiLevelListItems, HSSFCell cell) {
    StringBuilder buffer = new StringBuilder();
    // Note that again, an HSSFCellStye object is required and that
    // it's wrap text property should be set to 'true'
    HSSFCellStyle wrapStyle = workbook.createCellStyle();
    wrapStyle.setWrapText(true);
    // Step through the ArrayList of MultilLevelListItem instances.
    for (MultiLevelListItem multiLevelListItem : multiLevelListItems) {
        // For each element in the ArrayList, get the text for the high
        // level list item......
        buffer.append(InCellLists.BULLET_CHARACTER);
        buffer.append(" ");
        buffer.append(multiLevelListItem.getItemText());
        buffer.append("\n");
        // and then an ArrayList whose elements encapsulate the text
        // for the lower level list items.
        ArrayList<String> lowerLevelItems = multiLevelListItem.getLowerLevelItems();
        if (!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) {
            for (String item : lowerLevelItems) {
                buffer.append(InCellLists.TAB);
                buffer.append(InCellLists.BULLET_CHARACTER);
                buffer.append(" ");
                buffer.append(item);
                buffer.append("\n");
            }
        }
    }
    // The StringBuffer's contents are the source for the contents
    // of the cell.
    cell.setCellValue(new HSSFRichTextString(buffer.toString().trim()));
    cell.setCellStyle(wrapStyle);
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Example 3 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.

the class InCellLists method multiLevelListInCell.

/**
     * Insert a multi-level list into a cell.
     *
     * @param workbook A reference to the HSSFWorkbook that 'contains' the
     *                 cell.
     * @param multiLevelListItems An ArrayList whose elements contain instances
     *                            of the MultiLevelListItem class. Each element
     *                            encapsulates the text for the high level item
     *                            along with an ArrayList. Each element of this
     *                            ArrayList encapsulates the text for a lower
     *                            level item.
     * @param cell An instance of the HSSFCell class that encapsulates a
     *             reference to the spreadsheet cell into which the list
     *             will be written.
     */
public void multiLevelListInCell(HSSFWorkbook workbook, ArrayList<MultiLevelListItem> multiLevelListItems, HSSFCell cell) {
    StringBuilder buffer = new StringBuilder();
    // Note that again, an HSSFCellStye object is required and that
    // it's wrap text property should be set to 'true'
    HSSFCellStyle wrapStyle = workbook.createCellStyle();
    wrapStyle.setWrapText(true);
    // Step through the ArrayList of MultilLevelListItem instances.
    for (MultiLevelListItem multiLevelListItem : multiLevelListItems) {
        // For each element in the ArrayList, get the text for the high
        // level list item......
        buffer.append(multiLevelListItem.getItemText());
        buffer.append("\n");
        // and then an ArrayList whose elements encapsulate the text
        // for the lower level list items.
        ArrayList<String> lowerLevelItems = multiLevelListItem.getLowerLevelItems();
        if (!(lowerLevelItems == null) && !(lowerLevelItems.isEmpty())) {
            for (String item : lowerLevelItems) {
                buffer.append(InCellLists.TAB);
                buffer.append(item);
                buffer.append("\n");
            }
        }
    }
    // The StringBuffer's contents are the source for the contents
    // of the cell.
    cell.setCellValue(new HSSFRichTextString(buffer.toString().trim()));
    cell.setCellStyle(wrapStyle);
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Example 4 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.

the class InCellLists method bulletedListInCell.

/**
     * Insert a bulleted list into a cell.
     *
     * @param workbook A reference to the HSSFWorkbook that 'contains' the
     *                 cell.
     * @param listItems An ArrayList whose elements encapsulate the text for
     *                  the lists items.
     * @param cell An instance of the HSSFCell class that encapsulates a
     *             reference to the spreadsheet cell into which the list
     *             will be written.
     */
public void bulletedListInCell(HSSFWorkbook workbook, ArrayList<String> listItems, HSSFCell cell) {
    StringBuilder buffer = new StringBuilder();
    // Note that again, an HSSFCellStye object is required and that
    // it's wrap text property should be set to 'true'
    HSSFCellStyle wrapStyle = workbook.createCellStyle();
    wrapStyle.setWrapText(true);
    // with one difference; the bullet character prefixed to the items text.
    for (String listItem : listItems) {
        buffer.append(InCellLists.BULLET_CHARACTER + " ");
        buffer.append(listItem);
        buffer.append("\n");
    }
    // The StringBuffer's contents are the source for the contents
    // of the cell.
    cell.setCellValue(new HSSFRichTextString(buffer.toString().trim()));
    cell.setCellStyle(wrapStyle);
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Example 5 with HSSFRichTextString

use of org.apache.poi.hssf.usermodel.HSSFRichTextString in project poi by apache.

the class InCellLists method bulletedItemInCell.

/**
     * Inserts a single bulleted item into a cell.
     *
     * @param workbook A reference to the HSSFWorkbook that 'contains' the
     *                 cell.
     * @param listItem An instance of the String class encapsulating the
     *                 items text.
     * @param cell An instance of the HSSFCell class that encapsulates a
     *             reference to the spreadsheet cell into which the list item
     *             will be written.
     */
public void bulletedItemInCell(HSSFWorkbook workbook, String listItem, HSSFCell cell) {
    // A format String must be built to ensure that the contents of the
    // cell appear as a bulleted item.
    HSSFDataFormat format = workbook.createDataFormat();
    String formatString = InCellLists.BULLET_CHARACTER + " @";
    int formatIndex = format.getFormat(formatString);
    // Construct an HSSFCellStyle and set it's data formt to use the
    // object created above.
    HSSFCellStyle bulletStyle = workbook.createCellStyle();
    bulletStyle.setDataFormat((short) formatIndex);
    // Set the cells contents and style.
    cell.setCellValue(new HSSFRichTextString(listItem));
    cell.setCellStyle(bulletStyle);
}
Also used : HSSFCellStyle(org.apache.poi.hssf.usermodel.HSSFCellStyle) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString) HSSFDataFormat(org.apache.poi.hssf.usermodel.HSSFDataFormat) HSSFRichTextString(org.apache.poi.hssf.usermodel.HSSFRichTextString)

Aggregations

HSSFRichTextString (org.apache.poi.hssf.usermodel.HSSFRichTextString)38 HSSFCellStyle (org.apache.poi.hssf.usermodel.HSSFCellStyle)17 HSSFCell (org.apache.poi.hssf.usermodel.HSSFCell)16 HSSFRow (org.apache.poi.hssf.usermodel.HSSFRow)9 HSSFSheet (org.apache.poi.hssf.usermodel.HSSFSheet)8 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)7 HSSFClientAnchor (org.apache.poi.hssf.usermodel.HSSFClientAnchor)5 HSSFFont (org.apache.poi.hssf.usermodel.HSSFFont)5 HSSFPatriarch (org.apache.poi.hssf.usermodel.HSSFPatriarch)5 Test (org.junit.Test)5 HSSFSimpleShape (org.apache.poi.hssf.usermodel.HSSFSimpleShape)3 FileOutputStream (java.io.FileOutputStream)2 BigDecimal (java.math.BigDecimal)2 HSSFComment (org.apache.poi.hssf.usermodel.HSSFComment)2 Region (org.apache.poi.hssf.util.Region)2 Element (org.w3c.dom.Element)2 Text (org.w3c.dom.Text)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1