Esempio n. 1
0
        static void Main(string[] args)
        {
            if (File.Exists("test1.xls"))
            {
                File.Delete("test1.xls");
            }

            // Excel 导出格式.
            ExcelDataExportFormater <TestData> format1 = new TestDataExcelExportFormater1();

            // Excel 异步导出处理
            AsynchronousExcelExportProcess <ExcelDataExportFormater <TestData>, TestData> exper =
                new AsynchronousExcelExportProcess <ExcelDataExportFormater <TestData>, TestData>();


            // 设置 格式化.
            exper.ExcelDataExportFormater = format1;

            // 设置输出文件.
            exper.OutputFileName = "test1.xls";


            // 开始异步处理.
            exper.StartAsynchronousProcess();



            // 模拟 分页数据读取.
            for (int i = 0; i < 10; i++)
            {
                // 队列加入数据.
                List <TestData> newList = GetTestData(i);
                exper.AddReportData(newList);
            }

            // 结束异步处理.
            exper.FinishAsynchronousProcess();



            Console.WriteLine("异步生成 Excel 处理结束,按回车键开始 异步 Excel 读取!");

            Console.ReadLine();



            ExcelDataImportFormater <TestData> iformat1 = new TestDataExcelImportFormater1();

            AsynchronousExcelImportProcess <ExcelDataImportFormater <TestData>, TestData> impor =
                new AsynchronousExcelImportProcess <ExcelDataImportFormater <TestData>, TestData>();


            // 设置 格式化.
            impor.ExcelDataImportFormater = iformat1;

            // 设置输出文件.
            impor.InputFileName = "test1.xls";

            // 设置窗口大小.
            impor.WindowsSize = 3;


            // 设置 触发事件.
            impor.DataReaderStep += new AsynchronousExcelImportProcess <ExcelDataImportFormater <TestData>, TestData> .DataReaderStepHandler(DataReaderStepHandler);

            impor.DataReaderFinish += new AsynchronousExcelImportProcess <ExcelDataImportFormater <TestData>, TestData> .DataReaderFinishHandler(DataReaderFinishHandler);


            // 开始异步处理.
            impor.StartAsynchronousProcess();


            while (true)
            {
                if (isFinish)
                {
                    break;
                }
                Thread.Sleep(500);
            }


            Console.ReadLine();
        }
Esempio n. 2
0
        static void Main(string[] args)
        {

            if (File.Exists("test1.xls"))
            {
                File.Delete("test1.xls");
            }

            // Excel 导出格式.
            ExcelDataExportFormater<TestData> format1 = new TestDataExcelExportFormater1();

            // Excel 异步导出处理
            AsynchronousExcelExportProcess<ExcelDataExportFormater<TestData>, TestData> exper =
                new AsynchronousExcelExportProcess<ExcelDataExportFormater<TestData>, TestData>();


            // 设置 格式化.
            exper.ExcelDataExportFormater = format1;

            // 设置输出文件.
            exper.OutputFileName = "test1.xls";


            // 开始异步处理.
            exper.StartAsynchronousProcess();



            // 模拟 分页数据读取.
            for (int i = 0; i < 10; i++)
            {
                // 队列加入数据.
                List<TestData> newList = GetTestData(i);
                exper.AddReportData(newList);
 
            }

            // 结束异步处理.
            exper.FinishAsynchronousProcess();



            Console.WriteLine("异步生成 Excel 处理结束,按回车键开始 异步 Excel 读取!");

            Console.ReadLine();





            ExcelDataImportFormater<TestData> iformat1 = new TestDataExcelImportFormater1();

            AsynchronousExcelImportProcess<ExcelDataImportFormater<TestData>, TestData> impor =
                new AsynchronousExcelImportProcess<ExcelDataImportFormater<TestData>, TestData>();


            // 设置 格式化.
            impor.ExcelDataImportFormater = iformat1;

            // 设置输出文件.
            impor.InputFileName = "test1.xls";

            // 设置窗口大小.
            impor.WindowsSize = 3;


            // 设置 触发事件.
            impor.DataReaderStep += new AsynchronousExcelImportProcess<ExcelDataImportFormater<TestData>, TestData>.DataReaderStepHandler(DataReaderStepHandler);
            impor.DataReaderFinish += new AsynchronousExcelImportProcess<ExcelDataImportFormater<TestData>, TestData>.DataReaderFinishHandler(DataReaderFinishHandler);


            // 开始异步处理.
            impor.StartAsynchronousProcess();


            while (true)
            {
                if (isFinish)
                {
                    break;
                }
                Thread.Sleep(500);
            }


            Console.ReadLine();
        }
Esempio n. 3
0
        static void Main(string[] args)
        {


            if (File.Exists("test1.xls"))
            {
                File.Delete("test1.xls");
            }

            if (File.Exists("test2.xls"))
            {
                File.Delete("test2.xls");
            }


            // 用于测试的数据列表.
            List<TestData> testDataList = new List<TestData>();

            testDataList.Add(new TestData { UserName = "******", City = "上海", Zip = "200000" });
            testDataList.Add(new TestData { UserName = "******", City = "桂林" });
            testDataList.Add(new TestData { UserName = "******" });



            ExcelDataExportFormater<TestData> format1 = new TestDataExcelExportFormater1();

            ExcelDataExportFormater<TestData> format2 = new TestDataExcelExportFormater2();



            // 数据导出到 Excel。
            ExcelExportProcess<ExcelDataExportFormater<TestData>, TestData> exper =
                new ExcelExportProcess<ExcelDataExportFormater<TestData>, TestData>();


            // 设置 格式化.
            exper.ExcelDataExportFormater = format1;
            // 导出.
            exper.CreateExcelReport(testDataList, "test1.xls");



            Debug.WriteLine("输出到 test1.xls 完毕!");
            


            // 设置 格式化.
            exper.ExcelDataExportFormater = format2;
            // 导出.
            exper.CreateExcelReport(testDataList, "test2.xls");


            Debug.WriteLine("输出到 test2.xls 完毕!");






            ExcelDataImportFormater<TestData> iformat1 = new TestDataExcelImportFormater1();
            ExcelDataImportFormater<TestData> iformat2 = new TestDataExcelImportFormater2();

            ExcelImportProcess<ExcelDataImportFormater<TestData>, TestData> impr = 
                new ExcelImportProcess<ExcelDataImportFormater<TestData>,TestData>();


            // 从 test1.xls 读取.
            impr.ExcelDataImportFormater = iformat1;
            List<TestData> fileList1 = impr.ReadDataFromExcelReport("test1.xls");

            Console.WriteLine("从 test1.xls 读取数据!");

            foreach (TestData data in fileList1)
            {
                Console.WriteLine("UserName = {0}, City = {1}, Zip ={2}",
                    data.UserName,
                    data.City,
                    data.Zip);
            }



            // 从 test2.xls 读取.
            impr.ExcelDataImportFormater = iformat2;
            List<TestData> fileList2 = impr.ReadDataFromExcelReport("test2.xls");

            Console.WriteLine("从 test2.xls 读取数据!");

            foreach (TestData data in fileList2)
            {
                Console.WriteLine("UserName = {0}, City = {1}, Zip ={2}",
                    data.UserName,
                    data.City,
                    data.Zip);
            }



            Console.ReadLine();
        }
Esempio n. 4
0
        static void Main(string[] args)
        {
            if (File.Exists("test1.xls"))
            {
                File.Delete("test1.xls");
            }

            if (File.Exists("test2.xls"))
            {
                File.Delete("test2.xls");
            }


            // 用于测试的数据列表.
            List <TestData> testDataList = new List <TestData>();

            testDataList.Add(new TestData {
                UserName = "******", City = "上海", Zip = "200000"
            });
            testDataList.Add(new TestData {
                UserName = "******", City = "桂林"
            });
            testDataList.Add(new TestData {
                UserName = "******"
            });



            ExcelDataExportFormater <TestData> format1 = new TestDataExcelExportFormater1();

            ExcelDataExportFormater <TestData> format2 = new TestDataExcelExportFormater2();



            // 数据导出到 Excel。
            ExcelExportProcess <ExcelDataExportFormater <TestData>, TestData> exper =
                new ExcelExportProcess <ExcelDataExportFormater <TestData>, TestData>();


            // 设置 格式化.
            exper.ExcelDataExportFormater = format1;
            // 导出.
            exper.CreateExcelReport(testDataList, "test1.xls");



            Debug.WriteLine("输出到 test1.xls 完毕!");



            // 设置 格式化.
            exper.ExcelDataExportFormater = format2;
            // 导出.
            exper.CreateExcelReport(testDataList, "test2.xls");


            Debug.WriteLine("输出到 test2.xls 完毕!");



            ExcelDataImportFormater <TestData> iformat1 = new TestDataExcelImportFormater1();
            ExcelDataImportFormater <TestData> iformat2 = new TestDataExcelImportFormater2();

            ExcelImportProcess <ExcelDataImportFormater <TestData>, TestData> impr =
                new ExcelImportProcess <ExcelDataImportFormater <TestData>, TestData>();


            // 从 test1.xls 读取.
            impr.ExcelDataImportFormater = iformat1;
            List <TestData> fileList1 = impr.ReadDataFromExcelReport("test1.xls");

            Console.WriteLine("从 test1.xls 读取数据!");

            foreach (TestData data in fileList1)
            {
                Console.WriteLine("UserName = {0}, City = {1}, Zip ={2}",
                                  data.UserName,
                                  data.City,
                                  data.Zip);
            }



            // 从 test2.xls 读取.
            impr.ExcelDataImportFormater = iformat2;
            List <TestData> fileList2 = impr.ReadDataFromExcelReport("test2.xls");

            Console.WriteLine("从 test2.xls 读取数据!");

            foreach (TestData data in fileList2)
            {
                Console.WriteLine("UserName = {0}, City = {1}, Zip ={2}",
                                  data.UserName,
                                  data.City,
                                  data.Zip);
            }



            Console.ReadLine();
        }