protected void TestFunction(Expression <Func <ColumnCellDictionary, object> > exp, string expected)
        {
            var convert = new ExpressionConvert(new[] { "One", "Two", "Three", "Four", "Five", "Six" }, 3);
            var ret     = convert.Convert(exp);

            Assert.AreEqual(expected, ret);
        }
        public void Day()
        {
            Expression <Func <Dictionary <string, object>, object> > exp = c => DateTime.Now.Day;
            var convert = new ExpressionConvert(new string[] { }, 3);
            var ret     = convert.Convert(exp);

            Assert.AreEqual("DAY(NOW())", ret);
        }
        public void EDateWithColumn()
        {
            Expression <Func <Dictionary <string, ColumnValue>, object> > exp = c => ((DateTime)c["Date"]).AddMonths((int)c["Month"]);
            var convert = new ExpressionConvert(new string[] { "Date", "Month" }, 3);
            var ret     = convert.Convert(exp);

            Assert.AreEqual("EDATE(A4,B4)", ret);
        }
        public void EDate()
        {
            Expression <Func <Dictionary <string, object>, object> > exp = c => DateTime.Now.AddMonths(3);
            var convert = new ExpressionConvert(new string[] { }, 3);
            var ret     = convert.Convert(exp);

            Assert.AreEqual("EDATE(NOW(),3)", ret);
        }
Exemple #5
0
        private static void SetCellValue(ExcelType excelType, ExcelColumn column, ICell cell, string val,
                                         string[] columnTitles)
        {
            if (column.Type == typeof(Uri))
            {
                cell.Hyperlink = Switch <IHyperlink>(
                    excelType,
                    () => new HSSFHyperlink(HyperlinkType.Url)
                {
                    Address = val
                },
                    () => new XSSFHyperlink(HyperlinkType.Url)
                {
                    Address = val
                }
                    );
            }
            else if (column.Type == typeof(Expression))
            {
                var convert = new ExpressionConvert(columnTitles, cell.RowIndex);
                cell.SetCellFormula(convert.Convert(column.Formula));
                if (column.ResultType != null)
                {
                    if (column.ResultType == typeof(DateTime))
                    {
                        cell.CellStyle            = cell.Sheet.Workbook.CreateCellStyle();
                        cell.CellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("m/d/yy");
                    }
                }
                return;
            }
            else if (column.Type == typeof(string))
            {
                cell.SetCellType(CellType.String);
                cell.CellStyle            = cell.Sheet.Workbook.CreateCellStyle();
                cell.CellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("text");
            }

            if (column.Font != null)
            {
                IFont font = cell.Sheet.Workbook.CreateFont();
                font.FontName           = column.Font.FontName;
                font.FontHeightInPoints = column.Font.FontHeightInPoints;
                font.Color = column.Font.Color;
                if (column.Font.IsBold)
                {
                    font.Boldweight = (short)NPOI.SS.UserModel.FontBoldWeight.Bold;
                }
                cell.CellStyle.SetFont(font);
            }

            //cell.Hyperlink=new HSSFHyperlink

            cell.SetCellValue(val);
        }
Exemple #6
0
        private static void SetCellValue(ExcelType excelType, ExcelColumn column, ICell cell, string val,
                                         string[] columnTitles)
        {
            if (column.Type == typeof(Uri))
            {
                cell.Hyperlink = Switch <IHyperlink>(
                    excelType,
                    () => new HSSFHyperlink(HyperlinkType.Url)
                {
                    Address = val
                },
                    () => new XSSFHyperlink(HyperlinkType.Url)
                {
                    Address = val
                }
                    );
            }
            else if (column.Type == typeof(Expression))
            {
                var convert = new ExpressionConvert(columnTitles, cell.RowIndex);
                cell.SetCellFormula(convert.Convert(column.Formula));
                if (column.ResultType != null)
                {
                    if (column.ResultType == typeof(DateTime))
                    {
                        cell.CellStyle            = cell.Sheet.Workbook.CreateCellStyle();
                        cell.CellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("m/d/yy");
                    }
                }
                return;
            }
            else if (column.Type == typeof(string))
            {
                cell.SetCellType(CellType.String);
                cell.CellStyle            = cell.Sheet.Workbook.CreateCellStyle();
                cell.CellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("text");
            }

            //cell.Hyperlink=new HSSFHyperlink

            cell.SetCellValue(val);
        }