public void ItemTest() { StyleCollection target = new StyleCollection(); StyleDefn defn = new StyleDefn(); defn.Border.Color = PDFColors.Red; defn.Border.Width = 10; target.Add(defn); StyleDefn defn2 = new StyleDefn(); defn2.Border.Color = PDFColors.Gray; defn2.Border.Width = 2; target.Add(defn2); int index = 0; StyleBase expected = defn; StyleBase actual = target[index]; Assert.AreEqual(expected, actual); index = 1; expected = defn2; actual = target[index]; Assert.AreEqual(expected, actual); expected = defn; target[index] = defn; actual = target[index]; Assert.AreEqual(expected, actual); }
void AddStyles() { StyleCollection styles = book.Styles; Style style1 = styles.Add("Style 1"); style1.Fill.PatternType = PatternType.Solid; style1.Fill.BackgroundColor = blueFillColor; style1.Font.Color = blueFontColor; style1.Font.Name = "Segoe UI"; style1.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Left; style1.Alignment.Vertical = SpreadsheetVerticalAlignment.Center; style1.Alignment.Indent = 2; Style style2 = styles.Add("Style 2"); style2.Fill.PatternType = PatternType.Solid; style2.Fill.BackgroundColor = blueBorderColor; style2.Font.Color = blueFontColor; style2.Font.Name = "Segoe UI"; style2.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Left; style2.Alignment.Vertical = SpreadsheetVerticalAlignment.Center; style2.Alignment.Indent = 2; Style style3 = styles.Add("Style 3"); style3.Fill.PatternType = PatternType.Solid; style3.Fill.BackgroundColor = Color.FromArgb(255, 255, 255, 255); style3.Font.Color = Color.FromArgb(255, 0, 0, 0); style3.Font.Name = "Segoe UI"; style3.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center; style3.Alignment.Vertical = SpreadsheetVerticalAlignment.Center; style3.Flags.Number = false; }
public void MergeIntoTest() { StyleCollection target = new StyleCollection(); StyleDefn defn = new StyleDefn(); defn.Match = "doc:Label.sea"; defn.Border.Color = PDFColors.Red; defn.Border.Width = 10; defn.Font.FontFamily = (PDFFontSelector)"Helvetica"; target.Add(defn); StyleDefn defn2 = new StyleDefn(); defn2.Match = ".sea"; // lower priority defn2.Border.Color = PDFColors.Gray; defn2.Columns.ColumnCount = 3; target.Add(defn2); StyleDefn defn3 = new StyleDefn(); defn3.AppliedClass = "other"; defn3.Border.Width = 20; defn3.Stroke.Color = PDFColors.Aqua; target.Add(defn3); Label lbl = new Label(); lbl.ElementName = "doc:Label"; ComponentState state = ComponentState.Normal; Style style = new Style(); target.MergeInto(style, lbl, state); style.Flatten(); Assert.IsFalse(style.HasValues);//no style class on the label lbl.StyleClass = "sea"; style = new Style(); target.MergeInto(style, lbl, state); style.Flatten(); Assert.AreEqual(PDFColors.Red, style.Border.Color); //from defn as higher priority Assert.AreEqual((PDFUnit)10, style.Border.Width); // from defn (defn2 has no width) Assert.AreEqual((PDFFontSelector)"Helvetica", style.Font.FontFamily); //from defn Assert.AreEqual(3, style.Columns.ColumnCount); //from defn2 (lower priority but not set on defn) Assert.IsFalse(style.IsValueDefined(StyleKeys.StrokeColorKey)); //defn3 does have a stroke, but shoulld not be included }
public void StyleCollection_GetEnumerator_2() { // Arrange var list = new StyleCollection(); list.Add(new Style("id1")); list.Add(new Style("id2")); // Act var enumerator = (list as IEnumerable).GetEnumerator(); // Assert Assert.IsNotNull(enumerator); }
public void GetStyleByName() { TextDocument document = new TextDocument(); document.New(); StyleCollection collection = new StyleCollection(); collection.Add(new TableStyle(document, "a")); collection.Add(new TableStyle(document, "b")); IStyle nullStyle = new TableStyle(document, string.Empty); collection.Add(nullStyle); Assert.AreEqual("a", collection.GetStyleByName("a").StyleName); Assert.AreEqual("b", collection.GetStyleByName("b").StyleName); Assert.AreEqual(nullStyle, collection.GetStyleByName(string.Empty)); }
public void StyleCollection() { //ExStart //ExFor:StyleCollection.Add(Style) //ExFor:StyleCollection.Count //ExFor:StyleCollection.DefaultFont //ExFor:StyleCollection.DefaultParagraphFormat //ExFor:StyleCollection.Item(StyleIdentifier) //ExFor:StyleCollection.Item(Int32) //ExSummary:Shows how to add a Style to a document's styles collection. Document doc = new Document(); StyleCollection styles = doc.Styles; // Set default parameters for new styles that we may later add to this collection. styles.DefaultFont.Name = "Courier New"; // If we add a style of the "StyleType.Paragraph", the collection will apply the values of // its "DefaultParagraphFormat" property to the style's "ParagraphFormat" property. styles.DefaultParagraphFormat.FirstLineIndent = 15.0; // Add a style, and then verify that it has the default settings. styles.Add(StyleType.Paragraph, "MyStyle"); Assert.AreEqual("Courier New", styles[4].Font.Name); Assert.AreEqual(15.0, styles["MyStyle"].ParagraphFormat.FirstLineIndent); //ExEnd }
protected virtual void ParseCssStyles(StyleCollection collection, string content, PDFContextBase context) { bool parseCss = true; if (!string.IsNullOrEmpty(this.Relationship)) { if (this.Relationship.Equals("stylesheet", StringComparison.OrdinalIgnoreCase) == false) { parseCss = false; } } if (parseCss) { var parser = new Scryber.Styles.Parsing.CSSStyleParser(content, context); foreach (var style in parser) { if (null != style) { collection.Add(style); } } } }
public void ParseCSSWithComments_Performance() { var css = commentedCSS; int repeatCount = 1000; Stopwatch counter = Stopwatch.StartNew(); for (int i = 0; i < repeatCount; i++) { var cssparser = new Scryber.Styles.Parsing.CSSStyleParser(css, null); StyleCollection col = new StyleCollection(); foreach (var style in cssparser) { col.Add(style); } } counter.Stop(); var elapsed = counter.Elapsed.TotalMilliseconds / repeatCount; Assert.IsTrue(elapsed < 0.20, "Took too long to parse. Expected < 0.15ms per string, Actual : " + elapsed + "ms"); }
public void StyleCollection() { //ExStart //ExFor:StyleCollection.Add(Style) //ExFor:StyleCollection.Count //ExFor:StyleCollection.DefaultFont //ExFor:StyleCollection.DefaultParagraphFormat //ExFor:StyleCollection.Item(StyleIdentifier) //ExFor:StyleCollection.Item(Int32) //ExSummary:Shows how to add a Style to a StyleCollection. Document doc = new Document(); // New documents come with a collection of default styles that can be applied to paragraphs StyleCollection styles = doc.Styles; Assert.AreEqual(4, styles.Count); // We can set default parameters for new styles that will be added to the collection from now on styles.DefaultFont.Name = "Courier New"; styles.DefaultParagraphFormat.FirstLineIndent = 15.0; styles.Add(StyleType.Paragraph, "MyStyle"); // Styles within the collection can be referenced either by index or name Assert.AreEqual("Courier New", styles[4].Font.Name); Assert.AreEqual(15.0, styles["MyStyle"].ParagraphFormat.FirstLineIndent); //ExEnd }
public void ReturnsCorrectly() { string definitionName1 = "DefinitionName1"; string definitionValue1 = "DefinitionValue1"; string definitionName2 = "DefinitionName2"; string definitionValue2 = "DefinitionValue2"; var styles = new StyleCollection(); styles.Add( definitionName1, definitionValue1 ); styles.Add( definitionName2, definitionValue2 ); var result = styles.ToString(); string expectedResult = string.Format( "{0}:{1};{2}:{3}", definitionName1, definitionValue1, definitionName2, definitionValue2 ); Assert.AreEqual( expectedResult, result ); }
public void GetStyleByName() { TextDocument document = new TextDocument(); document.New(); StyleCollection collection = new StyleCollection(); collection.Add(new TableStyle(document, "a")); collection.Add(new TableStyle(document, "b")); IStyle nullStyle = new TableStyle(document, string.Empty); collection.Add(nullStyle); Assert.AreEqual("a", collection.GetStyleByName("a").StyleName); Assert.AreEqual("b", collection.GetStyleByName("b").StyleName); Assert.AreEqual(nullStyle, collection.GetStyleByName(string.Empty)); }
public void CSSParserWithComments() { var css = @" /* This is the grey body */ body.grey { background-color:#808080; /* body background */ color: #222; } body.grey div /* Inner divs */{ padding: 10px; /*color: #AAA;*/ margin:15px; } body.grey div.reverse{ /* Reverse the colors */ background-color: #222; color:#808080; }"; var cssparser = new Scryber.Styles.Parsing.CSSStyleParser(css, null); StyleCollection col = new StyleCollection(); foreach (var style in cssparser) { col.Add(style); } Assert.AreEqual(3, col.Count); //First one var one = col[0] as StyleDefn; Assert.AreEqual("body.grey", one.Match.ToString()); Assert.AreEqual(2, one.ValueCount); Assert.AreEqual((PDFColor)"#808080", one.GetValue(StyleKeys.BgColorKey, PDFColors.Transparent)); Assert.AreEqual((PDFColor)"#222", one.GetValue(StyleKeys.FillColorKey, PDFColors.Transparent)); var two = col[1] as StyleDefn; Assert.AreEqual("body.grey div", two.Match.ToString()); Assert.AreEqual(10, two.ValueCount); //All, Top, Left, Bottom and Right are all set for Margins and Padding // 96 pixels per inch, 72 points per inch Assert.AreEqual(7.5, two.GetValue(StyleKeys.PaddingAllKey, PDFUnit.Zero).PointsValue); Assert.AreEqual(11.25, two.GetValue(StyleKeys.MarginsAllKey, PDFUnit.Zero).PointsValue); var three = col[2] as StyleDefn; Assert.AreEqual("body.grey div.reverse", three.Match.ToString()); Assert.AreEqual(2, one.ValueCount); Assert.AreEqual((PDFColor)"#222", three.GetValue(StyleKeys.BgColorKey, PDFColors.Transparent)); Assert.AreEqual((PDFColor)"#808080", three.GetValue(StyleKeys.FillColorKey, PDFColors.Transparent)); }
void AddStyles() { StyleCollection styles = book.Styles; Style style1 = styles.Add("Style 1"); style1.Fill.PatternType = PatternType.Solid; style1.Fill.BackgroundColor = Color.FromArgb(255, 255, 255, 255); style1.Font.Color = Color.FromArgb(255, 218, 0, 0); style1.Font.Size = 36; style1.Font.Name = "Calibri Light"; style1.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Left; style1.Alignment.Vertical = SpreadsheetVerticalAlignment.Center; Style style2 = styles.Add("Style 2"); style2.Fill.PatternType = PatternType.Solid; style2.Fill.BackgroundColor = Color.FromArgb(255, 255, 255, 255); style2.Font.Color = Color.FromArgb(255, 89, 89, 89); style2.Font.Size = 18; style2.Font.Name = "Calibri Light"; Style style3 = styles.Add("Style 3"); style3.Fill.PatternType = PatternType.Solid; style3.Fill.BackgroundColor = Color.FromArgb(255, 89, 89, 89); style3.Font.Color = Color.FromArgb(255, 255, 255, 255); style3.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center; Style style4 = styles.Add("Style 4"); style4.Fill.PatternType = PatternType.Solid; style4.Fill.BackgroundColor = Color.FromArgb(255, 255, 255, 255); style4.Font.Color = Color.FromArgb(255, 89, 89, 89); style4.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center; style4.NumberFormat = "0"; Style style5 = styles.Add("Style 5"); style5.Fill.PatternType = PatternType.Solid; style5.Fill.BackgroundColor = Color.FromArgb(255, 238, 238, 238); style5.Font.Color = Color.FromArgb(255, 89, 89, 89); style5.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center; style5.NumberFormat = "0"; }
public void OwnerTest() { Document doc = new Document(); doc.ID = "First Document"; //doc.Styles should be initialized with the document as it's owner StyleCollection col = doc.Styles; Assert.AreEqual(doc, col.Owner); //A non IPDFComponent entry - make sure there are not cast exceptions Style unowned = new Style(); col.Add(unowned); //An IPDFComponent entry - so should have it's parent value set StylesDocument styleDoc = new StylesDocument(); col.Add(styleDoc); //parent should automatically be set on the styleDoc from the parent. Assert.AreEqual(doc, styleDoc.Parent); //Changing the owner should pass through Document other = new Document(); other.ID = "Other Document"; col.Owner = other; Assert.AreEqual(other, styleDoc.Parent); //removing the time should not set the owner. col.Remove(styleDoc); Assert.IsNull(styleDoc.Parent); //multiple hierarchy StylesDocument inner = new StylesDocument(); styleDoc.Styles.Add(inner); doc.Styles.Add(styleDoc); Assert.AreEqual(inner.Parent, styleDoc); Assert.AreEqual(other, styleDoc.Parent); }
void CreateStyles() { Style style1 = styles.Add("Style 1"); style1.Font.Size = 12; style1.Fill.PatternType = PatternType.Solid; style1.Fill.BackgroundColor = Color.FromArgb(255, 255, 255, 255); style1.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Left; style1.Alignment.Vertical = SpreadsheetVerticalAlignment.Center; style1.Alignment.Indent = 1; }
public void StyleCollection_Add() { // Arrange var style = new Style("id"); var list = new StyleCollection(); // Act list.Add(style); // Assert Assert.AreEqual(1, list.Count); }
public Document() { Elements = new ElementCollection <DocumentElement>(this); PageItems = new ElementCollection <DocumentElement>(this); Styles = new StyleCollection(); Measurements = new Measurements(); Document = this; foreach (var style in StyleReader.GetDefaultStyles()) { Styles.Add(style); } }
void CreateStyles() { StyleCollection styles = book.Styles; Style style1 = styles.Add("Style 1"); style1.Font.FontStyle = DevExpress.Spreadsheet.SpreadsheetFontStyle.Bold; style1.Font.Color = Color.FromArgb(255, 180, 180, 180); style1.Font.Size = 9; style1.Font.Name = "Segoe UI"; Style style2 = styles.Add("Style 2"); style2.Font.FontStyle = DevExpress.Spreadsheet.SpreadsheetFontStyle.Bold; style2.Font.Color = Color.FromArgb(255, 52, 150, 151); style2.Font.Size = 9; style2.Font.Name = "Segoe UI"; Style style3 = styles.Add("Style 3"); style3.Fill.PatternType = PatternType.Solid; style3.Fill.BackgroundColor = Color.FromArgb(255, 251, 251, 251); style3.Font.Color = Color.FromArgb(255, 0, 0, 0); style3.Flags.Font = false; Style style4 = styles.Add("Style 4"); style4.Fill.PatternType = PatternType.Solid; style4.Fill.BackgroundColor = Color.FromArgb(255, 237, 237, 237); style4.Font.Color = Color.FromArgb(255, 0, 0, 0); style4.Flags.Font = false; Style style5 = styles.Add("Style 5"); style5.Fill.PatternType = PatternType.Solid; style5.Fill.BackgroundColor = Color.FromArgb(255, 241, 241, 241); style5.Font.Color = Color.FromArgb(255, 0, 0, 0); style5.Flags.Font = false; Style style6 = styles.Add("Style 6"); style6.Fill.PatternType = PatternType.Solid; style6.Fill.BackgroundColor = Color.FromArgb(255, 242, 252, 252); style6.Font.Color = Color.FromArgb(255, 0, 0, 0); style6.Flags.Font = false; Style style7 = styles.Add("Style 7"); style7.Fill.PatternType = PatternType.Solid; style7.Fill.BackgroundColor = Color.FromArgb(255, 229, 238, 238); style7.Font.Color = Color.FromArgb(255, 0, 0, 0); style7.Flags.Font = false; }
public void StyleCollection_OuterXml() { // Arrange var style = new Style("id"); var list = new StyleCollection(); list.Add(style); // Act var xml = list.OuterXml; // Assert Assert.IsNotNull(xml); }
public void StyleCollection_Contains() { // Arrange var style = new Style("id"); var list = new StyleCollection(); list.Add(style); // Act var value = list.Contains(style); // Assert Assert.IsTrue(value); }
public void ParseCSSWithComments() { var css = commentedCSS; var cssparser = new Scryber.Styles.Parsing.CSSStyleParser(css, null); StyleCollection col = new StyleCollection(); foreach (var style in cssparser) { col.Add(style); } Assert.AreEqual(3, col.Count); //First one var one = col[0] as StyleDefn; Assert.AreEqual("body.grey", one.Match.ToString()); Assert.AreEqual(2, one.ValueCount); Assert.AreEqual((PDFColor)"#808080", one.GetValue(StyleKeys.BgColorKey, PDFColors.Transparent)); Assert.AreEqual((PDFColor)"#222", one.GetValue(StyleKeys.FillColorKey, PDFColors.Transparent)); var two = col[1] as StyleDefn; Assert.AreEqual("body.grey div", two.Match.ToString()); Assert.AreEqual(10, two.ValueCount); //All, Top, Left, Bottom and Right are all set for Margins and Padding // 96 pixels per inch, 72 points per inch Assert.AreEqual(7.5, two.GetValue(StyleKeys.PaddingAllKey, PDFUnit.Zero).PointsValue); Assert.AreEqual(11.25, two.GetValue(StyleKeys.MarginsAllKey, PDFUnit.Zero).PointsValue); var three = col[2] as StyleDefn; Assert.AreEqual("body.grey div.reverse", three.Match.ToString()); Assert.AreEqual(2 + 4 + 4, three.ValueCount); //2 colors and 4 each for margins and padding Assert.AreEqual((PDFColor)"#222", three.GetValue(StyleKeys.BgColorKey, PDFColors.Transparent)); Assert.AreEqual((PDFColor)"#808080", three.GetValue(StyleKeys.FillColorKey, PDFColors.Transparent)); Assert.AreEqual((PDFUnit)20, three.GetValue(StyleKeys.MarginsTopKey, 0.0)); Assert.AreEqual((PDFUnit)20, three.GetValue(StyleKeys.MarginsBottomKey, 0.0)); Assert.AreEqual((PDFUnit)10, three.GetValue(StyleKeys.MarginsLeftKey, 0.0)); Assert.AreEqual((PDFUnit)10, three.GetValue(StyleKeys.MarginsRightKey, 0.0)); Assert.AreEqual((PDFUnit)10, three.GetValue(StyleKeys.PaddingTopKey, 0.0)); Assert.AreEqual((PDFUnit)5, three.GetValue(StyleKeys.PaddingRightKey, 0.0)); Assert.AreEqual((PDFUnit)15, three.GetValue(StyleKeys.PaddingBottomKey, 0.0)); Assert.AreEqual((PDFUnit)1, three.GetValue(StyleKeys.PaddingLeftKey, 0.0)); }
public void StyleCollection_Remove() { // Arrange var style = new Style("id"); var list = new StyleCollection(); list.Add(style); // Act var value = list.Remove(style); // Assert Assert.AreEqual(0, list.Count); Assert.IsTrue(value); }
private void btnAdd_Click(object sender, EventArgs e) { Style s = new Style(); int styleNumber = 1; string baseName = Res.Get("Forms,Style,StyleName"); while (FStyles.IndexOf(baseName + styleNumber.ToString()) != -1) { styleNumber++; } s.Name = baseName + styleNumber.ToString(); FStyles.Add(s); ListViewItem li = lvStyles.Items.Add(s.Name, 87); li.Tag = s; li.BeginEdit(); }
public void StyleCollection_CopyTo() { // Arrange var style = new Style("id"); var list = new StyleCollection(); list.Add(style); var items = new Style[1]; // Act list.CopyTo(items, 0); // Assert Assert.AreEqual(style, items[0]); }
/// <summary> /// Gets the style used to add spacing between RenderTable cells and their content /// (corresponds to flex grid CellStyle.Margins; TableCell.Style cannot be used for that). /// (Other style props can be added here as needed.) /// </summary> /// <param name="cellStyle">The grid cell style.</param> /// <param name="styles">The C1PrintDocument styles collection to which a new style may be added.</param> /// <returns>The style to set as Parent for TableCell.RenderObject.Style.</returns> /// <remarks> /// An example of non-ambient attribute that IS supported by table cells is Borders - /// hence it is handled by TableCell.Style. /// </remarks> private Style CellRoStyleFromGridStyle(CellStyle cellStyle, StyleCollection styles) { string key = BuildCellRoStyleKey(cellStyle); if (_cellRoStyles.ContainsKey(key)) { return(_cellRoStyles[key]); } Style s = styles.Add(); // Convert flex Margins to Spacing between cell's RO and cell's borders: const int addWidth = 0;// 2; s.Spacing.Left = PixelsToUnit(cellStyle.Margins.Left + addWidth); s.Spacing.Top = PixelsToUnit(cellStyle.Margins.Top); s.Spacing.Right = PixelsToUnit(cellStyle.Margins.Right + addWidth); s.Spacing.Bottom = PixelsToUnit(cellStyle.Margins.Bottom); _cellRoStyles[key] = s; return(s); }
/// <summary> /// Gets the C1PrintDocument style corresponding to the specified C1FlexGrid cell style. /// If the required style has not been created yet, it is created and added to the _styles /// hashtable for reuse. /// </summary> /// <param name="cellStyle">The grid cell style.</param> /// <param name="styles">The C1PrintDocument styles collection to which a new style may be added.</param> /// <param name="dataType">The grid cell data type (used to disambiguate general text alignment).</param> /// <param name="value">The grid cell text (used to disambiguate general text alignment).</param> /// <param name="edges">Outer edges of the table on which the cell borders.</param> /// <param name="borderLeft">The left border of the cell (which is the right border of the cell on the left).</param> /// <param name="borderTop">The top border of the cell (which is the bottom border of the cell on the top).</param> /// <returns>The style to apply to the RenderTable cell.</returns> private Style StyleFromGridStyle(CellStyle cellStyle, StyleCollection styles, Type dataType, string value, EdgeEnum edges, LineDef borderLeft, LineDef borderTop) { string key = BuildCellStyleKey(cellStyle, dataType, value, edges, borderLeft, borderTop); // if a matching style already exists just use it: if (_styles.ContainsKey(key)) { return(_styles[key]); } Style s = styles.Add(); // we do not want to inherit any non-ambient properties from the "styles" owner - // all that is needed will be explicitly set by CopyCellStyle: s.Parent = null; // build the style based on cell style and other data: CopyCellStyle(s, cellStyle, dataType, value, edges, borderLeft, borderTop); // add the style to the hashtable for reuse, and return: _styles[key] = s; return(s); }
protected virtual void AddCssStyles(StyleCollection collection, PDFContextBase context) { if (!string.IsNullOrEmpty(this.StyleType)) { if (this.StyleType.Equals("text/css", StringComparison.OrdinalIgnoreCase) == false) { return; } } if (!string.IsNullOrEmpty(this.Media)) { if (this.Media == "all" || this.Media.StartsWith("all ")) { ; } else if (this.Media == "print" || this.Media.StartsWith("print ")) { ; } else { return; } } var parser = new Scryber.Styles.Parsing.CSSStyleParser(this.Contents, context); foreach (var style in parser) { if (null != style) { collection.Add(style); } } }
public Workbook CreateCatalog() { //Open a template file string designerFile = MapPath("~/App_Data/xls/Northwind.xls"); Workbook workbook = new Workbook(designerFile); productsList = productDao.GetAll(); CategoryList = categoryDao.GetAll(); //Create a new datatable DataTable dataTable2 = new DataTable(); //Get a worksheet Worksheet sheet = workbook.Worksheets["Sheet2"]; //Name the sheet sheet.Name = "Catalog"; //Get the worksheet cells Aspose.Cells.Cells cells = sheet.Cells; int currentRow = 55; //Add LightGray color to color palette workbook.ChangePalette(Color.LightGray, 55); //Get the workbook's styles collection StyleCollection styles = workbook.Styles; //Set CategoryName style with formatting attributes int styleIndex = styles.Add(); Style styleCategoryName = styles[styleIndex]; styleCategoryName.Font.Size = 14; styleCategoryName.Font.Color = Color.Blue; styleCategoryName.Font.IsBold = true; styleCategoryName.Font.Name = "Times New Roman"; //Set Description style with formatting attributes styleIndex = styles.Add(); Style styleDescription = styles[styleIndex]; styleDescription.Font.Name = "Times New Roman"; styleDescription.Font.Color = Color.Blue; styleDescription.Font.IsItalic = true; //Set ProductName style with formatting attributes styleIndex = styles.Add(); Style styleProductName = styles[styleIndex]; styleProductName.Font.IsBold = true; //Set Title style with formatting attributes styleIndex = styles.Add(); Style styleTitle = styles[styleIndex]; styleTitle.Font.IsBold = true; styleTitle.Font.IsItalic = true; styleTitle.ForegroundColor = Color.LightGray; styleIndex = styles.Add(); Style styleNumber = styles[styleIndex]; styleNumber.Font.Name = "Times New Roman"; styleNumber.Number = 8; //Create the styleflag struct StyleFlag styleflag = new StyleFlag(); styleflag.All = true; //Get the horizontal page breaks collection HorizontalPageBreakCollection hPageBreaks = sheet.HorizontalPageBreaks; DataTable dataTable1 = ConvertCategoriesToDataTable(CategoryList); for (int i = 0; i < dataTable1.Rows.Count; i++) { currentRow += 2; cells.SetRowHeight(currentRow, 20); cells[currentRow, 1].SetStyle(styleCategoryName); DataRow categoriesRow = dataTable1.Rows[i]; //Write CategoryName cells[currentRow, 1].PutValue((string)categoriesRow["CategoryName"]); //Write Description currentRow++; cells[currentRow, 1].PutValue((string)categoriesRow["Description"]); cells[currentRow, 1].SetStyle(styleDescription); dataTable2.Clear(); dataTable2 = GetProductsByCateGoryID(Convert.ToInt32(categoriesRow["CategoryID"].ToString())); currentRow += 2; //Import the datatable to the sheet cells.ImportDataTable(dataTable2, true, currentRow, 1); //Create a range Range range = cells.CreateRange(currentRow, 1, 1, 4); //Apply style to the range range.ApplyStyle(styleTitle, styleflag); //Create a range range = cells.CreateRange(currentRow + 1, 1, dataTable2.Rows.Count, 1); //Apply style to the range range.ApplyStyle(styleProductName, styleflag); //Create a range range = cells.CreateRange(currentRow + 1, 4, dataTable2.Rows.Count, 1); //Apply style to the range range.ApplyStyle(styleNumber, styleflag); currentRow += dataTable2.Rows.Count; //Apply horizontal page breaks hPageBreaks.Add(currentRow, 0); } //Remove the unnecessary worksheets in the workbook for (int i = 0; i < workbook.Worksheets.Count; i++) { sheet = workbook.Worksheets[i]; if (sheet.Name != "Catalog") { workbook.Worksheets.RemoveAt(i); i--; } } //Return the generated workbook return(workbook); }
internal static void AddBuildIn(StyleCollection<NumberFormatXmlWrapper> NumberFormats) { NumberFormats.Add("General", new NumberFormatXmlWrapper(true) { NumFmtId = 0, Format = "General" }); NumberFormats.Add("0", new NumberFormatXmlWrapper(true) { NumFmtId = 1, Format = "0" }); NumberFormats.Add("0.00", new NumberFormatXmlWrapper(true) { NumFmtId = 2, Format = "0.00" }); NumberFormats.Add("#,##0", new NumberFormatXmlWrapper(true) { NumFmtId = 3, Format = "#,##0" }); NumberFormats.Add("#,##0.00", new NumberFormatXmlWrapper(true) { NumFmtId = 4, Format = "#,##0.00" }); NumberFormats.Add("0%", new NumberFormatXmlWrapper(true) { NumFmtId = 9, Format = "0%" }); NumberFormats.Add("0.00%", new NumberFormatXmlWrapper(true) { NumFmtId = 10, Format = "0.00%" }); NumberFormats.Add("0.00E+00", new NumberFormatXmlWrapper(true) { NumFmtId = 11, Format = "0.00E+00" }); NumberFormats.Add("# ?/?", new NumberFormatXmlWrapper(true) { NumFmtId = 12, Format = "# ?/?" }); NumberFormats.Add("# ??/??", new NumberFormatXmlWrapper(true) { NumFmtId = 13, Format = "# ??/??" }); NumberFormats.Add("mm-dd-yy", new NumberFormatXmlWrapper(true) { NumFmtId = 14, Format = "mm-dd-yy" }); NumberFormats.Add("d-mmm-yy", new NumberFormatXmlWrapper(true) { NumFmtId = 15, Format = "d-mmm-yy" }); NumberFormats.Add("d-mmm", new NumberFormatXmlWrapper(true) { NumFmtId = 16, Format = "d-mmm" }); NumberFormats.Add("mmm-yy", new NumberFormatXmlWrapper(true) { NumFmtId = 17, Format = "mmm-yy" }); NumberFormats.Add("h:mm AM/PM", new NumberFormatXmlWrapper(true) { NumFmtId = 18, Format = "h:mm AM/PM" }); NumberFormats.Add("h:mm:ss AM/PM", new NumberFormatXmlWrapper(true) { NumFmtId = 19, Format = "h:mm:ss AM/PM" }); NumberFormats.Add("h:mm", new NumberFormatXmlWrapper(true) { NumFmtId = 20, Format = "h:mm" }); //NumberFormats.Add("h:mm:dd", new NumberFormatXmlWrapper(true) { NumFmtId = 21, Format = "h:mm:dd" }); NumberFormats.Add("m/d/yy h:mm", new NumberFormatXmlWrapper(true) { NumFmtId = 22, Format = "m/d/yy h:mm" }); NumberFormats.Add("#,##0 ;(#,##0)", new NumberFormatXmlWrapper(true) { NumFmtId = 37, Format = "#,##0 ;(#,##0)" }); NumberFormats.Add("#,##0 ;[Red](#,##0)", new NumberFormatXmlWrapper(true) { NumFmtId = 38, Format = "#,##0 ;[Red](#,##0)" }); NumberFormats.Add("#,##0.00;(#,##0.00)", new NumberFormatXmlWrapper(true) { NumFmtId = 39, Format = "#,##0.00;(#,##0.00)" }); NumberFormats.Add("#,##0.00;[Red](#,#)", new NumberFormatXmlWrapper(true) { NumFmtId = 40, Format = "#,##0.00;[Red](#,#)" }); NumberFormats.Add("mm:ss", new NumberFormatXmlWrapper(true) { NumFmtId = 45, Format = "mm:ss" }); NumberFormats.Add("[h]:mm:ss", new NumberFormatXmlWrapper(true) { NumFmtId = 46, Format = "[h]:mm:ss" }); NumberFormats.Add("mmss.0", new NumberFormatXmlWrapper(true) { NumFmtId = 47, Format = "mmss.0" }); NumberFormats.Add("##0.0", new NumberFormatXmlWrapper(true) { NumFmtId = 48, Format = "##0.0" }); NumberFormats.Add("@", new NumberFormatXmlWrapper(true) { NumFmtId = 49, Format = "@" }); NumberFormats.NextId = 164; }
public void ParseCSSWithMedia() { var css = @" @media only screen and (min-width : 1224px) { body.grey{ font-family:'Times New Roman', Times, serif } body.grey div{ font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif } } /* This is the grey body */ body.grey { background-color:#808080; /* body background */ color: #222; } @media print and (orientation: landscape) { body.grey{ font-family:'Gill Sans', 'Gill Sans MT', Calibri, 'Trebuchet MS', sans-serif } } body.grey div{ padding: 10px; /*color: #AAA;*/ margin:10px; } body.grey div.reverse{ /* Reverse the colors */ background-color: #222; color:#808080; } @media print { /* Nested media selector*/ @media (orientation: portrait) { body.grey { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; font-weight: bold; } } } "; var cssparser = new Scryber.Styles.Parsing.CSSStyleParser(css, null); StyleCollection col = new StyleCollection(); foreach (var style in cssparser) { col.Add(style); } Assert.AreEqual(6, col.Count); //Top one should be a media query Assert.IsInstanceOfType(col[0], typeof(StyleMediaGroup)); var media = (StyleMediaGroup)col[0]; Assert.AreEqual("screen", media.Media.Type); Assert.AreEqual(2, media.Styles.Count); Assert.AreEqual("body.grey", (media.Styles[0] as StyleDefn).Match.ToString()); //Second one normal style Assert.IsInstanceOfType(col[1], typeof(StyleDefn)); Assert.AreEqual(2, col[1].ValueCount); //Third is a media for print Assert.IsInstanceOfType(col[2], typeof(StyleMediaGroup)); media = (StyleMediaGroup)col[2]; Assert.AreEqual("print", media.Media.Type); Assert.AreEqual(1, media.Styles.Count); Assert.AreEqual("body.grey", (media.Styles[0] as StyleDefn).Match.ToString()); //Fourth and Fifth are normal Assert.IsInstanceOfType(col[3], typeof(StyleDefn)); Assert.AreEqual(10, col[3].ValueCount); //All, Top, Left, Bottom and Right are all set for Margins and Padding Assert.AreEqual("body.grey div", (col[3] as StyleDefn).Match.ToString()); Assert.IsInstanceOfType(col[4], typeof(StyleDefn)); Assert.AreEqual(2, col[4].ValueCount); //Include the background type Assert.AreEqual("body.grey div.reverse", (col[4] as StyleDefn).Match.ToString()); //Sixth is nested Assert.IsInstanceOfType(col[5], typeof(StyleMediaGroup)); media = (StyleMediaGroup)col[5]; Assert.AreEqual("print", media.Media.Type); Assert.AreEqual(1, media.Styles.Count); Assert.IsInstanceOfType(media.Styles[0], typeof(StyleMediaGroup)); //inner item media = media.Styles[0] as StyleMediaGroup; Assert.IsTrue(string.IsNullOrEmpty(media.Media.Type)); Assert.AreEqual("(orientation: portrait)", media.Media.Features); //one inner style Assert.AreEqual(1, media.Styles.Count); Assert.AreEqual("body.grey", (media.Styles[0] as StyleDefn).Match.ToString()); }
public void ParseMinifiedCssFile() { //This is a minimised version of the styles above var path = System.Environment.CurrentDirectory; path = System.IO.Path.Combine(path, "../../../Content/HTML/CSS/include.min.css"); path = System.IO.Path.GetFullPath(path); var css = System.IO.File.ReadAllText(path); var cssparser = new Scryber.Styles.Parsing.CSSStyleParser(css, null); StyleCollection col = new StyleCollection(); foreach (var style in cssparser) { col.Add(style); } //Sames tests, just with a minimised file Assert.AreEqual(6, col.Count); //Top one should be a media query Assert.IsInstanceOfType(col[0], typeof(StyleMediaGroup)); var media = (StyleMediaGroup)col[0]; Assert.AreEqual("screen", media.Media.Type); Assert.AreEqual(2, media.Styles.Count); Assert.AreEqual("body.grey", (media.Styles[0] as StyleDefn).Match.ToString()); //Second one normal style Assert.IsInstanceOfType(col[1], typeof(StyleDefn)); Assert.AreEqual("body.grey", (media.Styles[0] as StyleDefn).Match.ToString()); Assert.AreEqual(2, col[1].ValueCount); //Third is a media for print Assert.IsInstanceOfType(col[2], typeof(StyleMediaGroup)); media = (StyleMediaGroup)col[2]; Assert.AreEqual("print", media.Media.Type); Assert.AreEqual(1, media.Styles.Count); Assert.AreEqual("body.grey", (media.Styles[0] as StyleDefn).Match.ToString()); //Fourth and Fifth are normal Assert.IsInstanceOfType(col[3], typeof(StyleDefn)); Assert.AreEqual(10, col[3].ValueCount); //All, Top, Left, Bottom and Right are all set for Margins and Padding Assert.AreEqual("body.grey div", (col[3] as StyleDefn).Match.ToString()); Assert.IsInstanceOfType(col[4], typeof(StyleDefn)); Assert.AreEqual(2, col[4].ValueCount); //Include the background type Assert.AreEqual("body.grey div.reverse", (col[4] as StyleDefn).Match.ToString()); //Sixth is nested Assert.IsInstanceOfType(col[5], typeof(StyleMediaGroup)); media = (StyleMediaGroup)col[5]; Assert.AreEqual("print", media.Media.Type); Assert.AreEqual(1, media.Styles.Count); Assert.IsInstanceOfType(media.Styles[0], typeof(StyleMediaGroup)); //inner item media = media.Styles[0] as StyleMediaGroup; Assert.IsTrue(string.IsNullOrEmpty(media.Media.Type)); Assert.AreEqual("(orientation:portrait)", media.Media.Features); //one inner style Assert.AreEqual(1, media.Styles.Count); Assert.AreEqual("body.grey", (media.Styles[0] as StyleDefn).Match.ToString()); }
void CreateThemeBlueStyles() { Style style1 = styles.Add("Style 5.1"); style1.Font.Color = Color.FromArgb(255, 44, 150, 210); style1.Font.Size = 36; style1.Font.Name = "Segoe UI"; Style style2 = styles.Add("Style 5.2"); style2.Font.Color = Color.FromArgb(255, 0, 0, 0); style2.Font.Size = 10; style2.Font.Name = "Segoe UI"; Style style3 = styles.Add("Style 5.3"); style3.Font.FontStyle = DevExpress.Spreadsheet.SpreadsheetFontStyle.Bold; style3.Font.Color = Color.FromArgb(255, 49, 118, 177); style3.Font.Size = 10; style3.Font.Name = "Segoe UI"; style3.Borders.BottomBorder.Color = Color.FromArgb(255, 167, 200, 229); style3.Borders.BottomBorder.LineStyle = BorderLineStyle.Medium; style3.Alignment.Horizontal = SpreadsheetHorizontalAlignment.Center; style3.Alignment.Vertical = SpreadsheetVerticalAlignment.Center; Style style4 = styles.Add("Style 5.4"); style4.Font.FontStyle = DevExpress.Spreadsheet.SpreadsheetFontStyle.Bold; style4.Font.Color = Color.FromArgb(255, 49, 118, 177); style4.Font.Size = 10; style4.Font.Name = "Segoe UI"; style4.Borders.BottomBorder.Color = Color.FromArgb(255, 137, 182, 220); style4.Borders.BottomBorder.LineStyle = BorderLineStyle.Medium; Style style5 = styles.Add("Style 5.5"); style5.Font.FontStyle = DevExpress.Spreadsheet.SpreadsheetFontStyle.Bold; style5.Font.Color = Color.FromArgb(255, 49, 118, 177); style5.Font.Size = 10; style5.Font.Name = "Segoe UI"; style5.Borders.BottomBorder.Color = Color.FromArgb(255, 167, 200, 229); style5.Borders.BottomBorder.LineStyle = BorderLineStyle.Medium; Style style6 = styles.Add("Style 5.6"); style6.Fill.PatternType = PatternType.Solid; style6.Fill.BackgroundColor = Color.FromArgb(255, 245, 250, 255); style6.Font.Color = Color.FromArgb(255, 49, 118, 177); style6.Font.Size = 18; style6.Font.Name = "Segoe UI"; Style style7 = styles.Add("Style 5.7"); style7.Fill.PatternType = PatternType.Solid; style7.Fill.BackgroundColor = Color.FromArgb(255, 241, 248, 255); style7.Font.Color = Color.FromArgb(255, 0, 0, 0); style7.Font.Size = 9; style7.Font.Name = "Segoe UI Semibold"; Style style8 = styles.Add("Style 5.8"); style8.Fill.PatternType = PatternType.Solid; style8.Fill.BackgroundColor = Color.FromArgb(255, 245, 250, 255); style8.Font.Color = Color.FromArgb(255, 0, 0, 0); style8.Font.Size = 9; style8.Font.Name = "Segoe UI"; Style style9 = styles.Add("Style 5.9"); style9.Fill.PatternType = PatternType.Solid; style9.Fill.BackgroundColor = Color.FromArgb(255, 241, 248, 255); style9.Font.Color = Color.FromArgb(255, 0, 0, 0); style9.Font.Size = 9; style9.Font.Name = "Segoe UI"; Style style10 = styles.Add("Style 5.10"); style10.Fill.PatternType = PatternType.Solid; style10.Fill.BackgroundColor = Color.FromArgb(255, 231, 244, 255); style10.Font.Color = Color.FromArgb(255, 49, 118, 177); style10.Font.Size = 18; style10.Font.Name = "Segoe UI"; Style style11 = styles.Add("Style 5.11"); style11.Fill.PatternType = PatternType.Solid; style11.Fill.BackgroundColor = Color.FromArgb(255, 223, 240, 255); style11.Font.Color = Color.FromArgb(255, 0, 0, 0); style11.Font.Size = 9; style11.Font.Name = "Segoe UI Semibold"; Style style12 = styles.Add("Style 5.12"); style12.Fill.PatternType = PatternType.Solid; style12.Fill.BackgroundColor = Color.FromArgb(255, 231, 244, 255); style12.Font.Color = Color.FromArgb(255, 0, 0, 0); style12.Font.Size = 9; style12.Font.Name = "Segoe UI"; Style style13 = styles.Add("Style 5.13"); style13.Fill.PatternType = PatternType.Solid; style13.Fill.BackgroundColor = Color.FromArgb(255, 223, 240, 255); style13.Font.Color = Color.FromArgb(255, 0, 0, 0); style13.Font.Size = 9; style13.Font.Name = "Segoe UI"; }
private void Load(CompoundFile doc) { Stream stream; try { // see if workbook works stream = doc.OpenStream("Workbook"); } catch (IOException) { // see if book works, if not then leak the exception stream = doc.OpenStream("Book"); } SstRecord sst = null; /* long sstPos = 0; */ // record position dictionary SortedList<long, Biff> records = new SortedList<long, Biff>(); _styles = new StyleCollection(this); _formats = new FormatCollection(this); _fonts = new FontCollection(this); _palette = new Palette(this); _hyperLinks = new HyperLinkCollection(this); while (stream.Length - stream.Position >= GenericBiff.MinimumSize) { // capture the current stream position long pos = stream.Position; // decode the record if possible Biff record = GetCorrectRecord(new GenericBiff(stream), stream, sst); // capture // shared string table if (record is SstRecord) { Debug.Assert(sst == null); sst = (SstRecord)record; /* sstPos = pos; */ } // formatting records else if (record is FormatRecord) { FormatRecord f = (FormatRecord)record; _formats.Add(f.Index, new Format(this, f)); } else if (record is FontRecord) _fonts.Add(new Font(this, (FontRecord)record)); else if (record is PaletteRecord) _palette.Initialize((PaletteRecord)record); else if (record is XfRecord) _styles.Add(new Style(this, (XfRecord)record)); else if (record is HyperLinkRecord) _hyperLinks.Add((HyperLinkRecord)record); Debug.Assert(!records.ContainsKey(pos)); // store the position and corresponding record records[pos] = record; } // generate the worksheets _sheets = new WorksheetCollection(); foreach (Biff record in records.Values) { if (record is BoundSheetRecord) _sheets.Add(new Worksheet(this, (BoundSheetRecord)record, records)); } }
void AddStyles(IWorkbook book) { StyleCollection styles = book.Styles; Style style1 = styles.Add("Style 1"); style1.Fill.PatternType = PatternType.Solid; style1.Fill.BackgroundColor = Color.FromArgb(255, 246, 246, 246); Style style2 = styles.Add("Style 10"); style2.Fill.PatternType = PatternType.Solid; style2.Fill.BackgroundColor = Color.FromArgb(255, 226, 239, 251); Style style3 = styles.Add("Style 11"); style3.Fill.PatternType = PatternType.Solid; style3.Fill.BackgroundColor = Color.FromArgb(255, 232, 232, 232); Style style4 = styles.Add("Style 12"); style4.Fill.PatternType = PatternType.Solid; style4.Fill.BackgroundColor = Color.FromArgb(255, 222, 222, 222); Style style5 = styles.Add("Style 2"); style5.Fill.PatternType = PatternType.Solid; style5.Fill.BackgroundColor = Color.FromArgb(255, 249, 249, 249); Style style6 = styles.Add("Style 3"); style6.Fill.PatternType = PatternType.Solid; style6.Fill.BackgroundColor = Color.FromArgb(255, 255, 243, 196); Style style7 = styles.Add("Style 4"); style7.Fill.PatternType = PatternType.Solid; style7.Fill.BackgroundColor = Color.FromArgb(255, 255, 238, 170); Style style8 = styles.Add("Style 5"); style8.Fill.PatternType = PatternType.Solid; style8.Fill.BackgroundColor = Color.FromArgb(255, 203, 243, 175); Style style9 = styles.Add("Style 6"); style9.Fill.PatternType = PatternType.Solid; style9.Fill.BackgroundColor = Color.FromArgb(255, 219, 247, 199); Style style10 = styles.Add("Style 7"); style10.Fill.PatternType = PatternType.Solid; style10.Fill.BackgroundColor = Color.FromArgb(255, 219, 239, 255); Style style11 = styles.Add("Style 8"); style11.Fill.PatternType = PatternType.Solid; style11.Fill.BackgroundColor = Color.FromArgb(255, 230, 244, 255); Style style12 = styles.Add("Style 9"); style12.Fill.PatternType = PatternType.Solid; style12.Fill.BackgroundColor = Color.FromArgb(255, 230, 244, 255); }