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);
}
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);
}
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);
}
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);
}
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);
}
Aggregations