/** * Creates a Cell Style from the supplied parts * @param cellXfId The main XF for the cell. Must be a valid 0-based index into the XF table * @param cellStyleXfId Optional, style xf. A value of <code>-1</code> means no xf. * @param stylesSource Styles Source to work off */ public XSSFCellStyle(int cellXfId, int cellStyleXfId, StylesTable stylesSource, ThemesTable theme) { _cellXfId = cellXfId; _stylesSource = stylesSource; _cellXf = stylesSource.GetCellXfAt(this._cellXfId); _cellStyleXf = cellStyleXfId == -1 ? null : stylesSource.GetCellStyleXfAt(cellStyleXfId); _theme = theme; }
///** // * Perform a registration of ourselves // * to the style table // */ public long RegisterTo(StylesTable styles) { this._themes = styles.GetTheme(); short idx = (short)styles.PutFont(this, true); this._index = idx; return(idx); }
public long RegisterTo(StylesTable styles) { this._themes = styles.GetTheme(); short num = (short)styles.PutFont(this, true); this._index = num; return((long)num); }
/** * Return a copy of the font in use at a particular index. * * @param index The index. * @return A copy of the font that's currently being applied at that * index or null if no font is being applied or the * index is out of range. */ public XSSFFont GetFontAtIndex(int index) { ThemesTable themes = GetThemesTable(); int pos = 0; foreach (CT_RElt r in st.r) { int length = r.t.Length; if (index >= pos && index < pos + length) { XSSFFont fnt = new XSSFFont(ToCTFont(r.rPr)); fnt.SetThemesTable(themes); return(fnt); } pos += length; } return(null); }
/** * Records the Themes Table that is associated with * the current font, used when looking up theme * based colours and properties. */ public void SetThemesTable(ThemesTable themes) { this._themes = themes; }
protected String BuildStyle(IWorkbook workbook, ICellStyle cellStyle) { StringBuilder style = new StringBuilder(); if (workbook is HSSFWorkbook) { HSSFPalette palette = ((HSSFWorkbook)workbook).GetCustomPalette(); style.Append("white-space: pre-wrap; "); ExcelToHtmlUtils.AppendAlign(style, cellStyle.Alignment); if (cellStyle.FillPattern == FillPatternType.NoFill) { // no fill } else if (cellStyle.FillPattern == FillPatternType.SolidForeground) { //cellStyle. //HSSFColor. HSSFColor foregroundColor = palette.GetColor(cellStyle.FillForegroundColor); if (foregroundColor != null) { style.AppendFormat("background-color:{0}; ", ExcelToHtmlUtils.GetColor(foregroundColor)); } } else { HSSFColor backgroundColor = palette.GetColor(cellStyle.FillBackgroundColor); if (backgroundColor != null) { style.AppendFormat("background-color:{0}; ", ExcelToHtmlUtils.GetColor(backgroundColor)); } } } else { style.Append("white-space: pre-wrap; "); ExcelToHtmlUtils.AppendAlign(style, cellStyle.Alignment); StylesTable st = ((XSSFWorkbook)workbook).GetStylesSource(); ThemesTable tt = st.GetTheme(); if (cellStyle.FillPattern == FillPatternType.NoFill) { // no fill } else if (cellStyle.FillPattern == FillPatternType.SolidForeground) { //cellStyle IndexedColors clr = IndexedColors.ValueOf(cellStyle.FillForegroundColor); string hexstring = null; if (clr != null) { hexstring = clr.HexString; } else { XSSFColor foregroundColor = (XSSFColor)cellStyle.FillForegroundColorColor; if (foregroundColor != null) { hexstring = ExcelToHtmlUtils.GetColor(foregroundColor); } } if (hexstring != null) { style.AppendFormat("background-color:{0}; ", hexstring); } } else { IndexedColors clr = IndexedColors.ValueOf(cellStyle.FillBackgroundColor); string hexstring = null; if (clr != null) { hexstring = clr.HexString; } else { XSSFColor backgroundColor = (XSSFColor)cellStyle.FillBackgroundColorColor; if (backgroundColor != null) { hexstring = ExcelToHtmlUtils.GetColor(backgroundColor); } } if (hexstring != null) { style.AppendFormat("background-color:{0}; ", hexstring); } } } BuildStyle_Border(workbook, style, "top", cellStyle.BorderTop, cellStyle.TopBorderColor); BuildStyle_Border(workbook, style, "right", cellStyle.BorderRight, cellStyle.RightBorderColor); BuildStyle_Border(workbook, style, "bottom", cellStyle.BorderBottom, cellStyle.BottomBorderColor); BuildStyle_Border(workbook, style, "left", cellStyle.BorderLeft, cellStyle.LeftBorderColor); IFont font = cellStyle.GetFont(workbook); BuildStyle_Font(workbook, style, font); return(style.ToString()); }
/** * Creates a Cell Border from the supplied XML defInition */ public XSSFCellBorder(CT_Border border, ThemesTable theme) : this(border) { this._theme = theme; }
internal override void OnDocumentRead() { try { this.workbook = WorkbookDocument.Parse(this.GetPackagePart().GetInputStream()).Workbook; Dictionary <string, XSSFSheet> dictionary = new Dictionary <string, XSSFSheet>(); foreach (POIXMLDocumentPart relation in this.GetRelations()) { if (relation is SharedStringsTable) { this.sharedStringSource = (SharedStringsTable)relation; } else if (relation is StylesTable) { this.stylesSource = (StylesTable)relation; } else if (relation is ThemesTable) { this.theme = (ThemesTable)relation; } else if (relation is CalculationChain) { this.calcChain = (CalculationChain)relation; } else if (relation is MapInfo) { this.mapInfo = (MapInfo)relation; } else if (relation is XSSFSheet) { dictionary.Add(relation.GetPackageRelationship().Id, (XSSFSheet)relation); } } if (this.stylesSource != null) { this.stylesSource.SetTheme(this.theme); } if (this.sharedStringSource == null) { this.sharedStringSource = (SharedStringsTable)this.CreateRelationship((POIXMLRelation)XSSFRelation.SHARED_STRINGS, (POIXMLFactory)XSSFFactory.GetInstance()); } this.sheets = new List <XSSFSheet>(dictionary.Count); foreach (CT_Sheet ctSheet in this.workbook.sheets.sheet) { XSSFSheet xssfSheet = dictionary[ctSheet.id]; if (xssfSheet == null) { XSSFWorkbook.logger.Log(5, (object)("Sheet with name " + ctSheet.name + " and r:id " + ctSheet.id + " was defined, but didn't exist in package, skipping")); } else { xssfSheet.sheet = ctSheet; xssfSheet.OnDocumentRead(); this.sheets.Add(xssfSheet); } } this.namedRanges = new List <XSSFName>(); if (!this.workbook.IsSetDefinedNames()) { return; } foreach (CT_DefinedName name in this.workbook.definedNames.definedName) { this.namedRanges.Add(new XSSFName(name, this)); } } catch (XmlException ex) { throw new POIXMLException((Exception)ex); } }