Ejemplo n.º 1
0
        /// <summary>
        /// Input array:    a1      b1          c1                  Output: []      []                  c1
        ///                 1       2           3                           []      []                  3
        ///                 true    1-1-2012    true    true                TRUE    January 1, 2012     a1  b1
        ///                                                                 []      []                  1   2
        /// </summary>
        static void TestExcelCut()
        {
            ExcelDocument document = new ExcelDocument();

            string[][] array = { new string[] { "a1", "b1", "c1" }, new string[] { "1", "2", "3" }, new string[] { "true", "1-1-2012", "true", "true" } };
            document.AddArray(array, "Sheet1");
            List <List <string> > vs = document.GetRange("Sheet1", "A1", "D4");

            foreach (List <string> strs in vs)
            {
                foreach (string s in strs)
                {
                    Console.Write($"{s}, ");
                }
                Console.WriteLine();
            }

            Console.WriteLine();
            List <List <string> > a = document.CutRange("Sheet1", "A1", "B2");

            document.PasteRange("Sheet1", "C3", a);
            vs = document.GetRange("Sheet1", "A1", "D4");
            foreach (List <string> strs in vs)
            {
                foreach (string s in strs)
                {
                    Console.Write($"{s}, ");
                }
                Console.WriteLine();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Opens the given sheet of the given workbook from B1 to C10
        /// </summary>
        static void TestExcelOpen(string path, string sheetName)
        {
            ExcelDocument         document = ExcelDocument.Open(path);
            List <List <string> > vs       = document.GetRange(sheetName, "B1", "C10");

            foreach (List <string> strs in vs)
            {
                foreach (string s in strs)
                {
                    Console.Write($"{s}, ");
                }
                Console.WriteLine();
            }
        }
Ejemplo n.º 3
0
        static void TestExcelRead()
        {
            /// <summary>
            /// Input array:    a1      b1          c1
            ///                 1       2           3
            ///                 true    1-1-2012    true    true
            /// </summary>
            ExcelDocument document = new ExcelDocument();

            string[][] array = { new string[] { "a1", "b1", "c1" }, new string[] { "1", "2", "3" }, new string[] { "true", "1-1-2012", "true", "true" } };
            document.AddArray(array, "Sheet1");
            List <List <string> > vs = document.GetRange("Sheet1", "B1", "C3");

            foreach (List <string> strs in vs)
            {
                foreach (string s in strs)
                {
                    Console.Write($"{s}, ");
                }
                Console.WriteLine();
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Input array:    a1      b1          c1                  Output: A3
        ///                 1       2           3                           B1
        ///                 true    1-1-2012    true    true                C1
        ///                                                                 A3
        ///</summary>
        static void TestExcelScanToEnd()
        {
            ExcelDocument document = new ExcelDocument();

            string[][] array = { new string[] { "a1", "b1", "c1" }, new string[] { "1", "2", "3" }, new string[] { "true", "1-1-2012", "true", "true" } };
            document.AddArray(array, "Sheet1");
            List <List <string> > vs = document.GetRange("Sheet1", "A1", "D4");

            foreach (List <string> strs in vs)
            {
                foreach (string s in strs)
                {
                    Console.Write($"{s}, ");
                }
                Console.WriteLine();
            }

            Console.WriteLine(document.ScanToEnd("Sheet1", ExcelDocument.Direction.down));       //A3
            Console.WriteLine(document.ScanToEnd("Sheet1", ExcelDocument.Direction.up, "B3"));   //B1
            Console.WriteLine(document.ScanToEnd("Sheet1", ExcelDocument.Direction.right));      //C1
            Console.WriteLine(document.ScanToEnd("Sheet1", ExcelDocument.Direction.left, "D3")); //A3
        }