private static void AddExCssStyle(this IXLWorksheet worksheet, int rowId, int colId, HtmlNode cell)
 {
     var css = cell.GetAttributeValue("style", "");
     var parser = new StylesheetParser();
     var stylesheet = parser.Parse(css);
     SimpleSelector color =
         stylesheet.RuleSets.SelectMany(x => x.Selectors)
                   .SelectMany(x => x.SimpleSelectors)
                   .FirstOrDefault(x => x.ElementName == "color");
     string thing = (color == null) ? "" : color.Child.Pseudo;
     worksheet.Cell(rowId, colId).Style.Font.FontColor = XLColor.FromName(thing);
 }
        public static int AddTd(this IXLWorksheet worksheet, int rowId, int colId, HtmlNode cell)
        {
            // add text
            worksheet.Cell(rowId, colId).Value = cell.InnerText;

            // add data type
            worksheet.Cell(rowId, colId).DataType = GetDataType(cell.InnerText);

            // colspan merge
            int colspan = cell.GetAttributeValue("colspan", 1);
            if (colspan > 1)
            {
                var mergeUs = worksheet.Range(rowId, colId, rowId, colId + (colspan - 1));
                mergeUs.Merge();
            }

            // Try style with CssStyleCollection
            var stylernater = CssStyleTools.Create();
            stylernater.Value = cell.GetAttributeValue("style", "");
            string color = stylernater["color"];
            if (!string.IsNullOrWhiteSpace(color))
            {
                // rgb(
                //var snot = "rgb(255, 0, 0)";
                var snot = color;
                var poo = snot.Substring(4, snot.Length-4);
                var foo = poo.Substring(0, poo.Length - 1);
                string[] noo = foo.Split(',');
                var goo = noo.Select(x => x.Trim());
                List<int> hoo = goo.Select(x => int.Parse(x)).ToList();
                worksheet.Cell(rowId, colId).Style.Font.FontColor = XLColor.FromArgb(hoo[0], hoo[1], hoo[2]); //.FromName(color);
            }
            // YAAHGHGhghghgh. This is just as bad as ExCss!

            // add style?
            //worksheet.AddExCssStyle(rowId, colId, cell);

            return colspan;
        }
 public static HtmlTag Cell(this TableRowTag row, decimal number)
 {
     return row.Cell(number.ToString()).Style("text-align", "right");
 }
 public static TableRowTag AddCell(this TableRowTag row, string text)
 {
     row.Cell().Text(text);
     return row;
 }
Example #5
0
 public static void Cell(this ITableWriter writer, IFieldValue value)
 {
   writer.Cell(value.Name, value.Value);
 }