本文整理匯總了Java中org.apache.poi.hssf.usermodel.HSSFCell.setCellStyle方法的典型用法代碼示例。如果您正苦於以下問題:Java HSSFCell.setCellStyle方法的具體用法?Java HSSFCell.setCellStyle怎麽用?Java HSSFCell.setCellStyle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.hssf.usermodel.HSSFCell
的用法示例。
在下文中一共展示了HSSFCell.setCellStyle方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeHeader
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private void makeHeader ( final List<Field> columns, final HSSFSheet sheet )
{
final Font font = sheet.getWorkbook ().createFont ();
font.setFontName ( "Arial" );
font.setBoldweight ( Font.BOLDWEIGHT_BOLD );
font.setColor ( HSSFColor.WHITE.index );
final CellStyle style = sheet.getWorkbook ().createCellStyle ();
style.setFont ( font );
style.setFillForegroundColor ( HSSFColor.BLACK.index );
style.setFillPattern ( PatternFormatting.SOLID_FOREGROUND );
final HSSFRow row = sheet.createRow ( 0 );
for ( int i = 0; i < columns.size (); i++ )
{
final Field field = columns.get ( i );
final HSSFCell cell = row.createCell ( i );
cell.setCellValue ( field.getHeader () );
cell.setCellStyle ( style );
}
}
示例2: createColumnHeaders
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
*/
protected void createColumnHeaders() {
final HSSFRow headersRow = this.sheet.createRow(0);
final HSSFFont font = this.workbook.createFont();
font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
final HSSFCellStyle style = this.workbook.createCellStyle();
style.setFont(font);
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
int counter = 1;
for (int i = 0; i < this.model.getColumnCount(); i++) {
final HSSFCell cell = headersRow.createCell(counter++);
// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
cell.setCellValue(this.model.getColumnName(i));
cell.setCellStyle(style);
}
}
示例3: createRow
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
*
* @param rowIndex
* int
*/
protected void createRow(final int rowIndex) {
final HSSFRow row = this.sheet.createRow(rowIndex + 1); // since the
// rows in
// excel starts from 1
// not 0
final HSSFCellStyle style = this.workbook.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);
int counter = 1;
for (int i = 0; i < this.model.getColumnCount(); i++) {
final HSSFCell cell = row.createCell(counter++);
// cell.setEncoding(HSSFCell.ENCODING_UTF_16);
final Object value = this.model.getValueAt(rowIndex, i);
setValue(cell, value);
cell.setCellStyle(style);
}
}
示例4: setBold
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
* Set a bold font for the given cell with a given font size (in pt).
*
* @param wb
* the workbook that contains the cell
* @param cell
* the cell where the text is contained
* @param size
* the size in pt of the text
*/
public static void setBold(Workbook wb, HSSFCell cell, short size) {
Font font = wb.createFont();
font.setFontHeightInPoints((short) size);
font.setFontName("Arial");
font.setColor(IndexedColors.BLACK.getIndex());
font.setBold(true);
font.setItalic(false);
CellStyle style = wb.createCellStyle();
style.setFont(font);
cell.setCellStyle(style);
}
示例5: setLink
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
* Set a link to a cell. The link type should one of {@link Hyperlink}
*
* @param wb
* the workbook which contains the cell
* @param cell
* the cell where the link is stored
* @param address
* the cell destination address
* @param linkType
* the type selected among {@link Hyperlink}
*/
public static void setLink(Workbook wb, HSSFCell cell, String address, int linkType) {
CreationHelper helper = wb.getCreationHelper();
CellStyle style = wb.createCellStyle();
Font font = wb.createFont();
font.setUnderline(Font.U_SINGLE);
font.setColor(IndexedColors.BLUE.getIndex());
style.setFont(font);
Hyperlink link = helper.createHyperlink(linkType);
link.setAddress(address);
cell.setHyperlink(link);
cell.setCellStyle(style);
}
示例6: createHeader
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private boolean createHeader(WorkbookGeneratorContext context,
HSSFSheet sheet,
HSSFCellStyle style) {
if (context.headerNames == null || context.headerNames.isEmpty()) {
return false;
}
int headerRowIndex = 0;
HSSFRow rowHeader = sheet.createRow(headerRowIndex);
for (int i = 0; i < context.headerNames.size(); i++) {
HSSFCell cell = rowHeader.createCell(i);
sheet.autoSizeColumn((short) i);
cell.setCellStyle(style);
cell.setCellValue(new HSSFRichTextString(context.headerNames.get(i)));
}
return true;
}
示例7: writeCondtions
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
* 表頭條件
* @param sheet
* @param t
* @param cellCount
* @return
*/
void writeCondtions(HSSFSheet sheet){
T t = getConditions();
if (t!=null) {
HSSFRow row = sheet.createRow(getRowNumber());
row.setHeight((short) 500);
CellRangeAddress cra = new CellRangeAddress(getRowNumber(), getRowNumber(), 0, getColumnJson().size());
sheet.addMergedRegion(cra);
HSSFCell cell = row.createCell(0);
HSSFCellStyle style = cell.getCellStyle();
style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER);
style.setWrapText(true);
cell.setCellStyle(style);
setCellValue(cell, formatCondition(t));
addRowNumber();
}
}
示例8: setCellStyle
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
public static void setCellStyle(HSSFCell cell, String metricName, String scope, Double value) {
// getting the configuration of the metric
Map<String, MetricConfiguration> mm = MetricConfigurations.getMc().getMetricConfigurationsMap();
MetricConfiguration mc = mm.get(metricName + " " + scope);
if (mc != null) {
if (value < mc.getMinimum() || mc.getMaximum() < value) {
cell.setCellStyle(ReportGeneratorImpl.getRedBlueStyle());
} else {
cell.setCellStyle(ReportGeneratorImpl.getBlueStyle());
}
} else {
cell.setCellStyle(ReportGeneratorImpl.getBlueStyle());
}
}
示例9: createContentHeader
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/**
* @param sheet
* @param strings
*/
public final void createContentHeader(final HSSFSheet sheet,
final String... strings) {
HSSFRow row;
HSSFCell cell;
row = sheet.createRow(CONTENT_HEADER);
for (int i = 0; i < strings.length; i++) {
cell = row.createCell(i);
cell.setCellValue(strings[i]);
cell.setCellStyle(heading3Cs);
}
sheet.createFreezePane(0, CONTENT_HEADER + 1);
sheet.setAutoFilter(new CellRangeAddress(CONTENT_HEADER, CONTENT_HEADER,
0, strings.length - 1));
}
示例10: addDocumentIntoTheRow
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private void addDocumentIntoTheRow(Document document,
HSSFRow row, LinkedHashMap<String, Integer> columPoints,LinkedHashMap<String,String>map, HSSFCellStyle style) throws Exception {
// TODO Auto-generated method stub
HSSFCell cell;
//int count=0;
for(String key : map.keySet()){
String colum=map.get(key);
String mathodName="get"+key;
Object args[]=new Object[0];
Object result=null;
String value;
if((result=ReflectionUtil.invokeMethod(document, mathodName, args))!=null){
value=result.toString();
cell=row.createCell(columPoints.get(colum));
cell.setCellStyle(style);
cell.setCellValue(value);
}else{
cell=row.createCell(columPoints.get(colum));
cell.setCellStyle(style);
cell.setCellValue("");
}
}
}
示例11: createSheetHead
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private LinkedHashMap<String,Integer> createSheetHead(HSSFSheet sheet, HSSFCellStyle style,LinkedHashMap<String,String> map) {
HSSFRow row = sheet.createRow(2);
row.setHeight((short)1000);
HSSFCell cell;
int count=0;
LinkedHashMap<String,Integer> columPoints=new LinkedHashMap<String,Integer>();
for(String value:map.values()){
cell=row.createCell(count);
cell.setCellValue(value);
cell.setCellStyle(style);
columPoints.put(value, count);
count++;
}
return columPoints;
}
示例12: createSheetTitle
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
private void createSheetTitle(HSSFSheet sheet,HSSFCellStyle style1,HSSFCellStyle style2,String documentNumber,String title){
HSSFRow row = sheet.createRow(0);
row.setHeightInPoints(30);
HSSFCell cell1 = row.createCell(0);
cell1.setCellValue(title);
cell1.setCellStyle(style1);
sheet.addMergedRegion(new CellRangeAddress(0,(short)0,0,(short)6));
row = sheet.createRow(1);
HSSFCell[] cell = new HSSFCell[7];
for(int i = 0;i < 7;i++){
cell[i] = row.createCell(i);
cell[i].setCellStyle(style2);
}
HSSFHeader header = sheet.getHeader();
header.setRight("�� " + HSSFHeader.page() + " ҳ");
cell[0].setCellValue("����");
cell[1].setCellValue(documentNumber);
//cell[5].setCellValue("��" + header.page() + "ҳ");
sheet.addMergedRegion(new CellRangeAddress(1,1,1,4));
// sheet.addMergedRegion(new CellRangeAddress(1,1,5,6));
}
示例13: setStyle
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
void setStyle(int currentCol, int column, int row) {
if (!hasValue(column, row))
return;
HSSFCell cell = getCell(column, row);
int n = 0, s = 0, w = 0, e = 0;
if (row < 2 || !hasValue(column, row - 1))
n = 1;
if (column == currentCol || !hasValue(column - 1, row))
w = 1;
if (!hasValue(column, row + 1))
s = 1;
if (!hasValue(column + 1, row))
e = 1;
int index = n + 2 * s + 4 * e + 8 * w;
cell.setCellStyle(styles[index]);
}
示例14: setNumericCell
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
protected void setNumericCell(HSSFCell cell, BigDecimal value, HSSFWorkbook workbook)
{
if(logger.isDebugEnabled())
logger.debug("setNumericCell(cell={}, value={}, workbook={}) - start",
new Object[] {cell, value, workbook} );
cell.setCellValue( ((BigDecimal)value).doubleValue() );
HSSFDataFormat df = workbook.createDataFormat();
int scale = ((BigDecimal)value).scale();
short format;
if(scale <= 0){
format = df.getFormat("####");
}
else {
String zeros = createZeros(((BigDecimal)value).scale());
format = df.getFormat("####." + zeros);
}
if(logger.isDebugEnabled())
logger.debug("Using format '{}' for value '{}'.", String.valueOf(format), value);
HSSFCellStyle cellStyleNumber = workbook.createCellStyle();
cellStyleNumber.setDataFormat(format);
cell.setCellStyle(cellStyleNumber);
}
示例15: writeHeader
import org.apache.poi.hssf.usermodel.HSSFCell; //導入方法依賴的package包/類
/** tulis header **/
private void writeHeader(){
for(int i=0;i<headerNames.size();++i){
int c = 0;
short r = (short) headerTitleRowStart;
int x = 1 + r;
HSSFRow paramRow = sheet.createRow(i+r);
HSSFCell paramCell = paramRow.createCell((short) c);
// paramCell.setCellValue(headerParamNames.get(i+2));
paramCell.setCellValue(headerNames.get(i+x));
paramCell.setCellStyle(boldStyle);
HSSFCell paramValueCell = paramRow.createCell((short) (c+1));
// paramValueCell.setCellValue(headerParamValues.get(i+2));
paramValueCell.setCellValue(headerValues.get(i+x));
}
}