private String getIndentCSSStyle(SCell cell) { final int indention = _cell.getCellStyle().getIndention(); final boolean wrap = _cell.getCellStyle().isWrapText(); if (indention > 0) { if (wrap) { // ZSS-1016 return "float:right; width: " + (_sheet.getColumn(_cell.getColumnIndex()).getWidth() - (indention * 8.5) - RESERVE_CELL_MARGIN) + "px;"; } else return "text-indent:" + (indention * 8.5) + "px;"; } return ""; }
/** Gets Cell text by given row and column, it handling */ public static String getRichCellHtmlText(SSheet sheet, int row, int column) { final SCell cell = sheet.getCell(row, column); String text = ""; if (!cell.isNull()) { final SCellStyle style = cell.getCellStyle(); boolean wrap = style.isWrapText(); boolean vtxt = style.getRotation() == 255; // ZSS-918 final FormatResult ft = EngineFactory.getInstance() .createFormatEngine() .format(cell, new FormatContext(ZssContext.getCurrent().getLocale())); if (ft.isRichText()) { final SRichText rstr = ft.getRichText(); text = vtxt ? getVRichTextHtml(rstr, wrap) : getRichTextHtml(rstr, wrap); // ZSS-918 } else { text = vtxt ? escapeVText(ft.getText(), wrap) : escapeText(ft.getText(), wrap, true); // ZSS-918 } final SHyperlink hlink = cell.getHyperlink(); if (hlink != null) { text = getHyperlinkHtml(text, hlink, sheet, cell, style, ft, null); // ZSS-1018 } } return text; }
/** Gets Cell text by given row and column, it handling */ public static String getRichCellHtmlText( SSheet sheet, int row, int column, FormatResult ft, SCellStyle tbStyle) { // ZSS-1018 final SCell cell = sheet.getCell(row, column); String text = ""; if (!cell.isNull()) { final SCellStyle style = cell.getCellStyle(); boolean wrap = style.isWrapText(); boolean vtxt = style.getRotation() == 255; // ZSS-918 if (ft.isRichText()) { final SRichText rstr = ft.getRichText(); text = vtxt ? getVRichTextHtml(rstr, wrap) : getRichTextHtml(rstr, wrap); // ZSS-918 } else { text = vtxt ? escapeVText(ft.getText(), wrap) : escapeText(ft.getText(), wrap, true); // ZSS-918 } final SHyperlink hlink = cell.getHyperlink(); if (hlink != null) { text = getHyperlinkHtml(text, hlink, sheet, cell, style, ft, tbStyle); // ZSS-1018 } } return text; }
public static String getTextCSSStyle(SCell cell) { final SCellStyle style = cell.getCellStyle(); final StringBuffer sb = new StringBuffer(); Alignment textHAlign = getRealAlignment(cell); switch (textHAlign) { case RIGHT: sb.append("text-align:").append("right").append(";"); break; case CENTER: case CENTER_SELECTION: sb.append("text-align:").append("center").append(";"); break; default: break; } // ZSS-944: when rotate 90 degree, wrap must be false final int rotate90 = style.getRotation(); boolean textWrap = style.isWrapText() && rotate90 != 90 && rotate90 != -90; // ZSS-1020 if (textWrap) { sb.append("white-space:").append("pre-wrap").append(";"); // ZSS-1118 } /*else{ sb.append("white-space:").append("nowrap").append(";"); }*/ return sb.toString(); }
// Halignment determined by style alignment, text format and value type public static Alignment getRealAlignment(SCell cell) { final SCellStyle style = cell.getCellStyle(); CellType type = cell.getType(); Alignment align = style.getAlignment(); if (align == Alignment.GENERAL) { // ZSS-918: vertical text default to horizontal center; no matter the type final boolean vtxt = style.getRotation() == 255; if (vtxt) return Alignment.CENTER; // ZSS-1020: 90 degree text default to horizontal right; no matter the type final boolean deg90 = style.getRotation() == 90; if (deg90) return Alignment.RIGHT; final String format = style.getDataFormat(); if (format != null && format.startsWith("@")) // a text format type = CellType.STRING; else if (type == CellType.FORMULA) type = cell.getFormulaResultType(); switch (type) { case BLANK: return align; case BOOLEAN: return Alignment.CENTER; case ERROR: return Alignment.CENTER; case NUMBER: return Alignment.RIGHT; case STRING: default: return Alignment.LEFT; } } return align; }
public CellFormatHelper(SSheet sheet, int row, int col, MergeMatrixHelper mmhelper) { _sheet = sheet; _row = row; _col = col; _cell = sheet.getCell(row, col); _cellStyle = _cell.getCellStyle(); _mmHelper = mmhelper; _formatEngine = EngineFactory.getInstance().createFormatEngine(); }
// @since 3.8.0 public String getRealHtmlStyle(FormatResult ft, SCellStyle tbCellStyle) { // ZSS-977 if (!_cell.isNull()) { final StringBuffer sb = new StringBuffer(); sb.append( getFontHtmlStyle( _sheet, _cell, _cell.getCellStyle(), ft, tbCellStyle)); // ZSS-977, ZSS-1018 sb.append(getIndentCSSStyle(_cell)); return sb.toString(); } return ""; }
// ZSS-725 public static String getRichTextEditCellHtml(SSheet sheet, int row, int column) { final SCell cell = sheet.getCell(row, column); String text = ""; if (!cell.isNull()) { boolean wrap = cell.getCellStyle().isWrapText(); final FormatResult ft = EngineFactory.getInstance() .createFormatEngine() .format(cell, new FormatContext(ZssContext.getCurrent().getLocale())); if (ft.isRichText()) { final SRichText rstr = ft.getRichText(); text = RichTextHelper.getCellRichTextHtml(rstr, wrap); } else { text = RichTextHelper.getFontTextHtml( escapeText(ft.getText(), wrap, true), cell.getCellStyle().getFont()); } } return text; }
/** Gets Cell text by given row and column */ public static String getCellHtmlText( SSheet sheet, int row, int column, FormatResult ft, SCellStyle tbStyle) { // ZSS-1018 final SCell cell = sheet.getCell(row, column); String text = ""; if (cell != null) { boolean wrap = cell.getCellStyle().isWrapText(); if (ft.isRichText()) { final SRichText rstr = ft.getRichText(); text = rstr.getText(); } else { text = ft.getText(); } text = escapeText(text, wrap, true); } return text; }
/** Gets Cell text by given row and column */ public static String getCellHtmlText(SSheet sheet, int row, int column) { final SCell cell = sheet.getCell(row, column); String text = ""; if (cell != null) { boolean wrap = cell.getCellStyle().isWrapText(); final FormatResult ft = EngineFactory.getInstance() .createFormatEngine() .format(cell, new FormatContext(ZssContext.getCurrent().getLocale())); if (ft.isRichText()) { final SRichText rstr = ft.getRichText(); text = rstr.getText(); } else { text = ft.getText(); } text = escapeText(text, wrap, true); } return text; }