Пример #1
0
        static void Main(string[] args)
        {
            FluentConfiguration();
            //DbHelper help = new DbHelper(DbHelper.BuildConStr("172.17.99.125,1521", "orcl", "qw", "password", Collector.DataBase.DBHelpMe.DBTypeEnum.Oracle));
            //string a = "2";
            //int data = help.ExecuteSql_All<int>("select count(1) from T_SystemNotice_RECV where GGBH=:GGBH and SEND_STATION_ID=:id", new { GGBH = "2017061910112005", id = a }).FirstOrDefault();
            Person p = new Person
            {
                Name = "张奇",
                Age  = 18,
                Car  = "benci"
            };
            Person p1 = new Person
            {
                Name = "周菲",
                Age  = 20,
                Car  = "naosi"
            };
            List <Person> datas = new List <Person>();

            datas.Add(p);
            datas.Add(p1);
            var excelFile = "e:\\a.xlsx";

            datas.ToExcel(excelFile, "zhoufei");
            Console.ReadKey();
        }
Пример #2
0
        public void GetExcelFromDifferentObjectsInAList_Test()
        {
            var sample = new List <dynamic>
            {
                new { RowNumber = 1, Name = "Mojtaba", LastName = "Nik" },
                new { test = 2, Name1 = "Mojtaba", LastName2 = "Nik" }
            };

            Assert.Throws(Is.TypeOf <TargetException>(), () => sample.ToExcel());
        }
Пример #3
0
        public void TC_ShouldWriteList() {  
            addSheet();
            var target = getRange("A1");

            var list = new List();
            list.AddRange(new object[] { 665, 987897, 909 });
            list.ToExcel(target, "Mytitle", true);

            A.AreEqual("Mytitle", getValue("A1"));
            A.AreEqual(665, getValue("A2"));
            A.AreEqual(909, getValue("A4"));
            A.AreEqual(null, getValue("A5"));
        }
        private static string GenerarExcel <T>(ContextoSe contexto, List <T> elementos)
        {
            VariableDtm ruta              = GestorDeVariables.VariableDeRutaDeExportaciones(contexto);
            var         fichero           = $"{elementos[0].GetType()}.xls";
            var         fecha             = DateTime.Now;
            var         rutaDeExportacion = $@"{ruta.Valor}\{fecha.Year}-{fecha.Month}-{fecha.Day}\{contexto.DatosDeConexion.Login}";

            if (!Directory.Exists(rutaDeExportacion))
            {
                Directory.CreateDirectory(rutaDeExportacion);
            }
            return(elementos.ToExcel(rutaDeExportacion, fichero));
        }
Пример #5
0
        //Require Administrator rights
        public static void TestListToExcel()
        {
            List<Name> names = new List<Name>();

            for (int i = 0; i < 5; i++)
            {
                Name name = new Name();
                name.FirstName = "Mustafa" + i;

                names.Add(name);
            }

            names.ToExcel("c:\\musta.xls");
        }
Пример #6
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");


            var page = await scraper.LoadFromWebAsync(BaseUrl);

            var govtSecurityElement = page.DocumentNode.SelectSingleNode("//*[@id=\"header\"]/div[2]/div/ul/li[8]/div/div[1]/div[4]/ol/li[1]/a");

            var link = govtSecurityElement.Attributes.FirstOrDefault(x => x.Name == "href")?.Value;

            if (link == null)
            {
                Console.WriteLine("No link found");
                return;
            }

            var govtSecurityPage = await scraper.LoadFromWebAsync(BaseUrl + link);

            var listExtract = new List <SecuritiesModel>();

            //extract first page
            listExtract.AddRange(ExtractData(govtSecurityPage));


            //extract subsequent pages
            var pageLinks = govtSecurityPage.DocumentNode.SelectNodes("//*[@id=\"ContentTextinner\"]/a")?
                            .Select(x =>
                                    x.Attributes.FirstOrDefault(x => x.Name == "href")?.Value);


            foreach (var lk in pageLinks)
            {
                var pageData = await scraper.LoadFromWebAsync(BaseUrl + "/rates/" + lk);

                var extractedInfo = ExtractData(pageData);
                listExtract.AddRange(extractedInfo);
            }

            //save list of extracted data to excel
            var bytes       = listExtract.ToExcel();
            var desktopPath = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
            var filePath    = Path.Combine(desktopPath, "sec.xlsx");
            await File.WriteAllBytesAsync(filePath, bytes);

            Console.WriteLine($"Excel file saved at {filePath}");

            Console.Read();
        }
Пример #7
0
        public void TC_ShouldWriteList()
        {
            addSheet();
            var target = getRange("A1");

            var list = new List();

            list.AddRange(new object[] { 665, 987897, 909 });
            list.ToExcel(target, "Mytitle", true);

            A.AreEqual("Mytitle", getValue("A1"));
            A.AreEqual(665, getValue("A2"));
            A.AreEqual(909, getValue("A4"));
            A.AreEqual(null, getValue("A5"));
        }
Пример #8
0
        public void GetExcelFromDynamicObject_Test()
        {
            var sample = new List <dynamic>();

            for (int i = 0; i < 500; i++)
            {
                sample.Add(new { RowNumber = i + 1, Name = "Mojtaba", LastName = "Nik" });
            }

            var result = sample.ToExcel();

            Assert.That(result, Has.Length.GreaterThan(0));

            var excelContent = ExcelHelper.GetDataTableFromExcel(result, true);

            Assert.That(excelContent.Rows.Count, Is.EqualTo(500));
            Assert.That(excelContent.Rows[399]["ROWNUMBER"], Is.EqualTo("400"));
            Assert.That(excelContent.Rows[399]["NAME"], Is.EqualTo("Mojtaba"));
            Assert.That(excelContent.Rows[399]["LastName"], Is.EqualTo("Nik"));
        }
Пример #9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press any key!");
            Console.ReadKey();

            List <Person> people = new List <Person>
            {
                new Person
                {
                    Id       = 1,
                    Name     = "Peter",
                    Birthday = new DateTime(1991, 12, 1)
                },

                new Person
                {
                    Id       = 2,
                    Name     = "Harry",
                    Birthday = new DateTime(1993, 9, 16)
                },

                new Person
                {
                    Id       = 3,
                    Name     = "Amy",
                    Birthday = new DateTime(1994, 6, 16)
                }
            };

            people.ToExcel("c:/people.xlsx");

            var result = people.ToExcelContent();

            foreach (var item in result)
            {
                Console.Write(item);
            }

            Console.WriteLine("Press any key!");
            Console.ReadKey();
        }
Пример #10
0
        public void ExportExcel()
        {
            List <ExportModel> entities = new List <ExportModel>();

            for (int i = 0; i < 1000; i++)
            {
                ExportModel entity = new ExportModel();
                entity.Id         = Guid.NewGuid();
                entity.Name       = "测试00" + i;
                entity.CreateTime = DateTime.Now.AddSeconds(i);
                entity.Sort       = i;
                entity.Amount     = i * 20;
                entity.Sex        = i % 2 == 0 ? "男" : "女";
                entity.SexNum     = i % 2 == 0?1:0;
                entity.Power      = i % 3 * 10;

                entities.Add(entity);
            }

            entities.ToExcel("D:\\测试.xlsx");
        }
Пример #11
0
        public override async Task ProcessInScope(IServiceProvider serviceProvider)
        {
            Console.WriteLine("Processing starts here");

            var transactions         = new List <TransactionItem>();
            var transactionsToExport = new List <TransactionExport>();

            var fileName = string.Format("{0}.xlsx", DateTime.Now.ToString("dd-MM-yyyy"));

            try
            {
                transactions = await GetTransactions();

                if (transactions.Count == 0)
                {
                    var exc = new Exception($"no-transaction-found");
                    SentrySdk.CaptureException(exc);
                }

                for (int i = 0; i < transactions.Count; i++)
                {
                    transactions[i].payables = await GetTransactionsPayables(transactions[i].id.ToString());

                    var order = await GetEcommerceOrder(transactions[i].metadata.order_number);

                    if (order != null && order.order.line_items.Count > 0)
                    {
                        transactions[i].product = order.order.line_items[0].name;
                    }

                    for (int k = 0; k < transactions[i].payables.Count; k++)
                    {
                        var transaction = new TransactionExport
                        {
                            Status                 = transactions[i].status,
                            DateCreated            = transactions[i].formated_date_created,
                            DateUpdated            = transactions[i].formated_date_updated,
                            PaidAmount             = transactions[i].paid_amount,
                            Installments           = transactions[i].installments.Value,
                            PaymentMethod          = transactions[i].payment_method,
                            Id                     = transactions[i].id,
                            State                  = transactions[i].address != null ? transactions[i].address.state : "",
                            Name                   = transactions[i].customer != null ? transactions[i].customer.name : "",
                            Email                  = transactions[i].customer != null ? transactions[i].customer.email : "",
                            DocumentType           = transactions[i].customer != null ? transactions[i].customer.document_type : "",
                            DocumentNumber         = transactions[i].customer != null ? transactions[i].customer.document_number : "",
                            Product                = transactions[i].product,
                            PayableStatus          = transactions[i].customer != null ? transactions[i].payables[k].status : "",
                            PayableType            = transactions[i].customer != null ? transactions[i].payables[k].type : "",
                            PayableAmount          = transactions[i].payables != null ? transactions[i].payables[k].amount : 0,
                            PayableFee             = transactions[i].payables != null ? transactions[i].payables[k].fee : 0,
                            PayableAnticipationFee = transactions[i].payables != null ? transactions[i].payables[k].anticipation_fee : 0,
                            PayableInstallment     = transactions[i].payables != null ? transactions[i].payables[k].installment : 0,
                            PayablePaymentDate     = transactions[i].payables != null ? transactions[i].payables[k].formated_payment_date : "",
                            PayableAccuralDate     = transactions[i].payables != null ? transactions[i].payables[k].formated_accural_date : "",
                            OrderNumber            = transactions[i].metadata != null ? transactions[i].metadata.order_number : 0
                        };

                        transactionsToExport.Add(transaction);
                    }
                }


                var bytes            = transactionsToExport.ToExcel("answers");
                var webRoot          = _env.WebRootPath;
                var reportFolderPath = System.IO.Path.Combine(webRoot, "finance_reports");

                if (!Directory.Exists(reportFolderPath))
                {
                    Directory.CreateDirectory(reportFolderPath);
                }

                var file = System.IO.Path.Combine(webRoot, "finance_reports", fileName);
                File.WriteAllBytes(file, bytes);
            }
            catch (Exception ex)
            {
                string content = JsonConvert.SerializeObject(ex);

                var exc = new Exception($"finance_report_error: {content}");
                SentrySdk.CaptureException(exc);
            }
        }
Пример #12
0
 public static void SaveExcel <TEntity>(List <TEntity> list, string strExcelFullName, Action <FluentConfiguration <TEntity> > action = null)
     where TEntity : class, new()
 {
     SetFluentConfiguration(action);
     list.ToExcel(strExcelFullName);
 }
Пример #13
0
        public void ExcelImport(int beginYear, int type, List <SendData> sends = null, List <ReceiveData> receiveses = null)
        {
            const string filter = "HIDDEN";
            string       title  = beginYear + "年";

            title += "收文列表";
            List <object> excelList = new List <object>();

            if (sends != null)
            {
                #region 发文
                title = title.Replace("收文列表", "发文列表");
                excelList.Add(new
                {
                    ID               = "序列号",
                    Title            = "标题",
                    SerialNumber     = "公文文号",
                    SignDate         = "签发日期",
                    Attituder        = "签发人",
                    Attitude         = "签发意见",
                    Department       = "主送",
                    Staff            = "拟稿人",
                    Dept             = "拟稿部门",
                    DeptStaffName    = "部门审核人",
                    SignAttitudes    = "会签部门意见",
                    CheckStaffName   = "局办公室核稿人",
                    CollateStaffName = "二校",
                    PrintStaffName   = "文印人"
                });
                sends.ForEach(p => excelList.Add(new
                {
                    ID = string.Format("{0:D8}", p.Send.ID),
                    p.Send.Title,
                    p.Send.SerialNumber,
                    SignDate  = p.Send.SignDate.HasValue ? p.Send.SignDate.Value.ToString("yyyy年MM月dd日") : "",
                    Attituder = p.Send.AttituderName,
                    p.Send.Attitude,
                    p.Send.Department,
                    Staff = p.Send.Staff != null ? p.Send.Staff.Name : "",
                    Dept  = p.Send.StaffDept != null ? p.Send.StaffDept.Name : "",
                    p.Send.DeptStaffName,
                    SignAttitudes  = string.Join(enter, p.CoopAttitudes),
                    CheckStaffName = string.Format("{0} {1}", p.Send.CheckStaffName, p.Send.AuditorStaffName),
                    p.Send.CollateStaffName,
                    p.Send.PrintStaffName
                }));
                #endregion
            }
            else if (receiveses != null)
            {
                #region 收文与信访
                if (type != 1)
                {
                    title = title.Replace("收文列表", "信访列表");
                }

                excelList.Add(new
                {
                    ID              = "序列号",
                    Title           = "标题",
                    SerialNumber    = "公文文号",
                    Department      = "来文单位",
                    Type            = "公文类型",
                    GetDate         = "收件日期",
                    Staff           = "收件人",
                    PrimaryAttitude = "拟办意见",
                    PrimaryStaff    = "拟办人",
                    LeaderAttitude  = "局领导批示",
                    DealAttitude    = "处理意见",
                    CoopAttitude    = "协办意见"
                });
                receiveses.ForEach(p => excelList.Add(new
                {
                    ID = string.Format("{0:D8}", p.Receive.ID),
                    p.Receive.Title,
                    p.Receive.SerialNumber,
                    p.Receive.Department,
                    p.Receive.Type,
                    GetDate = p.Receive.GetDate.HasValue ? p.Receive.GetDate.Value.ToString("yyyy年MM月dd日") : "",
                    Staff   = p.Receive.Staff != null ? p.Receive.Staff.Name : "",
                    p.Receive.PrimaryAttitude,
                    PrimaryStaff   = p.Receive.PrimaryStaff != null ? p.Receive.PrimaryStaff.Name : "",
                    LeaderAttitude = string.Join(enter, p.LeaderAttitude),
                    DealAttitude   = string.Join(enter, p.DealAttitudes),
                    CoopAttitude   = string.Join(enter, p.CoopAttitudes),
                }));
                #endregion
            }

            excelList.ToExcel("admin", title, filter, path + title + ".xls");
        }