Beispiel #1
0
        public void Write2Rows()
        {
            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.CreateNew(Filename))
            {
                using (IWorksheetWriter writer = spreadsheet.WriteToWorksheet("UnitTests"))
                {
                    Assert.That(writer.GetCurrentCell().Address, Is.EqualTo("A1"));
                    writer.WriteRow(new List <string> {
                        "One", "Two", "Three"
                    });
                    Assert.That(writer.GetCurrentCell().Address, Is.EqualTo("A2"));
                    writer.WriteRow(new List <string> {
                        "Four", "Five", "Six"
                    });
                    Assert.That(writer.GetCurrentCell().Address, Is.EqualTo("A3"));
                }
            }

            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.OpenReadOnly(Filename))
            {
                IWorksheetReader reader = spreadsheet.ReadWorksheet("UnitTests");
                List <string>    list   = reader.ReadRow();
                Assert.That(list, Is.Not.Empty);
                Assert.That(list, Is.EquivalentTo(new List <string> {
                    "One", "Two", "Three"
                }));
                list = reader.ReadRow();
                Assert.That(list, Is.Not.Empty);
                Assert.That(list, Is.EquivalentTo(new List <string> {
                    "Four", "Five", "Six"
                }));
            }
        }
        public void WriteEnterpriseSiteArea()
        {
            Hierarchy hierarchy = new Hierarchy();

            hierarchy.Enterprise = new Enterprise("My Company");
            hierarchy.Enterprise.Site.Add(new Site("My Site"));
            hierarchy.Enterprise.Site[0].Area.Add(new Area("My Area"));

            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.CreateNew(Filename))
            {
                HierarchyWriterCommand command = new HierarchyWriterCommand(hierarchy, spreadsheet);
                command.Execute();
            }

            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.OpenReadOnly(Filename))
            {
                using (IWorksheetReader reader = spreadsheet.ReadWorksheet("Hierarchy"))
                {
                    reader.MoveTo("A1");
                    Assert.That(reader.ReadRow(), Is.EquivalentTo(expectedHeader));
                    CheckRow(reader, "A2", 1, "Enterprise", string.Empty, "My Company");
                    CheckRow(reader, "A3", 2, "Site", string.Empty, "My Site");
                    CheckRow(reader, "A4", 3, "Area", string.Empty, "My Area");
                }
            }
        }
Beispiel #3
0
        public void Write()
        {
            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.CreateNew(Filename))
            {
                using (IWorksheetWriter writer = spreadsheet.WriteToWorksheet("UnitTests"))
                {
                    Assert.That(writer.GetCurrentCell().Address, Is.EqualTo("A1"));
                    writer.Write("One");
                    Assert.That(writer.GetCurrentCell().Address, Is.EqualTo("B1"));

                    writer.MoveTo("D3");
                    writer.Write("New value at D3");
                    Assert.That(writer.GetCurrentCell().Address, Is.EqualTo("E3"));
                }
            }

            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.OpenReadOnly(Filename))
            {
                IWorksheetReader reader = spreadsheet.ReadWorksheet("UnitTests");
                reader.MoveTo("A1");
                Assert.That(reader.Read(), Is.EqualTo("One"));
                Assert.That(reader.GetCurrentCell().Address, Is.EqualTo("B1"));
                reader.MoveTo("D3");
                Assert.That(reader.Read(), Is.EqualTo("New value at D3"));
                Assert.That(reader.GetCurrentCell().Address, Is.EqualTo("E3"));
            }
        }
Beispiel #4
0
        public void GetCurrentCell()
        {
            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.CreateNew(Filename))
            {
                using (IWorksheetWriter writer = spreadsheet.WriteToWorksheet("UnitTests"))
                {
                    Assert.That(writer.GetCurrentCell().Address, Is.EqualTo("A1"));
                    writer.MoveTo("B2");
                    Assert.That(writer.GetCurrentCell().Address, Is.EqualTo("B2"));

                    writer.MoveTo(10, 20);
                    Assert.That(writer.GetCurrentCell().Address, Is.EqualTo("T10"));
                }
            }
        }
Beispiel #5
0
 private void WriteTestValues()
 {
     using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.CreateNew(Filename))
     {
         IWorksheetWriter writer = spreadsheet.WriteToWorksheet("UnitTests");
         writer.WriteRow(new List <string> {
             "A-1", "B-1", "C-1"
         });
         writer.WriteRow(new List <string> {
             "A-2", "B-2", "C-2"
         });
         writer.WriteRow(new List <string> {
             "A-3", "B-3", "C-3"
         });
     }
 }
Beispiel #6
0
 public void IsEndOfDataEmpty()
 {
     using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.CreateNew(Filename))
     {
         using (spreadsheet.WriteToWorksheet("UnitTests"))
         {
         }
     }
     using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.OpenReadOnly(Filename))
     {
         using (IWorksheetReader reader = spreadsheet.ReadWorksheet("UnitTests"))
         {
             Assert.That(reader.IsEndOfData(), Is.True);
         }
     }
 }
Beispiel #7
0
        public void ReadOnlyWorksheet()
        {
            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.CreateNew(Filename))
            {
                Assert.That(spreadsheet.IsReadOnly, Is.False);
                IWorksheetWriter worksheet = spreadsheet.WriteToWorksheet("New sheet");
                worksheet.WriteRow(new List <string> {
                    "One", "Two", "Three"
                });
                Assert.That(worksheet, Is.Not.Null);
            }

            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.OpenReadOnly(Filename))
            {
                Assert.That(spreadsheet.IsReadOnly, Is.True);
                Assert.Throws <InvalidOperationException>(() => spreadsheet.WriteToWorksheet("Should fail"));
            }
        }
Beispiel #8
0
        public void ReadRow()
        {
            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.CreateNew(Filename))
            {
                IWorksheetWriter writer = spreadsheet.WriteToWorksheet("UnitTests");
                List <string>    list   = new List <string> {
                    "One", "Two", "Three"
                };
                writer.WriteRow(list);
            }

            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.OpenReadOnly(Filename))
            {
                IWorksheetReader reader = spreadsheet.ReadWorksheet("UnitTests");
                List <string>    list   = reader.ReadRow();
                Assert.That(list, Is.Not.Empty);
                Assert.That(list, Is.EquivalentTo(new List <string> {
                    "One", "Two", "Three"
                }));
            }
        }
Beispiel #9
0
        public void MoveToAndWrite()
        {
            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.CreateNew(Filename))
            {
                using (IWorksheetWriter writer = spreadsheet.WriteToWorksheet("UnitTests"))
                {
                    Assert.That(writer.GetCurrentCell().Address, Is.EqualTo("A1"));
                    writer.MoveTo("B2");
                    writer.WriteRow(new List <string> {
                        "One", "Two", "Three"
                    });
                    Assert.That(writer.GetCurrentCell().Address, Is.EqualTo("B3"));
                    writer.WriteRow(new List <string> {
                        "Four", "Five", "Six"
                    });
                    Assert.That(writer.GetCurrentCell().Address, Is.EqualTo("B4"));
                }
            }

            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.OpenReadOnly(Filename))
            {
                using (IWorksheetReader reader = spreadsheet.ReadWorksheet("UnitTests"))
                {
                    Assert.That(reader.GetCurrentCell().Address, Is.EqualTo("A1"));
                    Assert.That(reader.ReadRow(), Is.EquivalentTo(new List <string>()));

                    reader.MoveTo("B2");
                    Assert.That(reader.GetCurrentCell().Address, Is.EqualTo("B2"));
                    Assert.That(reader.ReadRow(), Is.EquivalentTo(new List <string> {
                        "One", "Two", "Three"
                    }));
                    Assert.That(reader.GetCurrentCell().Address, Is.EqualTo("B3"));
                    Assert.That(reader.ReadRow(), Is.EquivalentTo(new List <string> {
                        "Four", "Five", "Six"
                    }));
                }
            }
        }
Beispiel #10
0
        public void ReadAndWrite()
        {
            List <string> list = new List <string> {
                "One", "Two", "Three"
            };

            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.CreateNew(Filename))
            {
                IWorksheetWriter worksheet = spreadsheet.WriteToWorksheet("New sheet");
                Assert.That(worksheet, Is.Not.Null);
                worksheet.WriteRow(list);
            }

            List <string> result;

            using (IExcelSpreadsheet spreadsheet = ExcelSpreadsheet.OpenReadOnly(Filename))
            {
                IWorksheetReader worksheet = spreadsheet.ReadWorksheet("New sheet");
                Assert.That(worksheet, Is.Not.Null);
                result = worksheet.ReadRow();
            }

            Assert.That(result, Is.EquivalentTo(list));
        }
Beispiel #11
0
 public void EmptyFilename()
 {
     Assert.Throws <ArgumentException>(() => ExcelSpreadsheet.CreateNew(""));
 }
Beispiel #12
0
 public void NullFilename()
 {
     Assert.Throws <ArgumentNullException>(() => ExcelSpreadsheet.CreateNew(null));
 }
 public Worksheet(string filename, string name)
 {
     spreadsheet = ExcelSpreadsheet.CreateNew(filename);
     writer      = spreadsheet.WriteToWorksheet(name);
 }