예제 #1
0
        public void createMonthYearSummaryExcel()
        {
            ExcelWorksheet workSheet;
            ExcelWorksheet workSheet2;

            using (Stream AccountMovmentStream = GetAssemblyFile("Transactions.xlsx"))
            {
                workSheet = ExcelServices.GetExcelWorksheet(AccountMovmentStream, "Felles");
            }
            using (Stream SubCategoriesStream = GetAssemblyFile("Categories.xlsx"))
            {
                workSheet2 = ExcelServices.GetExcelWorksheet(SubCategoriesStream);
            }

            var subCategoriesjArray  = JArray.Parse(ExcelServices.GetJsonFromTable(workSheet2));
            var accountMovmentjArray = JArray.Parse(ExcelServices.GetJsonFromTable(workSheet));
            List <SubCategory>     categorisModel   = ModelClassServices.GetSubCategoriesFromJarray(subCategoriesjArray);
            IEnumerable <string>   categoryList     = categorisModel.Select(cat => cat.Category).Distinct();
            List <AccountMovement> accountMovements = ModelClassServices.GetAccountMovmentsFromJarray(accountMovmentjArray);

            var modementsViewModels = ModelClassServices.CreateMovementsViewModels(accountMovements, categorisModel, "Felles");

            var excelPkg = new ExcelPackage();

            try
            {
                //Add excel sheet
                ExcelWorksheet wsSheet = excelPkg.Workbook.Worksheets.Add("MonthResume");

                //Add Table Title
                ExcelServices.AddSheetHeading(wsSheet, "TableName");

                // Add "input" and "output" headet to Excel table
                //ExcelServices.AddTableHeadings(wsSheet, new[] { "col1", "col2", "col3" }, subCategoriesjArray.Count+ accountMovmentjArray.Count);

                //Add transactions to excel Sheet
                ExcelServices.CreateExcelMonthSummaryTableFromMovementsViewModel(modementsViewModels, wsSheet, categoryList, 0, null, true);
                //ExcelServices.CreateExcelTableFromMovementsViewModel(modementsViewModels, wsSheet, "TableName", categoryList);
            }
            catch (Exception e)
            {
                var noko = e.Message;
            }
            var filename = "MonthResumeTests";
            var path     = string.Concat(@"h:\temp\");

            Directory.CreateDirectory(path);
            var filePath = Path.Combine(path, string.Concat(filename, ".xlsx"));

            excelPkg?.SaveAs(new FileInfo(filePath));

            File.Exists(filePath).Should().BeTrue();
        }
예제 #2
0
        public void createMovementsExcel()
        {
            Stream SubCategoriesStream  = GetAssemblyFile("Categories.xlsx");
            Stream AccountMovmentStream = GetAssemblyFile("Transactions.xlsx");

            ExcelWorksheet workSheet  = ExcelServices.GetExcelWorksheet(AccountMovmentStream, "Felles");
            ExcelWorksheet workSheet2 = ExcelServices.GetExcelWorksheet(SubCategoriesStream);

            var subCategoriesjArray                 = JArray.Parse(ExcelServices.GetJsonFromTable(workSheet2));
            var accountMovmentjArray                = JArray.Parse(ExcelServices.GetJsonFromTable(workSheet));
            List <SubCategory>     subCategories    = ModelClassServices.GetSubCategoriesFromJarray(subCategoriesjArray);
            List <AccountMovement> accountMovements = ModelClassServices.GetAccountMovmentsFromJarray(accountMovmentjArray);

            var modementsViewModels = ModelClassServices.CreateMovementsViewModels(accountMovements, subCategories, "Felles");

            var excelPkg = new ExcelPackage();

            try
            {
                ExcelWorksheet wsSheet = excelPkg.Workbook.Worksheets.Add("fellesResum");
                //Add Table Title
                new ExcelServices();
                ExcelServices.AddSheetHeading(wsSheet, "TableName");

                // Add "input" and "output" headet to Excel table
                //ExcelServices.AddTableHeadings(wsSheet, new[] { "col1", "col2", "col3" }, subCategoriesjArray.Count+ accountMovmentjArray.Count);
                //Add DMN Table to excel Sheet
                ExcelServices.CreateExcelTableFromMovementsViewModel(modementsViewModels, wsSheet, "TableName");
            }
            catch (Exception e)
            {
                var noko = e.Message;
            }
            var filename = "MovementsTests";
            var path     = string.Concat(@"h:\temp\");

            Directory.CreateDirectory(path);
            var filePath = Path.Combine(path, string.Concat(filename, ".xlsx"));

            excelPkg?.SaveAs(new FileInfo(filePath));

            File.Exists(filePath).Should().BeTrue();
        }