Esempio n. 1
0
            public void TestConstructorItemWithPerson()
            {
                var t = new Person {
                    Name = "andrei", WebSite = "http://msprogrammer.serviciipeweb.ro/"
                };
                var export = new ExportExcel2007 <Person>();

                Assert.AreEqual(@"<row>
   <c t='inlineStr'>
                <is>
                    <t>@System.Security.SecurityElement.Escape((((object)Model.Name) ?? """").ToString())
                    </t>
                </is>
    </c>
   <c t='inlineStr'>
                <is>
                    <t>@System.Security.SecurityElement.Escape((((object)Model.WebSite) ?? """").ToString())
                    </t>
                </is>
    </c>
   <c t='inlineStr'>
                <is>
                    <t>@System.Security.SecurityElement.Escape((((object)Model.CV) ?? """").ToString())
                    </t>
                </is>
    </c>
</row>".Replace("\r", "").Replace("\n", ""), export.ExportItem.Replace("\r", "").Replace("\n", ""));
            }
Esempio n. 2
0
        static void Advanced_ModifyTemplates()
        {
            var p = new Person {
                Name = "andrei", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc"
            };
            var p1 = new Person {
                Name = "you", WebSite = "http://yourwebsite.com/"
            };
            var list = new List <Person>()
            {
                p, p1
            };

            //advanced - modifying templates - in this case , added Number
            var export = new ExportExcel2007 <Person>();

            //File.WriteAllText("Excel2007Header.txt",export.ExportHeader);
            //File.WriteAllText("Excel2007Item.txt", export.ExportItem);
            //File.WriteAllText("Excel2007Collection.txt", export.ExportCollection);
            export.ExportHeader     = File.ReadAllText("Excel2007Header.txt");
            export.ExportItem       = File.ReadAllText("Excel2007Item.txt");
            export.ExportCollection = File.ReadAllText("Excel2007Collection.txt");
            var data = export.ExportResult(list);

            if (!writeAndStartFile("WithId.xlsx", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete WithId.xlsx");
            }
        }
Esempio n. 3
0
            public void TestCorrectJson()
            {
                string data = @"[
    { 'Name':'Andrei Ignat', 
        'WebSite':'http://msprogrammer.serviciipeweb.ro/',
        'CV':'http://serviciipeweb.ro/iafblog/content/binary/cv.doc'        
    },
{ 'Name':'Your Name', 
        'WebSite':'http://your website',
        'CV':'cv.doc'        
    }
]";


                var p = new Person {
                    Name = "Andrei Ignat", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc"
                };
                var byte1 = new ExportExcel2007 <Person>().ExportResult(new List <Person>()
                {
                    p, p
                });

                var byte2 = ExportFactory.ExportDataJson(data, ExportToFormat.Excel2007);

                //File.WriteAllBytes("byte1.xlsx",byte1);
                //File.WriteAllBytes("byte2.xlsx", byte2);
                Assert.IsTrue(Math.Abs(byte1.Length - byte2.Length) < 100);
            }
Esempio n. 4
0
            public void TestCorrectDictionary()
            {
                var data = new Dictionary <string, object> [2];

                data[0] = new Dictionary <string, object>();

                data[0]["Name"]    = "yAndrei Ignat";
                data[0]["WebSite"] = "http://msprogrammer.serviciipeweb.ro/";
                data[0]["CV"]      = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc";

                data[1] = new Dictionary <string, object>();

                data[1]["Name"]    = "xAndrei Ignat";
                data[1]["WebSite"] = "http://msprogrammer.serviciipeweb.ro/";
                data[1]["CV"]      = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc";


                var p = new Person {
                    Name = "Andrei Ignat", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc"
                };

                var byte1 = new ExportExcel2007 <Person>().ExportResult(new List <Person>()
                {
                    p, p
                });

                var byte2 = ExportFactory.ExportDataDictionary(data, ExportToFormat.Excel2007);

                File.WriteAllBytes("a.xlsx", byte2);
                Process.Start("a.xlsx");
                Assert.IsTrue(Math.Abs(byte1.Length - byte2.Length) < 100);
            }
            public void TestConstructorItemWithPerson()
            {
                var t = new Person {Name = "andrei", WebSite = "http://msprogrammer.serviciipeweb.ro/"};
                var export = new ExportExcel2007<Person>();
                Assert.AreEqual(@"<row>
   <c t='inlineStr'>
                <is>
                    <t>@Model.Name
                    </t>
                </is>
    </c>
   <c t='inlineStr'>
                <is>
                    <t>@Model.WebSite
                    </t>
                </is>
    </c>
   <c t='inlineStr'>
                <is>
                    <t>@Model.CV
                    </t>
                </is>
    </c>
</row>", export.ExportItem);
            }
            public void TestConstructorItemWithPerson()
            {
                var t = new Person {
                    Name = "andrei", WebSite = "http://msprogrammer.serviciipeweb.ro/"
                };
                var export = new ExportExcel2007 <Person>();

                Assert.AreEqual(@"<row>
   <c t='inlineStr'>
                <is>
                    <t>@Model.Name
                    </t>
                </is>
    </c>
   <c t='inlineStr'>
                <is>
                    <t>@Model.WebSite
                    </t>
                </is>
    </c>
   <c t='inlineStr'>
                <is>
                    <t>@Model.CV
                    </t>
                </is>
    </c>
</row>", export.ExportItem);
            }
Esempio n. 7
0
            public void TestCorrectJson()
            {
                string data = @"[
    { 'Name':'Andrei Ignat', 
        'WebSite':'http://msprogrammer.serviciipeweb.ro/',
        'CV':'http://serviciipeweb.ro/iafblog/content/binary/cv.doc'        
    },
{ 'Name':'Your Name', 
        'WebSite':'http://your website',
        'CV':'cv.doc'        
    }
]";
                

                var p = new Person { Name = "Andrei Ignat", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc" };
                var byte1 = new ExportExcel2007<Person>().ExportResult(new List<Person>(){p,p});

                var byte2 = ExportFactory.ExportDataJson(data, ExportToFormat.Excel2007);

                //File.WriteAllBytes("byte1.xlsx",byte1);
                //File.WriteAllBytes("byte2.xlsx", byte2);
                Assert.IsTrue(Math.Abs(byte1.Length-byte2.Length)<100);


            }
Esempio n. 8
0
            //[TestMethod]
            public void TestExcel2007Dataset()
            {
                var ds       = new DataSet();
                var table    = new DataTable("programmers");
                var idColumn = table.Columns.Add("ID", typeof(int));

                table.Columns.Add("Name", typeof(string));
                table.Columns.Add("WebSite", typeof(string));

                table.PrimaryKey = new DataColumn[] { idColumn };

                table.Rows.Add(new object[] { 1, "Andrei Ignat", "http://msprogrammer.serviciipeweb.ro" });
                table.Rows.Add(new object[] { 2, "Scott Hanselman", "http://www.hanselman.com/blog/" });

                ds.Tables.Add(table);

                var dta = new DataTable("andrei");

                dta.Columns.Add(new DataColumn("ID", typeof(int)));
                dta.Columns.Add(new DataColumn("Data", typeof(string)));
                dta.Rows.Add(1, "test 1 ");
                dta.Rows.Add(2, "test 2 ");
                dta.Rows.Add(3, "test 3 ");
                ds.Tables.Add(dta);



                var export = new ExportExcel2007 <Person>();
                var data   = ExportFactory.ExportDataSet(ds, ExportToFormat.Excel2007);

                File.WriteAllBytes("multipleDataSet.xlsx", data);
                Process.Start("multipleDataSet.xlsx");
            }
 public void TestWithPersonHeader()
 {
     var p = new Person {Name = "andrei", WebSite = "http://msprogrammer.serviciipeweb.ro/"};
     var export = new ExportExcel2007<Person>();
     var data = export.ExportResultStringPart(new List<Person>() {p});
     var str = data;
     Assert.IsTrue(str.Contains(export.ExportHeader),"must contain the header");
 }
            public void TestWithPersonData()
            {
                var p = new Person { Name = "Andrei Ignat", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc" };
                var export = new ExportExcel2007<Person>();
                var data = export.ExportResultStringPart(new List<Person>() { p});
                var str = data;
                Assert.IsTrue(str.Contains("http://serviciipeweb.ro/iafblog/content/binary/cv.doc"),"must contain the cv");

            }
            //[TestMethod]
            public void TestExcel2007()
            {
                var p = new Person { Name = "Andrei Ignat", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc" };
                var export = new ExportExcel2007<Person>();
                var data = export.ExportResult(new List<Person>() { p });
                //var str = Encoding.Unicode.GetString(data);
                File.WriteAllBytes("a.xlsx",data);
                Process.Start("a.xlsx");

            }
Esempio n. 12
0
        public FileContentResult DownloadAsExcel()
        {
            var listWithPerson = db.Suppliers.Include(s => s.Plan).Include(s => s.User).ToList();
            var export         = new ExportExcel2007 <Supplier>();
            var data           = export.ExportResult(listWithPerson);
            var _path          = Server.MapPath("~/DownloadedFiles/a.xlsx");

            System.IO.File.WriteAllBytes(_path, data);
            Process.Start(_path);

            return(null);
        }
Esempio n. 13
0
            public void TestWithPersonHeader()
            {
                var p = new Person {
                    Name = "andrei", WebSite = "http://msprogrammer.serviciipeweb.ro/"
                };
                var export = new ExportExcel2007 <Person>();
                var data   = export.ExportResultStringPart(new List <Person>()
                {
                    p
                });
                var str = data;

                Assert.IsTrue(str.Contains(export.ExportHeader), "must contain the header");
            }
Esempio n. 14
0
            public void TestWithPersonData()
            {
                var p = new Person {
                    Name = "Andrei Ignat", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc"
                };
                var export = new ExportExcel2007 <Person>();
                var data   = export.ExportResultStringPart(new List <Person>()
                {
                    p
                });
                var str = data;

                Assert.IsTrue(str.Contains("http://serviciipeweb.ro/iafblog/content/binary/cv.doc"), "must contain the cv");
            }
Esempio n. 15
0
        static void Main(string[] args)
        {
            var p = new Person {
                Name = "andrei", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc"
            };

            Export <Person> export = new ExportHtml <Person>();
            var             data   = export.ExportResult(new List <Person>()
            {
                p
            });

            File.WriteAllBytes("a.html", data);
            Process.Start("a.html");

            export = new ExportExcel2007 <Person>();
            data   = export.ExportResult(new List <Person>()
            {
                p
            });
            File.WriteAllBytes("a.xlsx", data);
            Process.Start("a.xlsx");


            export = new ExportWord2007 <Person>();
            data   = export.ExportResult(new List <Person>()
            {
                p
            });
            File.WriteAllBytes("a.docx", data);
            Process.Start("a.docx");


            export = new ExportPdfiTextSharp4 <Person>();
            data   = export.ExportResult(new List <Person>()
            {
                p
            });
            File.WriteAllBytes("a.pdf", data);
            Process.Start("a.pdf");


            //or you can use the factory
            data = ExportFactory.ExportData(new List <Person>()
            {
                p
            }, ExportToFormat.Excel2007);
            File.WriteAllBytes("b.xlsx", data);
            Process.Start("b.xlsx");
        }
Esempio n. 16
0
            //[TestMethod]
            public void TestExcel2007()
            {
                var p = new Person {
                    Name = "Andrei Ignat", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc"
                };
                var export = new ExportExcel2007 <Person>();
                var data   = export.ExportResult(new List <Person>()
                {
                    p
                });

                //var str = Encoding.Unicode.GetString(data);
                File.WriteAllBytes("a.xlsx", data);
                Process.Start("a.xlsx");
            }
Esempio n. 17
0
            public void TestExcel2007MultipleSheetEqualJustOneSheet()
            {
                var p = new Person {
                    Name = "Andrei Ignat", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc"
                };
                var list = new List <Person>()
                {
                    p
                };
                var export = new ExportExcel2007 <Person>();
                var data   = export.ExportResult(list);

                var data1 = export.ExportMultipleSheets(new IList[] { list });

                Assert.IsTrue(Math.Abs(data.Length - data1.Length) < 100);
            }
Esempio n. 18
0
            public void TestCorrectCSV()
            {
                var data = new List<string>();
                data.Add("Name,WebSite,CV");
                data.Add("Andrei Ignat,http://msprogrammer.serviciipeweb.ro/,http://serviciipeweb.ro/iafblog/content/binary/cv.doc");
                data.Add("Andrei Ignat,http://msprogrammer.serviciipeweb.ro/,http://serviciipeweb.ro/iafblog/content/binary/cv.doc");

                var p = new Person { Name = "Andrei Ignat", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc" };

                var byte1 = new ExportExcel2007<Person>().ExportResult(new List<Person>() { p, p });

                var byte2 = ExportFactory.ExportDataCsv(data.ToArray(), ExportToFormat.Excel2007);

                Assert.IsTrue(Math.Abs(byte1.Length - byte2.Length) < 100);


            }
Esempio n. 19
0
            public void TestCorrectCSV()
            {
                var data = new List <string>();

                data.Add("Name,WebSite,CV");
                data.Add("Andrei Ignat,http://msprogrammer.serviciipeweb.ro/,http://serviciipeweb.ro/iafblog/content/binary/cv.doc");
                data.Add("Andrei Ignat,http://msprogrammer.serviciipeweb.ro/,http://serviciipeweb.ro/iafblog/content/binary/cv.doc");

                var p = new Person {
                    Name = "Andrei Ignat", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc"
                };

                var byte1 = new ExportExcel2007 <Person>().ExportResult(new List <Person>()
                {
                    p, p
                });

                var byte2 = ExportFactory.ExportDataCsv(data.ToArray(), ExportToFormat.Excel2007);

                Assert.IsTrue(Math.Abs(byte1.Length - byte2.Length) < 100);
            }
Esempio n. 20
0
            //[TestMethod]
            public void TestExcel2007MultipleSheets()
            {
                var p = new Person {
                    Name = "Andrei Ignat", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc"
                };
                var list = new List <Person>()
                {
                    p
                };
                var kvp = new List <Tuple <string, string> >();

                for (int i = 0; i < 10; i++)
                {
                    var q = new Tuple <string, string>("This is key " + i, "Value " + i);
                    kvp.Add(q);
                }

                var export = new ExportExcel2007 <Person>();
                var data   = export.ExportMultipleSheets(new IList[] { list, kvp });


                File.WriteAllBytes("multiple.xlsx", data);
                Process.Start("multiple.xlsx");
            }
Esempio n. 21
0
        static void Main(string[] args)
        {
            var p = new Person { Name = "andrei", WebSite = "http://msprogrammer.serviciipeweb.ro/" , CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc" };

            Export<Person> export = new ExportHtml<Person>();
            var data = export.ExportResult(new List<Person>() { p });            
            File.WriteAllBytes("a.html",data);
            Process.Start("a.html");

            export = new ExportExcel2007<Person>();
            data = export.ExportResult(new List<Person>() { p });
            File.WriteAllBytes("a.xlsx", data);
            Process.Start("a.xlsx");


            export = new ExportWord2007<Person>();
            data = export.ExportResult(new List<Person>() { p });
            File.WriteAllBytes("a.docx", data);
            Process.Start("a.docx");


            export = new ExportPdfiTextSharp4<Person>();
            data = export.ExportResult(new List<Person>() { p });
            File.WriteAllBytes("a.pdf", data);
            Process.Start("a.pdf");


            //or you can use the factory
            data = ExportFactory.ExportData(new List<Person>() { p }, ExportToFormat.Excel2007);
            File.WriteAllBytes("b.xlsx", data);
            Process.Start("b.xlsx");

            //export from JSON
            string dataJson = @"[
    { 'Name':'Andrei Ignat', 
        'WebSite':'http://msprogrammer.serviciipeweb.ro/',
        'CV':'http://serviciipeweb.ro/iafblog/content/binary/cv.doc'        
    },
{ 'Name':'Andrei Ignat', 
        'WebSite':'http://msprogrammer.serviciipeweb.ro/',
        'CV':'http://serviciipeweb.ro/iafblog/content/binary/cv.doc'        
    }
]";

            data = ExportFactory.ExportDataJson(dataJson, ExportToFormat.Excel2007);
            File.WriteAllBytes("bJson.xlsx", data);
            Process.Start("bJson.xlsx");


            //or from CSV
            var dataCSV = new List<string>();
            dataCSV.Add("Name,WebSite,CV");
            dataCSV.Add("Andrei Ignat,http://msprogrammer.serviciipeweb.ro/,http://serviciipeweb.ro/iafblog/content/binary/cv.doc");
            dataCSV.Add("Andrei Ignat,http://msprogrammer.serviciipeweb.ro/,http://serviciipeweb.ro/iafblog/content/binary/cv.doc");

            data = ExportFactory.ExportDataCsv(dataCSV.ToArray(), ExportToFormat.Excel2007);
            File.WriteAllBytes("bCSV.xlsx", data);
            Process.Start("bCSV.xlsx");

            var dta = new DataTable("andrei");
            dta.Columns.Add(new DataColumn("ID", typeof(int)));
            dta.Columns.Add(new DataColumn("Data", typeof(string)));
            
            dta.Rows.Add(1, "test 1 ");
            dta.Rows.Add(2, "test 2 ");
            dta.Rows.Add(3, "test 3 ");

            data = ExportFactory.ExportDataFromDataTable(dta, ExportToFormat.Excel2007);
            File.WriteAllBytes("dta.xlsx",data);
            Process.Start("a.xlsx");

            //advanced - modifying templates - in this case , added Number
            export = new ExportExcel2007<Person>();
            //File.WriteAllText("Excel2007Header.txt",export.ExportHeader);
            //File.WriteAllText("Excel2007Item.txt", export.ExportItem);
            //File.WriteAllText("Excel2007Collection.txt", export.ExportCollection);
            export.ExportHeader = File.ReadAllText("Excel2007Header.txt");
            export.ExportItem = File.ReadAllText("Excel2007Item.txt");
            export.ExportCollection = File.ReadAllText("Excel2007Collection.txt");
            data = export.ExportResult(new List<Person>() { p });
            File.WriteAllBytes("WithId.xlsx", data);
            Process.Start("WithId.xlsx");

        }
Esempio n. 22
0
        static void Main(string[] args)
        {
            var p = new Person { Name = "andrei", WebSite = "http://msprogrammer.serviciipeweb.ro/" , CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc" };

            Export<Person> export = new ExportHtml<Person>();
            var data = export.ExportResult(new List<Person>() { p });            
            File.WriteAllBytes("a.html",data);
            Process.Start("a.html");

            export=new ExportExcel2007<Person>();
            data = export.ExportResult(new List<Person>() { p });
            File.WriteAllBytes("a.xlsx", data);
            Process.Start("a.xlsx");


            export = new ExportWord2007<Person>();
            data = export.ExportResult(new List<Person>() { p });
            File.WriteAllBytes("a.docx", data);
            Process.Start("a.docx");


            export = new ExportPdfiTextSharp4<Person>();
            data = export.ExportResult(new List<Person>() { p });
            File.WriteAllBytes("a.pdf", data);
            Process.Start("a.pdf");


            //or you can use the factory
            data = ExportFactory.ExportData(new List<Person>() {p}, ExportToFormat.Excel2007);
            File.WriteAllBytes("b.xlsx", data);
            Process.Start("b.xlsx");

            //export from JSON
            string dataJson = @"[
    { 'Name':'Andrei Ignat', 
        'WebSite':'http://msprogrammer.serviciipeweb.ro/',
        'CV':'http://serviciipeweb.ro/iafblog/content/binary/cv.doc'        
    },
{ 'Name':'Andrei Ignat', 
        'WebSite':'http://msprogrammer.serviciipeweb.ro/',
        'CV':'http://serviciipeweb.ro/iafblog/content/binary/cv.doc'        
    }
]";

            data= ExportFactory.ExportDataJson(dataJson, ExportToFormat.Excel2007);
            File.WriteAllBytes("bJson.xlsx", data);
            Process.Start("bJson.xlsx");


            //or from CSV
            var dataCSV = new List<string>();
            dataCSV.Add("Name,WebSite,CV");
            dataCSV.Add("Andrei Ignat,http://msprogrammer.serviciipeweb.ro/,http://serviciipeweb.ro/iafblog/content/binary/cv.doc");
            dataCSV.Add("Andrei Ignat,http://msprogrammer.serviciipeweb.ro/,http://serviciipeweb.ro/iafblog/content/binary/cv.doc");

            data= ExportFactory.ExportDataCsv(dataCSV.ToArray(), ExportToFormat.Excel2007);
            File.WriteAllBytes("bCSV.xlsx", data);
            Process.Start("bCSV.xlsx");


        }
Esempio n. 23
0
        private static void Advanced_MultipleSheets()
        {
            var p = new Person {
                Name = "andrei", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc"
            };
            var p1 = new Person {
                Name = "you", WebSite = "http://yourwebsite.com/"
            };
            var list = new List <Person>()
            {
                p, p1
            };

            var kvp = new List <Tuple <string, string> >();

            for (int i = 0; i < 10; i++)
            {
                var q = new Tuple <string, string>("This is key " + i, "Value " + i);
                kvp.Add(q);
            }

            var export = new ExportExcel2007 <Person>();
            var data   = export.ExportMultipleSheets(new IList[] { list, kvp });

            if (!writeAndStartFile("multiple.xlsx", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete multiple.xlsx");
            }


            //export dataset
            var ds       = new DataSet();
            var table    = new DataTable("programmers");
            var idColumn = table.Columns.Add("ID", typeof(int));

            table.Columns.Add("Name", typeof(string));
            table.Columns.Add("WebSite", typeof(string));

            table.PrimaryKey = new DataColumn[] { idColumn };

            table.Rows.Add(new object[] { 1, "Andrei Ignat", "http://msprogrammer.serviciipeweb.ro" });
            table.Rows.Add(new object[] { 2, "Scott Hanselman", "http://www.hanselman.com/blog/" });

            ds.Tables.Add(table);

            var dta = new DataTable("andrei");

            dta.Columns.Add(new DataColumn("ID", typeof(int)));
            dta.Columns.Add(new DataColumn("Data", typeof(string)));
            dta.Rows.Add(1, "test 1 ");
            dta.Rows.Add(2, "test 2 ");
            dta.Rows.Add(3, "test 3 ");
            ds.Tables.Add(dta);



            export = new ExportExcel2007 <Person>();
            data   = ExportFactory.ExportDataSet(ds, ExportToFormat.Excel2007);
            if (!writeAndStartFile("multipleDataSet.xlsx", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete multipleDataSet.xlsx");
            }
        }
Esempio n. 24
0
        static void SeeAllExport()
        {
            var p = new Person {
                Name = "andrei", WebSite = "http://msprogrammer.serviciipeweb.ro/", CV = "http://serviciipeweb.ro/iafblog/content/binary/cv.doc"
            };
            var p1 = new Person {
                Name = "you", WebSite = "http://yourwebsite.com/"
            };
            var list = new List <Person>()
            {
                p, p1
            };
            Export <Person> export = new ExportHtml <Person>();
            var             data   = export.ExportResult(list);

            if (!writeAndStartFile("a.html", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete a.html");
            }

            export = new ExportExcel2003 <Person>();
            data   = export.ExportResult(list);
            if (!writeAndStartFile("a.xls", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete a.xls");
            }

            export = new ExportODS <Person>();
            data   = export.ExportResult(list);
            if (!writeAndStartFile("a.ods", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete a.ods");
            }


            export = new ExportExcel2007 <Person>();
            data   = export.ExportResult(list);
            if (!writeAndStartFile("a.xlsx", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete a.xlsx");
            }

            export = new ExportWord2003 <Person>();
            data   = export.ExportResult(list);
            if (!writeAndStartFile("a.doc", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete a.doc");
            }



            export = new ExportWord2007 <Person>();
            data   = export.ExportResult(list);
            if (!writeAndStartFile("a.docx", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete a.docx");
            }


            export = new ExportPdfiTextSharp4 <Person>();
            data   = export.ExportResult(list);
            if (!writeAndStartFile("a.pdf", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete a.pdf");
            }


            export = new ExportODT <Person>();
            data   = export.ExportResult(list);
            if (!writeAndStartFile("a.odt", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete a.odt");
            }


            //or you can use the factory
            data = ExportFactory.ExportData(list, ExportToFormat.Excel2007);
            if (!writeAndStartFile("b.xlsx", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete b.xlsx");
            }

            //export from JSON
            string dataJson = @"[
    { 'Name':'Andrei Ignat', 
        'WebSite':'http://msprogrammer.serviciipeweb.ro/',
        'CV':'http://serviciipeweb.ro/iafblog/content/binary/cv.doc'        
    },
{ 'Name':'Andrei Ignat', 
        'WebSite':'http://msprogrammer.serviciipeweb.ro/',
        'CV':'http://serviciipeweb.ro/iafblog/content/binary/cv.doc'        
    }
]";

            data = ExportFactory.ExportDataJson(dataJson, ExportToFormat.Excel2007);
            if (!writeAndStartFile("bJson.xlsx", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete bJson.xlsx");
            }


            //or from CSV
            var dataCSV = new List <string>();

            dataCSV.Add("Name,WebSite,CV");
            dataCSV.Add("Andrei Ignat,http://msprogrammer.serviciipeweb.ro/,http://serviciipeweb.ro/iafblog/content/binary/cv.doc");
            dataCSV.Add("Andrei Ignat,http://msprogrammer.serviciipeweb.ro/,http://serviciipeweb.ro/iafblog/content/binary/cv.doc");

            data = ExportFactory.ExportDataCsv(dataCSV.ToArray(), ExportToFormat.Excel2007);
            if (!writeAndStartFile("bCSV.xlsx", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete bCSV.xlsx");
            }

            var dta = new DataTable("andrei");

            dta.Columns.Add(new DataColumn("ID", typeof(int)));
            dta.Columns.Add(new DataColumn("Data", typeof(string)));

            dta.Rows.Add(1, "test 1 ");
            dta.Rows.Add(2, "test 2 ");
            dta.Rows.Add(3, "test 3 ");

            data = ExportFactory.ExportDataFromDataTable(dta, ExportToFormat.Excel2007);
            if (!writeAndStartFile("dta.xlsx", data))
            {
                Console.WriteLine(" !!!!!!!!!!Could not delete a.xlsx");
            }
        }