public void CreateSingleSheetWorksheet_ShouldThrowArgumentException_WhenWorksheetNameIsMissing()
        {
            //Arrange
            var configuration = new SpreadsheetConfiguration <SampleExportRecord>();

            //Act/Assert
            //Assert that it throws the exception
            var result = Assert.Throws <ArgumentException>(() =>
                                                           _spreadsheetGenerator.CreateSingleSheetSpreadsheet <SampleExportRecord>(configuration));

            //Assert for the proper property
            Assert.Equal("WorksheetName", result.ParamName);
        }
        public void CreateSingleSheetWorksheet_ShouldThrowArgumentException_WhenRenderTitleIsTrueAndDocumentTitleIsNull()
        {
            //Arrange
            var configuration = new SpreadsheetConfiguration <SampleExportRecord>
            {
                WorksheetName = "TestSheet", ExportData = new List <SampleExportRecord>(), RenderTitle = true
            };

            //Act/Assert
            //Assert that it throws the exception
            var result = Assert.Throws <ArgumentException>(() =>
                                                           _spreadsheetGenerator.CreateSingleSheetSpreadsheet <SampleExportRecord>(configuration));

            //Assert for the proper property
            Assert.Equal("DocumentTitle", result.ParamName);
        }
Example #3
0
        public async Task Constructor_ChangeJsonFile_ReturnTrue()
        {
            ConfigSettings configSettings = CreateConfigSettingsByJsonFile();

            await WriteJsonFileAsync(configSettings);

            SpreadsheetConfiguration actual = new SpreadsheetConfiguration(
                TestContext.CurrentContext.TestDirectory, JsonFile
                );

            configSettings.Cell.Font.FontName = "標楷體";
            await WriteJsonFileAsync(configSettings);

            // 要等ChangeToken.OnChange()觸發完畢
            await Task.Delay(5000);

            actual.CellStyle.Font.Name.Should().Be("標楷體");

            DeleteJsonFile();
        }
        static void Main(string[] args)
        {
            //Setup our DI Container
            var services = new ServiceCollection();

            services.UseIcgNetCoreUtilitiesSpreadsheet();
            var provider = services.BuildServiceProvider();

            //Get our generator and export
            var exportGenerator  = provider.GetService <ISpreadsheetGenerator>();
            var exportDefinition = new SpreadsheetConfiguration <SimpleExportData>
            {
                RenderTitle      = true,
                DocumentTitle    = "Sample Export of 100 Records",
                RenderSubTitle   = true,
                DocumentSubTitle = "Showing the full options",
                ExportData       = GetSampleExportData(100),
                WorksheetName    = "Sample"
            };
            var fileContent = exportGenerator.CreateSingleSheetSpreadsheet(exportDefinition);

            System.IO.File.WriteAllBytes("Sample.xlsx", fileContent);

            var multiSheet = new List <ISpreadsheetConfiguration <object> >();

            multiSheet.Add(exportDefinition);
            multiSheet.Add(new SpreadsheetConfiguration <SimpleExportData>
            {
                RenderTitle      = true,
                DocumentTitle    = "Sample Second of 50 Records",
                RenderSubTitle   = true,
                DocumentSubTitle = "Showing the full options",
                ExportData       = GetSampleExportData(50),
                WorksheetName    = "Additional"
            });
            var multiFileContent = exportGenerator.CreateMultiSheetSpreadsheet(multiSheet);

            System.IO.File.WriteAllBytes("Sample-Multi.xlsx", multiFileContent);
            Console.WriteLine("Files Created");
            Console.ReadLine();
        }
Example #5
0
        public void Constructor_UseAction_ReturnTrue()
        {
            CellFont  cellFont  = new CellFont("新細明體", 10, Color.Black, FontStyles.None);
            CellStyle cellStyle = new CellStyle(HorizontalAlignment.Center, VerticalAlignment.Middle, false, false, Color.Empty, cellFont);

            CreateTestCellStyle(cellStyle, out CellStyle listHeaderStyle,
                                out CellStyle listTextStyle, out CellStyle listNumberStyle, out CellStyle listDateTimeStyle
                                );

            SpreadsheetConfiguration actual = new SpreadsheetConfiguration(x => {
                x.CellStyle         = cellStyle;
                x.ListHeaderStyle   = listHeaderStyle;
                x.ListTextStyle     = listTextStyle;
                x.ListNumberStyle   = listNumberStyle;
                x.ListDateTimeStyle = listDateTimeStyle;
            });

            actual.CellStyle.Should().Be(cellStyle);
            actual.ListHeaderStyle.Should().Be(listHeaderStyle);
            actual.ListTextStyle.Should().Be(listTextStyle);
            actual.ListNumberStyle.Should().Be(listNumberStyle);
            actual.ListDateTimeStyle.Should().Be(listDateTimeStyle);
        }
Example #6
0
        public async Task Constructor_UseJsonFile_ReturnTrue()
        {
            ConfigSettings configSettings = CreateConfigSettingsByJsonFile();

            await WriteJsonFileAsync(configSettings);

            SpreadsheetConfiguration actual = new SpreadsheetConfiguration(
                TestContext.CurrentContext.TestDirectory, JsonFile
                );

            CellStyle cellStyle = new CellStyle(font: new CellFont("新細明體", 10, Color.Black));

            CreateTestCellStyle(cellStyle, out CellStyle listHeaderStyle,
                                out CellStyle listTextStyle, out CellStyle listNumberStyle, out CellStyle listDateTimeStyle
                                );

            actual.CellStyle.Should().Be(cellStyle);
            actual.ListHeaderStyle.Should().Be(listHeaderStyle);
            actual.ListTextStyle.Should().Be(listTextStyle);
            actual.ListNumberStyle.Should().Be(listNumberStyle);
            actual.ListDateTimeStyle.Should().Be(listDateTimeStyle);

            DeleteJsonFile();
        }