本文整理汇总了Java中org.apache.poi.hssf.usermodel.HSSFCell.getCellStyle方法的典型用法代码示例。如果您正苦于以下问题:Java HSSFCell.getCellStyle方法的具体用法?Java HSSFCell.getCellStyle怎么用?Java HSSFCell.getCellStyle使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.poi.hssf.usermodel.HSSFCell
的用法示例。
在下文中一共展示了HSSFCell.getCellStyle方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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();
}
}
示例2: copyCellStyle
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static List<HSSFCellStyle> copyCellStyle(final HSSFWorkbook workbook, final HSSFRow row) {
final List<HSSFCellStyle> cellStyleList = new ArrayList<HSSFCellStyle>();
for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
final HSSFCell cell = row.getCell(colNum);
if (cell != null) {
final HSSFCellStyle style = cell.getCellStyle();
final HSSFCellStyle newCellStyle = copyCellStyle(workbook, style);
cellStyleList.add(newCellStyle);
} else {
cellStyleList.add(null);
}
}
return cellStyleList;
}
示例3: copyCellStyle
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static List<HSSFCellStyle> copyCellStyle(HSSFWorkbook workbook,
HSSFRow row) {
List<HSSFCellStyle> cellStyleList = new ArrayList<HSSFCellStyle>();
for (int colNum = row.getFirstCellNum(); colNum <= row.getLastCellNum(); colNum++) {
HSSFCell cell = row.getCell(colNum);
if (cell != null) {
HSSFCellStyle style = cell.getCellStyle();
HSSFCellStyle newCellStyle = copyCellStyle(workbook, style);
cellStyleList.add(newCellStyle);
} else {
cellStyleList.add(null);
}
}
return cellStyleList;
}
示例4: xlsToHtml
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private void xlsToHtml() throws Throwable {
FileOutputStream output = new FileOutputStream(new File(htmlPath));
StringBuffer htmlHeaderSB = new StringBuffer();
htmlHeaderSB.append("<html xmlns:o='urn:schemas-microsoft-com:office:office' xmlns:x='urn:schemas-microsoft-com:office:excel' "
+ "xmlns='http://www.w3.org/TR/REC-html40'>");
htmlHeaderSB.append("<head><meta http-equiv=Content-Type content='text/html; charset=utf-8'><meta name=ProgId content=Excel.Sheet>"
+ "</head><body>");
output.write(htmlHeaderSB.toString().getBytes());
HSSFSheet sheet;
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(filePath)); // 获整个Excel
for (int sheetIndex = 0; sheetIndex < workbook.getNumberOfSheets(); sheetIndex++) {
if (workbook.getSheetAt(sheetIndex) != null) {
sheet = workbook.getSheetAt(sheetIndex);// 获得不为空的这个sheet
if (sheet != null) {
int firstRowNum = sheet.getFirstRowNum(); // 第一行
int lastRowNum = sheet.getLastRowNum(); // 最后一行
// 构造Table
output.write(("<table width=\"100%\" style=\"border:1px solid #000;border-width:1px 0 0 1px;margin:2px 0 2px 0;"
+ "border-collapse:collapse;\">").getBytes());
for (int rowNum = firstRowNum; rowNum <= lastRowNum; rowNum++) {
if (sheet.getRow(rowNum) != null) {// 如果行不为空,
HSSFRow row = sheet.getRow(rowNum);
short firstCellNum = row.getFirstCellNum(); // 该行的第一个单元格
short lastCellNum = row.getLastCellNum(); // 该行的最后一个单元格
int height = (int) (row.getHeight() / 15.625); // 行的高度
output.write(("<tr height=\"" + height + "\" style=\"border:1px solid #000;border-width:0 1px 1px 0;"
+ "margin:2px 0 2px 0;\">").getBytes());
for (short cellNum = firstCellNum; cellNum <= lastCellNum; cellNum++) { // 循环该行的每一个单元格
HSSFCell cell = row.getCell(cellNum);
if (cell != null) {
if (cell.getCellType() != HSSFCell.CELL_TYPE_BLANK) {
StringBuffer tdStyle = new StringBuffer("<td style=\"border:1px solid #000; border-width:0 1px 1px 0;"
+ "margin:2px 0 2px 0; ");
HSSFCellStyle cellStyle = cell.getCellStyle();
HSSFPalette palette = workbook.getCustomPalette(); // 类HSSFPalette用于求颜色的国际标准形式
HSSFColor hColor = palette.getColor(cellStyle.getFillForegroundColor());
HSSFColor hColor2 = palette.getColor(cellStyle.getFont(workbook).getColor());
String bgColor = convertToStardColor(hColor);// 背景颜色
short boldWeight = cellStyle.getFont(workbook).getBoldweight(); // 字体粗细
short fontHeight = (short) (cellStyle.getFont(workbook).getFontHeight() / 2); // 字体大小
String fontColor = convertToStardColor(hColor2); // 字体颜色
if (bgColor != null && !"".equals(bgColor.trim())) {
tdStyle.append(" background-color:");
tdStyle.append(bgColor);
tdStyle.append("; ");
}
if (fontColor != null && !"".equals(fontColor.trim())) {
tdStyle.append(" color:");
tdStyle.append(fontColor);
tdStyle.append("; ");
}
tdStyle.append(" font-weight:");
tdStyle.append(boldWeight);
tdStyle.append("; ");
tdStyle.append(" font-size: ");
tdStyle.append(fontHeight);
tdStyle.append("%;");
output.write((tdStyle + "\"").getBytes());
int width = (int) (sheet.getColumnWidth(cellNum) / 35.7); //
int cellRegionCol = getMergerCellRegionCol(sheet, rowNum, cellNum); // 合并的列(solspan)
int cellRegionRow = getMergerCellRegionRow(sheet, rowNum, cellNum);// 合并的行(rowspan)
String align = convertAlignToHtml(cellStyle.getAlignment()); //
String vAlign = convertVerticalAlignToHtml(cellStyle.getVerticalAlignment());
output.write((" align=\"" + align + "\" valign=\"" + vAlign + "\" width=\"" + width + "\" ").getBytes());
output.write((" colspan=\"" + cellRegionCol + "\" rowspan=\"" + cellRegionRow + "\"").getBytes());
output.write((">" + getCellValue(cell) + "</td>").getBytes());
}
}
}
output.write("</tr>".getBytes());
}
}
output.write(("</table>").getBytes());
}
}
}
output.write(("</body></html>").getBytes());
output.close();
}
示例5: copyRow
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static void copyRow(final HSSFSheet oldSheet, final HSSFSheet newSheet, final int oldRowNum, final int newRowNum) {
final HSSFRow oldRow = oldSheet.getRow(oldRowNum);
final HSSFRow newRow = newSheet.createRow(newRowNum);
if (oldRow == null) {
return;
}
newRow.setHeight(oldRow.getHeight());
if (oldRow.getFirstCellNum() == -1) {
return;
}
for (int colNum = oldRow.getFirstCellNum(); colNum <= oldRow.getLastCellNum(); colNum++) {
final HSSFCell oldCell = oldRow.getCell(colNum);
final HSSFCell newCell = newRow.createCell(colNum);
if (oldCell != null) {
final HSSFCellStyle style = oldCell.getCellStyle();
newCell.setCellStyle(style);
final int cellType = oldCell.getCellType();
newCell.setCellType(cellType);
if (cellType == Cell.CELL_TYPE_BOOLEAN) {
newCell.setCellValue(oldCell.getBooleanCellValue());
} else if (cellType == Cell.CELL_TYPE_FORMULA) {
newCell.setCellFormula(oldCell.getCellFormula());
} else if (cellType == Cell.CELL_TYPE_NUMERIC) {
newCell.setCellValue(oldCell.getNumericCellValue());
} else if (cellType == Cell.CELL_TYPE_STRING) {
newCell.setCellValue(oldCell.getRichStringCellValue());
}
}
}
POIUtils.copyMergedRegion(newSheet, getMergedRegionList(oldSheet, oldRowNum), newRowNum);
}
示例6: copyRow
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public static void copyRow(HSSFSheet oldSheet, HSSFSheet newSheet,
int oldRowNum, int newRowNum) {
HSSFRow oldRow = oldSheet.getRow(oldRowNum);
HSSFRow newRow = newSheet.createRow(newRowNum);
if (oldRow == null) {
return;
}
newRow.setHeight(oldRow.getHeight());
if (oldRow.getFirstCellNum() == -1) {
return;
}
for (int colNum = oldRow.getFirstCellNum(); colNum <= oldRow
.getLastCellNum(); colNum++) {
HSSFCell oldCell = oldRow.getCell(colNum);
HSSFCell newCell = newRow.createCell(colNum);
if (oldCell != null) {
HSSFCellStyle style = oldCell.getCellStyle();
newCell.setCellStyle(style);
int cellType = oldCell.getCellType();
newCell.setCellType(cellType);
if (cellType == HSSFCell.CELL_TYPE_BOOLEAN) {
newCell.setCellValue(oldCell.getBooleanCellValue());
} else if (cellType == HSSFCell.CELL_TYPE_FORMULA) {
newCell.setCellFormula(oldCell.getCellFormula());
} else if (cellType == HSSFCell.CELL_TYPE_NUMERIC) {
newCell.setCellValue(oldCell.getNumericCellValue());
} else if (cellType == HSSFCell.CELL_TYPE_STRING) {
newCell.setCellValue(oldCell.getRichStringCellValue());
}
}
}
POIUtils.copyMergedRegion(newSheet,
getMergedRegionList(oldSheet, oldRowNum), newRowNum);
}
示例7: createMatrixCellStyle
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private MatrixCellStyle createMatrixCellStyle(HSSFWorkbook workbook,
HSSFSheet sheet, CellLocation matrixCellLocation) {
int matrixRowNum = matrixCellLocation.r;
int matrixColumnNum = matrixCellLocation.c;
HSSFRow matrixHeaderTemplateRow = sheet.getRow(matrixRowNum);
HSSFCell matrixHeaderTemplateCell = matrixHeaderTemplateRow
.getCell(matrixColumnNum);
MatrixCellStyle matrixCellStyle = new MatrixCellStyle();
matrixCellStyle.headerTemplateCellStyle = matrixHeaderTemplateCell
.getCellStyle();
matrixCellStyle.style11 = this.createMatrixCellStyle(workbook,
matrixCellStyle.headerTemplateCellStyle, false, true, true,
false);
matrixCellStyle.style12 = this.createMatrixCellStyle(workbook,
matrixCellStyle.headerTemplateCellStyle, false, true, true,
true);
matrixCellStyle.style13 = this.createMatrixCellStyle(workbook,
matrixCellStyle.headerTemplateCellStyle, false, false, true,
true);
matrixCellStyle.style21 = this.createMatrixCellStyle(workbook,
matrixCellStyle.headerTemplateCellStyle, true, true, true,
false);
matrixCellStyle.style22 = this
.createMatrixCellStyle(workbook,
matrixCellStyle.headerTemplateCellStyle, true, true,
true, true);
this.setIndexMatrixColor(workbook, matrixCellStyle.style22);
matrixCellStyle.style23 = this.createMatrixCellStyle(workbook,
matrixCellStyle.headerTemplateCellStyle, true, false, true,
true);
this.setIndexMatrixColor(workbook, matrixCellStyle.style23);
matrixCellStyle.style31 = this.createMatrixCellStyle(workbook,
matrixCellStyle.headerTemplateCellStyle, true, true, false,
false);
matrixCellStyle.style32 = this.createMatrixCellStyle(workbook,
matrixCellStyle.headerTemplateCellStyle, true, true, false,
true);
this.setIndexMatrixColor(workbook, matrixCellStyle.style32);
matrixCellStyle.style33 = this.createMatrixCellStyle(workbook,
matrixCellStyle.headerTemplateCellStyle, true, false, false,
true);
this.setIndexMatrixColor(workbook, matrixCellStyle.style33);
return matrixCellStyle;
}
示例8: getValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
public Object getValue(int row, String column) throws DataSetException {
if (logger.isDebugEnabled())
logger.debug("getValue(row={}, columnName={}) - start", Integer.toString(row), column);
assertValidRowIndex(row);
int columnIndex = getColumnIndex(column);
HSSFCell cell = _sheet.getRow(row + 1).getCell(columnIndex);
if (cell == null) {
return null;
}
int type = cell.getCellType();
switch (type) {
case HSSFCell.CELL_TYPE_NUMERIC:
HSSFCellStyle style = cell.getCellStyle();
if (HSSFDateUtil.isCellDateFormatted(cell)) {
return getDateValue(cell);
} else if (XlsDataSetWriter.DATE_FORMAT_AS_NUMBER_DBUNIT.equals(style.getDataFormatString())) {
// The special dbunit date format
return getDateValueFromJavaNumber(cell);
} else {
return getNumericValue(cell);
}
case HSSFCell.CELL_TYPE_STRING:
return cell.getRichStringCellValue().getString();
case HSSFCell.CELL_TYPE_FORMULA:
throw new DataTypeException("Formula not supported at row=" +
row + ", column=" + column);
case HSSFCell.CELL_TYPE_BLANK:
return null;
case HSSFCell.CELL_TYPE_BOOLEAN:
return cell.getBooleanCellValue() ? Boolean.TRUE : Boolean.FALSE;
case HSSFCell.CELL_TYPE_ERROR:
throw new DataTypeException("Error at row=" + row +
", column=" + column);
default:
throw new DataTypeException("Unsupported type at row=" + row +
", column=" + column);
}
}
示例9: getCellValue
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
/**
* This is a helper method to retrieve the value of a
* cell regardles of its type, which will be converted
* into a String.
*
* @param cell
* @return
*/
private String getCellValue(HSSFCell cell) {
if (cell == null) {
return null;
}
String result = null;
int cellType = cell.getCellType();
switch (cellType) {
case HSSFCell.CELL_TYPE_BLANK:
result = "";
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
result = cell.getBooleanCellValue() ?
"true" : "false";
break;
case HSSFCell.CELL_TYPE_ERROR:
result = "ERROR: " + cell.getErrorCellValue();
break;
case HSSFCell.CELL_TYPE_FORMULA:
result = cell.getCellFormula();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
HSSFCellStyle cellStyle = cell.getCellStyle();
short dataFormat = cellStyle.getDataFormat();
// assumption is made that dataFormat = 15,
// when cellType is HSSFCell.CELL_TYPE_NUMERIC
// is equal to a DATE format.
if (dataFormat == 15) {
result = cell.getDateCellValue().toString();
} else {
result = String.valueOf(
cell.getNumericCellValue());
}
break;
case HSSFCell.CELL_TYPE_STRING:
result = cell.getStringCellValue();
break;
default:
break;
}
return result;
}
示例10: isTextEmpty
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
protected boolean isTextEmpty( HSSFCell cell )
{
final String value;
switch ( cell.getCellType() )
{
case HSSFCell.CELL_TYPE_STRING:
// XXX: enrich
value = cell.getRichStringCellValue().getString();
break;
case HSSFCell.CELL_TYPE_FORMULA:
switch ( cell.getCachedFormulaResultType() )
{
case HSSFCell.CELL_TYPE_STRING:
HSSFRichTextString str = cell.getRichStringCellValue();
if ( str == null || str.length() <= 0 )
return false;
value = str.toString();
break;
case HSSFCell.CELL_TYPE_NUMERIC:
HSSFCellStyle style = cell.getCellStyle();
if ( style == null )
{
return false;
}
value = ( _formatter.formatRawCellContents(
cell.getNumericCellValue(), style.getDataFormat(),
style.getDataFormatString() ) );
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
value = String.valueOf( cell.getBooleanCellValue() );
break;
case HSSFCell.CELL_TYPE_ERROR:
value = ErrorEval.getText( cell.getErrorCellValue() );
break;
default:
value = ExcelToHtmlUtils.EMPTY;
break;
}
break;
case HSSFCell.CELL_TYPE_BLANK:
value = ExcelToHtmlUtils.EMPTY;
break;
case HSSFCell.CELL_TYPE_NUMERIC:
value = _formatter.formatCellValue( cell );
break;
case HSSFCell.CELL_TYPE_BOOLEAN:
value = String.valueOf( cell.getBooleanCellValue() );
break;
case HSSFCell.CELL_TYPE_ERROR:
value = ErrorEval.getText( cell.getErrorCellValue() );
break;
default:
return true;
}
return ExcelToHtmlUtils.isEmpty( value );
}
示例11: createMatrixCellStyle
import org.apache.poi.hssf.usermodel.HSSFCell; //导入方法依赖的package包/类
private MatrixCellStyle createMatrixCellStyle(final HSSFWorkbook workbook, final HSSFSheet sheet, final CellLocation matrixCellLocation) {
final int matrixRowNum = matrixCellLocation.r;
final int matrixColumnNum = matrixCellLocation.c;
final HSSFRow matrixHeaderTemplateRow = sheet.getRow(matrixRowNum);
final HSSFCell matrixHeaderTemplateCell = matrixHeaderTemplateRow.getCell(matrixColumnNum);
final MatrixCellStyle matrixCellStyle = new MatrixCellStyle();
matrixCellStyle.headerTemplateCellStyle = matrixHeaderTemplateCell.getCellStyle();
matrixCellStyle.style11 = this.createMatrixCellStyle(workbook, matrixCellStyle.headerTemplateCellStyle, false, true, true, false);
matrixCellStyle.style12 = this.createMatrixCellStyle(workbook, matrixCellStyle.headerTemplateCellStyle, false, true, true, true);
matrixCellStyle.style13 = this.createMatrixCellStyle(workbook, matrixCellStyle.headerTemplateCellStyle, false, false, true, true);
matrixCellStyle.style21 = this.createMatrixCellStyle(workbook, matrixCellStyle.headerTemplateCellStyle, true, true, true, false);
matrixCellStyle.style22 = this.createMatrixCellStyle(workbook, matrixCellStyle.headerTemplateCellStyle, true, true, true, true);
setIndexMatrixColor(workbook, matrixCellStyle.style22);
matrixCellStyle.style23 = this.createMatrixCellStyle(workbook, matrixCellStyle.headerTemplateCellStyle, true, false, true, true);
setIndexMatrixColor(workbook, matrixCellStyle.style23);
matrixCellStyle.style31 = this.createMatrixCellStyle(workbook, matrixCellStyle.headerTemplateCellStyle, true, true, false, false);
matrixCellStyle.style32 = this.createMatrixCellStyle(workbook, matrixCellStyle.headerTemplateCellStyle, true, true, false, true);
setIndexMatrixColor(workbook, matrixCellStyle.style32);
matrixCellStyle.style33 = this.createMatrixCellStyle(workbook, matrixCellStyle.headerTemplateCellStyle, true, false, false, true);
setIndexMatrixColor(workbook, matrixCellStyle.style33);
return matrixCellStyle;
}