public void GetStyleByName_Null() { TextDocument document = new TextDocument(); document.New(); StyleCollection collection = new StyleCollection(); IStyle nullStyle = new TableStyle(document, string.Empty); collection.Add(nullStyle); Assert.AreEqual(nullStyle, collection.GetStyleByName(null)); }
/// <summary> /// Creates the table style. /// </summary> /// <param name="styleNode">The style node.</param> private void CreateTableStyle(XmlNode styleNode) { TableStyle tableStyle = new TableStyle(this._document); tableStyle.Node = styleNode.CloneNode(true); IPropertyCollection pCollection = new IPropertyCollection(); if (styleNode.HasChildNodes) { foreach(XmlNode node in styleNode.ChildNodes) { IProperty property = this.GetProperty(tableStyle, node.CloneNode(true)); if (property != null) pCollection.Add(property); } } tableStyle.Node.InnerXml = ""; foreach(IProperty property in pCollection) tableStyle.PropertyCollection.Add(property); if (!this._common) this._document.Styles.Add(tableStyle); else this._document.CommonStyles.Add(tableStyle); }
/// <summary> /// Gets the table style as HTML. /// </summary> /// <param name="tableStyle">The table style.</param> /// <returns></returns> public string GetTableStyleAsHtml(TableStyle tableStyle) { string style = ""; try { if (tableStyle != null) { if (tableStyle.TableProperties != null) { if (tableStyle.TableProperties.Width != null) { string width = tableStyle.TableProperties.Width; if (width.EndsWith("cm")) width = width.Replace("cm", ""); else if (width.EndsWith("in")) width = width.Replace("in", ""); try { double wd = Convert.ToDouble(width, System.Globalization.NumberFormatInfo.InvariantInfo); string wdPx = ""; if (tableStyle.TableProperties.Width.EndsWith("cm")) wdPx = SizeConverter.CmToPixelAsString(wd); else if (tableStyle.TableProperties.Width.EndsWith("in")) wdPx = SizeConverter.InchToPixelAsString(wd); if (wdPx.Length > 0) style = "width=\""+wdPx.Replace("px", "")+"\" "; } catch(Exception ex) { if (this.OnWarning != null) { AODLWarning warning = new AODLWarning("Exception while trying to build a table width width.: " + tableStyle.TableProperties.Width, ex); //warning.InMethod = AODLException.GetExceptionSourceInfo(new StackFrame(1, true)); //warning.OriginalException = ex; OnWarning(warning); } } } if (tableStyle.TableProperties.Align != null) if (tableStyle.TableProperties.Align != "margin") if (tableStyle.TableProperties.Align == "center") style += "align=\"center\" "; else if (tableStyle.TableProperties.Align == "right") style += "align=\"center\" "; //Because display prob by some browser } } } catch(Exception ex) { throw new AODLException("Exception while trying to build a HTML style string from a TableStyle.", ex); } return style; }