Example #1
0
        public void WriteXlsxTest()
        {
            XlsxWriter writer         = new XlsxWriter();
            string     xlsxOutputPath = $@".\assets\_output_{DateTime.Now.ToString("yyyyMMddHHmmss")}.xlsx";

            writer.WriteXlsx(@".\assets\template.xlsx", xlsxOutputPath, new[] {
                new WriteXlsxOptions
                {
                    SheetName = "Sheet1",
                    IndividualReplacements = new Dictionary <string, object> {
                        { "##NAME##", "Lorem Ipsum" },
                        { "##AGE##", 35 },
                        { "##BIRTHDATE##", new DateTime(1982, 1, 18) },
                        { "##HEIGHT##", 1.85M },
                        { "##EMAIL##", "*****@*****.**" },
                        { "##ISMARRIED##", true },
                    },
                    LineLocators = new [] {
                        "##SON_NAME##", "##SON_AGE##", "##SON_EMAIL##", "##SON_BIRTHDATE##", "##SON_HEIGHT##", "##SON_GENDER##"
                    },
                    LineReplacements = new [] {
                        new Dictionary <string, object> {
                            { "##SON_NAME##", "Agnes" },
                            { "##SON_AGE##", 2 },
                            { "##SON_EMAIL##", "*****@*****.**" },
                            { "##SON_BIRTHDATE##", new DateTime(2015, 6, 17) },
                            { "##SON_HEIGHT##", 0.65 },
                            { "##SON_GENDER##", "F" }
                        },
                        new Dictionary <string, object> {
                            { "##SON_NAME##", "Bernardo" },
                            { "##SON_AGE##", 10 },
                            { "##SON_EMAIL##", "*****@*****.**" },
                            { "##SON_BIRTHDATE##", new DateTime(2007, 10, 20) },
                            { "##SON_HEIGHT##", 1.50 },
                            { "##SON_GENDER##", "M" }
                        },
                        new Dictionary <string, object> {
                            { "##SON_NAME##", "Miguel" },
                            { "##SON_AGE##", 8 },
                            { "##SON_EMAIL##", "*****@*****.**" },
                            { "##SON_BIRTHDATE##", new DateTime(2017, 11, 11) },
                            { "##SON_HEIGHT##", 1.25 },
                            { "##SON_GENDER##", "M" }
                        },
                    }
                }
            });
            Assert.IsTrue(File.Exists(xlsxOutputPath));
            Process.Start(xlsxOutputPath);
        }