Exemplo n.º 1
0
        public void TestExport()
        {
            var customers = ExcelImport.Import <CustomerTest>(@"C:\Users\Administrator\Desktop\客户导入.xlsx");
            var bytes     = ExcelExport.Export(customers, @"C:\Users\Administrator\Desktop\客户导出模板.xlsx", "客户导出", 1, new List <int>()
            {
                6
            });

            using (var fs = new FileStream(@"C:\Users\Administrator\Desktop\客户导出.xlsx", FileMode.OpenOrCreate, FileAccess.Write))
            {
                fs.Write(bytes, 0, bytes.Length);
            }
        }
        private void buttonImport_Click(object sender, EventArgs e)
        {
            openFileDialog1.FileName = String.Empty;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                path = openFileDialog1.FileName;
            }

            using (context)
            {
                ExcelImport excelImport = new ExcelImport();
                excelImport.Import(context, path);
            }
        }
Exemplo n.º 3
0
    /// <summary>
    /// Excelを作成
    /// </summary>
    private void ExcelExport()
    {
        IWorkbook book  = new HSSFWorkbook();                  //Excelを作成
        ISheet    sheet = book.CreateSheet("PlayerParameter"); //シートを作成

        CreateHeaderRow(book, sheet);                          //ヘッダー行を作成

        AddToExcel(book, sheet);                               //エクセルに保存

        //エクセルファイルを生成
        using (var fs = new FileStream(file, FileMode.OpenOrCreate, FileAccess.Write))
        {
            book.Write(fs);
        }

        ExcelImport.Import(file, 0);
    }
Exemplo n.º 4
0
        public void TestContractImport()
        {
            var contracts   = ExcelImport.Import <ContractTest>(@"C:\Users\Administrator\Desktop\合同分城市平均天数.xlsx", 4);
            var groups      = contracts.Where(p => p.Cycle.IndexOf("0000-00-00 00:00:00") == -1).GroupBy(p => p.BuildingNo).Select(g => new { No = g.Key, Count = g.Count() });
            var buildingNos = groups.Where(p => p.Count > 1).Select(p => p.No).ToList();

            contracts = contracts.Where(p => buildingNos.Contains(p.BuildingNo)).ToList();

            foreach (var item in contracts)
            {
                var times = item.Cycle.Split('至');
                item.BeginTime = DateTime.Parse(times[0]);
                item.EndTime   = DateTime.Parse(times[1]);
            }

            var treatContracts = new List <ContractTest>();

            foreach (var no in buildingNos)
            {
                var list = contracts.Where(p => p.BuildingNo == no).ToList();
                for (int i = 0; i < list.Count; i++)
                {
                    for (int j = i + 1; j < list.Count; j++)
                    {
                        if (!list[i].TimeRangeOnly(list[j]))
                        {
                            if (!treatContracts.Any(p => p.ID == list[i].ID))
                            {
                                treatContracts.Add(list[i]);
                            }
                            treatContracts.Add(list[j]);
                        }
                    }
                }
            }
            var bytes = ExcelExport.Export(treatContracts, @"C:\Users\Administrator\Desktop\合同分城市到处模板.xlsx", "Sheet1", 0);

            using (var fs = new FileStream(@"C:\Users\Administrator\Desktop\合同分城市导出.xlsx", FileMode.OpenOrCreate, FileAccess.Write))
            {
                fs.Write(bytes, 0, bytes.Length);
            }
        }
Exemplo n.º 5
0
        static void Main(string[] args)
        {
            string excelFile     = null;
            string dataFile      = null;
            Side   side          = Side.All;
            string headModel     = null;
            string dataFormatStr = null;
            string dataType      = "List<Dictionary<string, object>>";

            optionSet = new OptionSet()
            {
                { "excelFile=", "Excel folder path", s => excelFile = s },
                { "dataFile=", "The code out folder", s => dataFile = s },
                { "headModel=", "The last export info.", s => headModel = s },
                { "side=", "The last export info.", s => side = (Side)Enum.Parse(typeof(Side), s) },
                { "dataFormat=", "Data format", s => dataFormatStr = s },
                { "dataType=", "Data Type", s => dataType = s },
            };

            optionSet.Parse(args);

            if (string.IsNullOrEmpty(excelFile))
            {
                Console.WriteLine("Excel file is null");
                return;
            }

            if (string.IsNullOrEmpty(dataFile))
            {
                Console.WriteLine("Code out path is null");
                return;
            }

            if (!Path.IsPathRooted(excelFile))
            {
                excelFile = Path.Combine(Directory.GetCurrentDirectory(), excelFile);
            }

            if (!Path.IsPathRooted(dataFile))
            {
                dataFile = Path.Combine(Directory.GetCurrentDirectory(), dataFile);
            }

            ImportSetting setting = new ImportSetting();

            if (!string.IsNullOrEmpty(headModel))
            {
                switch (headModel)
                {
                case "Normal":
                    setting.headModel = HeadModel.CreateNormalModel();
                    break;

                case "Simple":
                    setting.headModel = HeadModel.CreateSimpleModel();
                    break;

                //use default have side
                case "All":
                default:
                    break;
                }
            }

            ExcelImport import = new ExcelImport(setting);

            import.side = side;


            DataFormat dataFormat = (DataFormat)Enum.Parse(typeof(DataFormat), dataFormatStr);

            import.dataFormat = dataFormat;
            import.dataType   = TypeInfo.Parse(dataType).ToSystemType();

            import.Import(dataFile, excelFile);
        }
Exemplo n.º 6
0
 public void TestImport()
 {
     var customers = ExcelImport.Import <CustomerTest>(@"C:\Users\Administrator\Desktop\客户导入.xlsx");
 }