Пример #1
0
        public void CustomersWrite()
        {
            ExcelStorage provider = new ExcelStorage(typeof(CustomersVerticalBar));

            provider.StartRow    = 3;
            provider.StartColumn = 2;
            provider.FileName    = @"..\data\Excel\Customers.xls";

            object[] res = provider.ExtractRecords();

            long start = DateTime.Now.Ticks;

            provider.FileName = @"salida.xls";

            provider.StartRow    = 10;
            provider.StartColumn = 5;
            provider.InsertRecords(res);

            TimeSpan ts = new TimeSpan(DateTime.Now.Ticks - start);

            Console.WriteLine(ts.TotalSeconds);

            if (File.Exists(@"salida.xls"))
            {
                File.Delete(@"salida.xls");
            }
        }
Пример #2
0
        public void OrdersWrite()
        {
            FileHelperEngine engine = new FileHelperEngine(typeof(OrdersExcelType));

            OrdersExcelType[] resFile = (OrdersExcelType[])Common.ReadTest(engine, @"Good\OrdersWithOutDates.txt");

            ExcelStorage provider = new ExcelStorage(typeof(OrdersExcelType));

            provider.StartRow     = 1;
            provider.StartColumn  = 1;
            provider.FileName     = @"c:\tempex.xls";
            provider.OverrideFile = true;

            provider.InsertRecords(resFile);

            OrdersExcelType[] res = (OrdersExcelType[])provider.ExtractRecords();

            if (File.Exists(@"c:\tempex.xls"))
            {
                File.Delete(@"c:\tempex.xls");
            }

            Assert.AreEqual(resFile.Length, res.Length);

            for (int i = 0; i < res.Length; i++)
            {
                Assert.AreEqual(resFile[i].CustomerID, res[i].CustomerID);
                Assert.AreEqual(resFile[i].EmployeeID, res[i].EmployeeID);
                Assert.AreEqual(resFile[i].Freight, res[i].Freight);
                Assert.AreEqual(resFile[i].OrderID, res[i].OrderID);
                Assert.AreEqual(resFile[i].ShipVia, res[i].ShipVia);
            }
        }
    static void Main(string[] args)
    {
        // create some data to export
        MyClass[] rows = new MyClass[2] {
            new MyClass()
            {
                Field1 = "Apples", Field2 = 23, Field3 = "Yes"
            },
            new MyClass()
            {
                Field1 = "Oranges", Field2 = 17, Field3 = "No"
            }
        };
        ExcelStorage provider = new ExcelStorage(typeof(MyClass));

        // Set the destination Excel spreadsheet
        provider.FileName = @"MyClass.xlsx";
        // Template.xlsx contains just the column headers on row 1
        provider.TemplateFile = @"Template.xlsx";
        // StartRow is after the header row
        provider.StartRow = 2;

        provider.OverrideFile = true;
        provider.InsertRecords(rows);
    }
Пример #4
0
        public void NoTemplate()
        {
            ExcelStorage provider = new ExcelStorage(typeof(CustomersVerticalBar), 1, 1);

            provider.TemplateFile = @"..\the template is not there.xls";
            provider.FileName     = @"output.xls";

            provider.InsertRecords(new object[] { new CustomersVerticalBar() });
        }