/// <summary>Applies column styles.</summary> public virtual void ApplyColStyles() { if (colgroups.IsEmpty() || maxIndex != -1) { return; } FinalizeColgroups(); RowColHelper tableRowColHelper = new RowColHelper(); RowColHelper headerRowColHelper = new RowColHelper(); RowColHelper footerRowColHelper = new RowColHelper(); IElementNode element; foreach (INode child in tableElement.ChildNodes()) { if (child is IElementNode) { element = (IElementNode)child; if (TagConstants.THEAD.Equals(element.Name())) { ApplyColStyles(element, headerRowColHelper); } else { if (TagConstants.TFOOT.Equals(element.Name())) { ApplyColStyles(element, footerRowColHelper); } else { ApplyColStyles(element, tableRowColHelper); } } } } }
/// <summary>Applies column styles.</summary> /// <param name="node">the node</param> /// <param name="rowColHelper">the helper class to keep track of the position inside the table</param> private void ApplyColStyles(INode node, RowColHelper rowColHelper) { int col; IElementNode element; foreach (INode child in node.ChildNodes()) { if (child is IElementNode) { element = (IElementNode)child; if (TagConstants.TR.Equals(element.Name())) { ApplyColStyles(element, rowColHelper); rowColHelper.NewRow(); } else { if (TagConstants.TH.Equals(element.Name()) || TagConstants.TD.Equals(element.Name())) { int?colspan = CssUtils.ParseInteger(element.GetAttribute(AttributeConstants.COLSPAN)); int?rowspan = CssUtils.ParseInteger(element.GetAttribute(AttributeConstants.ROWSPAN)); colspan = colspan != null ? colspan : 1; rowspan = rowspan != null ? rowspan : 1; col = rowColHelper.MoveToNextEmptyCol(); if (GetColWrapper(col) != null) { ColWrapper colWrapper = GetColWrapper(col); if (colWrapper.GetCellCssProps() != null) { element.AddAdditionalHtmlStyles(colWrapper.GetCellCssProps()); } String elemLang = element.GetAttribute(AttributeConstants.LANG); String trLang = null; if (node is IElementNode) { trLang = ((IElementNode)node).GetAttribute(AttributeConstants.LANG); } if (trLang == null && colWrapper.GetLang() != null && elemLang == null) { element.GetAttributes().SetAttribute(AttributeConstants.LANG, colWrapper.GetLang()); } } rowColHelper.UpdateCurrentPosition((int)colspan, (int)rowspan); } else { ApplyColStyles(child, rowColHelper); } } } } }
/// <summary>Applies column styles.</summary> /// <param name="node">the node</param> /// <param name="rowColHelper">the helper class to keep track of the position inside the table</param> private void ApplyColStyles(INode node, RowColHelper rowColHelper) { int col; IElementNode element; foreach (INode child in node.ChildNodes()) { if (child is IElementNode) { element = (IElementNode)child; if (element.Name().Equals(TagConstants.TR)) { ApplyColStyles(element, rowColHelper); rowColHelper.NewRow(); } else { if (element.Name().Equals(TagConstants.TH) || element.Name().Equals(TagConstants.TD)) { int?colspan = CssUtils.ParseInteger(element.GetAttribute(AttributeConstants.COLSPAN)); int?rowspan = CssUtils.ParseInteger(element.GetAttribute(AttributeConstants.ROWSPAN)); colspan = colspan != null ? colspan : 1; rowspan = rowspan != null ? rowspan : 1; col = rowColHelper.MoveToNextEmptyCol(); if (GetColWrapper(col) != null && GetColWrapper(col).GetCellCssProps() != null) { element.AddAdditionalHtmlStyles(GetColWrapper(col).GetCellCssProps()); } rowColHelper.UpdateCurrentPosition((int)colspan, (int)rowspan); } else { ApplyColStyles(child, rowColHelper); } } } } }