コード例 #1
0
        public void AvrTableToTableTest()
        {
            var originalTable = DataHelper.GenerateTestTable();
            var avrTable      = new AvrDataTable(originalTable);

            AccessTests.RemoveCopyColumns(avrTable);
            var finalTable = avrTable.ToDataTable();

            BinarySerializerTests.AssertTablesAreEqual(originalTable, finalTable);
        }
コード例 #2
0
        public void Export()
        {
            AvrDataTable data = CreateData();

            AccessTests.RemoveCopyColumns(data);
            string fileName = Path.GetTempPath() + "test.xls";

            using (var npoiExcelWrapper = new NpoiExcelWrapper(ExportType.Xls))
            {
                npoiExcelWrapper.Export(fileName, data);
                Assert.IsTrue(File.Exists(fileName));
                for (int j = 0; j < data.Columns.Count; j++)
                {
                    Assert.AreEqual(data.Columns[j].Caption, npoiExcelWrapper.Workbook.GetSheetAt(0).GetRow(0).GetCell(j).StringCellValue);
                }

                for (int j = 0; j < data.Rows.Count; j++)
                {
                    Assert.AreEqual(data.Rows[j][0], npoiExcelWrapper.Workbook.GetSheetAt(0).GetRow(j + 1).GetCell(0).StringCellValue);
                }
                for (int j = 0; j < data.Rows.Count; j++)
                {
                    Assert.AreEqual(((DateTime)data.Rows[j][1]).Date, npoiExcelWrapper.Workbook.GetSheetAt(0).GetRow(j + 1).GetCell(1).DateCellValue.Date);
                }
                for (int j = 0; j < data.Rows.Count; j++)
                {
                    Assert.AreEqual(data.Rows[j][2], Convert.ToInt32(npoiExcelWrapper.Workbook.GetSheetAt(0).GetRow(j + 1).GetCell(2).NumericCellValue));
                }
                for (int j = 0; j < data.Rows.Count; j++)
                {
                    Assert.AreEqual(data.Rows[j][3], npoiExcelWrapper.Workbook.GetSheetAt(0).GetRow(j + 1).GetCell(3).NumericCellValue);
                }
            }

            fileName = Path.GetTempPath() + "test.xlsx";
            using (var npoiExcelWrapper = new NpoiExcelWrapper(ExportType.Xlsx))
            {
                npoiExcelWrapper.Export(fileName, data);
                Assert.IsTrue(File.Exists(fileName));
                for (int j = 0; j < data.Columns.Count; j++)
                {
                    Assert.AreEqual(data.Columns[j].Caption, npoiExcelWrapper.Workbook.GetSheetAt(0).GetRow(0).GetCell(j).StringCellValue);
                }

                for (int j = 0; j < data.Rows.Count; j++)
                {
                    Assert.AreEqual(data.Rows[j][0], npoiExcelWrapper.Workbook.GetSheetAt(0).GetRow(j + 1).GetCell(0).StringCellValue);
                }
                for (int j = 0; j < data.Rows.Count; j++)
                {
                    Assert.AreEqual(((DateTime)data.Rows[j][1]).Date, npoiExcelWrapper.Workbook.GetSheetAt(0).GetRow(j + 1).GetCell(1).DateCellValue.Date);
                }
                for (int j = 0; j < data.Rows.Count; j++)
                {
                    Assert.AreEqual(data.Rows[j][2], Convert.ToInt32(npoiExcelWrapper.Workbook.GetSheetAt(0).GetRow(j + 1).GetCell(2).NumericCellValue));
                }
                for (int j = 0; j < data.Rows.Count; j++)
                {
                    Assert.AreEqual(data.Rows[j][3], npoiExcelWrapper.Workbook.GetSheetAt(0).GetRow(j + 1).GetCell(3).NumericCellValue);
                }
            }

            //fileName = Path.GetTempPath() + "test1.xlsx";
            //using (var npoiExcelWrapper = new ClosedXmlExcelWrapper())
            //{
            //    npoiExcelWrapper.Export(fileName, data);
            //    Assert.IsTrue(File.Exists(fileName));
            //}
        }