public void Setup() { sut = new ExcelExport(); formatter = new CellFormatter(); workBook = Helper.CreateWorkBookWithSheet(); sampleData = new List <List <Cell> > { new List <Cell> { new Cell { Value = "1" }, new Cell { Value = "2" }, new Cell { Value = "a" }, new Cell { Value = "b" }, } }; }
public void WriteDataToExport(IEnumerable <IEnumerable <Cell> > rowData, CellFormatter formatter, string sheetName) { if (currentSheet == null) { currentSheet = workBook.CreateSheet(sheetName); } formatter.WriteDataToSheet(currentSheet, rowData); }
/// <summary> /// Exports the data supplied to an excel workbook /// </summary> /// <param name="rowData">The data to be exported to the workbook</param> /// <param name="formatter"></param> public void WriteDataToExport(IEnumerable <IEnumerable <Cell> > rowData, CellFormatter formatter, ExcelFileType excelFileType) { if (excelFileType == ExcelFileType.XLS) { ExcelExporter = new ExcelXlsExporter(); } ExcelExporter.WriteDataToExport(rowData, formatter, "Sheet 1"); }
public void Should_return_stream_with_data() { MemoryStream outputStream = new MemoryStream(); ExcelExport target = new ExcelExport(); CellFormatter formatter = new CellFormatter(); target.WriteDataToExport(sampleData, formatter, ExcelFileType.XLS); target.ExportToStream(outputStream); Assert.IsTrue(outputStream.Length > 0); }
public void Should_be_able_to_pass_data_to_be_written_to_workbook() { ExcelExport target = new ExcelExport(); Workbook book = Helper.CreateWorkBookWithSheet(); List <List <Cell> > cells = new List <List <Cell> > { new List <Cell> { new Cell { Value = "123" } } }; CellFormatter formatter = Substitute.For <CellFormatter>(); formatter.WriteDataToSheet(book.GetSheetAt(0), cells); formatter.Received().WriteDataToSheet(book.GetSheetAt(0), cells); }
public void Setup() { target = new CellFormatter(); workBook = Helper.CreateWorkBookWithSheet(); sampleData = new List <List <Cell> > { new List <Cell> { new Cell { Value = "1" }, new Cell { Value = "2", IsBold = true }, new Cell { Value = "a" }, new Cell { Value = "b", IsBold = true }, } }; }
public override void Execute() { #line 10 "..\..\Chart\Views\ChartResultsTable.cshtml" ResultTable queryResult = (ResultTable)ViewData[ViewDataKeys.Results]; bool navigate = (bool)ViewData[ViewDataKeys.Navigate]; var formatters = (Dictionary <int, CellFormatter>)ViewData[ViewDataKeys.Formatters]; var entityFormatter = (EntityFormatter)ViewData[ViewDataKeys.EntityFormatter]; #line default #line hidden WriteLiteral("\r\n<div"); WriteLiteral(" class=\"table-responsive\""); WriteLiteral(">\r\n <table"); WriteAttribute("id", Tuple.Create(" id=\"", 607), Tuple.Create("\"", 640) #line 17 "..\..\Chart\Views\ChartResultsTable.cshtml" , Tuple.Create(Tuple.Create("", 612), Tuple.Create <System.Object, System.Int32>(Model.Compose("tblResults") #line default #line hidden , 612), false) ); WriteLiteral(" class=\"sf-search-results table table-hover table-condensed\""); WriteLiteral(">\r\n <thead>\r\n <tr>\r\n"); #line 20 "..\..\Chart\Views\ChartResultsTable.cshtml" #line default #line hidden #line 20 "..\..\Chart\Views\ChartResultsTable.cshtml" if (!Model.Value.GroupResults && navigate) { #line default #line hidden WriteLiteral(" <th"); WriteLiteral(" class=\"sf-th-entity\""); WriteLiteral("></th>\r\n"); #line 23 "..\..\Chart\Views\ChartResultsTable.cshtml" } #line default #line hidden WriteLiteral(" "); #line 24 "..\..\Chart\Views\ChartResultsTable.cshtml" if (queryResult.Columns.Any()) { foreach (ResultColumn col in queryResult.Columns) { var order = Model.Value.Orders.FirstOrDefault(oo => oo.Token.FullKey() == col.Column.Name); #line default #line hidden WriteLiteral(" <th"); WriteLiteral(" data-column-name=\""); #line 29 "..\..\Chart\Views\ChartResultsTable.cshtml" Write(col.Column.Name); #line default #line hidden WriteLiteral("\""); WriteLiteral(">\r\n <span"); WriteAttribute("class", Tuple.Create(" class=\"", 1269), Tuple.Create("\"", 1424) , Tuple.Create(Tuple.Create("", 1277), Tuple.Create("sf-header-sort", 1277), true) #line 30 "..\..\Chart\Views\ChartResultsTable.cshtml" , Tuple.Create(Tuple.Create(" ", 1291), Tuple.Create <System.Object, System.Int32>(order == null ? "" : ((order.OrderType == OrderType.Ascending ? "asc" : "desc") + (" l" + Model.Value.Orders.IndexOf(order) % 4)) #line default #line hidden , 1292), false) ); WriteLiteral("></span>\r\n <span>"); #line 31 "..\..\Chart\Views\ChartResultsTable.cshtml" Write(col.Column.DisplayName); #line default #line hidden WriteLiteral("</span>\r\n </th>\r\n"); #line 33 "..\..\Chart\Views\ChartResultsTable.cshtml" } } #line default #line hidden WriteLiteral(" </tr>\r\n </thead>\r\n <tbody>\r\n"); #line 38 "..\..\Chart\Views\ChartResultsTable.cshtml" #line default #line hidden #line 38 "..\..\Chart\Views\ChartResultsTable.cshtml" if (!queryResult.Rows.Any()) { #line default #line hidden WriteLiteral(" <tr>\r\n <td"); WriteAttribute("colspan", Tuple.Create(" colspan=\"", 1731), Tuple.Create("\"", 1792) #line 41 "..\..\Chart\Views\ChartResultsTable.cshtml" , Tuple.Create(Tuple.Create("", 1741), Tuple.Create <System.Object, System.Int32>(queryResult.Columns.Count() + (navigate ? 1 : 0) #line default #line hidden , 1741), false) ); WriteLiteral(">\r\n"); WriteLiteral(" "); #line 42 "..\..\Chart\Views\ChartResultsTable.cshtml" Write(SearchMessage.NoResultsFound.NiceToString()); #line default #line hidden WriteLiteral("\r\n </td>\r\n </tr>\r\n"); #line 45 "..\..\Chart\Views\ChartResultsTable.cshtml" } else { foreach (var row in queryResult.Rows) { if (Model.Value.GroupResults) { #line default #line hidden WriteLiteral(" <tr>\r\n"); #line 53 "..\..\Chart\Views\ChartResultsTable.cshtml" #line default #line hidden #line 53 "..\..\Chart\Views\ChartResultsTable.cshtml" foreach (var col in queryResult.Columns) { CellFormatter ft = formatters[col.Index]; var value = row[col]; #line default #line hidden WriteLiteral(" <td "); #line 57 "..\..\Chart\Views\ChartResultsTable.cshtml" Write(ft.WriteDataAttribute(value)); #line default #line hidden WriteLiteral(">"); #line 57 "..\..\Chart\Views\ChartResultsTable.cshtml" Write(ft.Formatter(Html, value)); #line default #line hidden WriteLiteral("</td>\r\n"); #line 58 "..\..\Chart\Views\ChartResultsTable.cshtml" } #line default #line hidden WriteLiteral(" </tr>\r\n"); #line 60 "..\..\Chart\Views\ChartResultsTable.cshtml" } else { Lite <Entity> entityField = row.Entity; #line default #line hidden WriteLiteral(" <tr"); WriteLiteral(" data-entity=\""); #line 64 "..\..\Chart\Views\ChartResultsTable.cshtml" Write(entityField.Key()); #line default #line hidden WriteLiteral("\""); WriteLiteral(">\r\n"); #line 65 "..\..\Chart\Views\ChartResultsTable.cshtml" #line default #line hidden #line 65 "..\..\Chart\Views\ChartResultsTable.cshtml" if (entityField != null && navigate) { #line default #line hidden WriteLiteral(" <td>"); #line 67 "..\..\Chart\Views\ChartResultsTable.cshtml" Write((entityFormatter ?? QuerySettings.EntityFormatRules.Last(fr => fr.IsApplyable(row)).Formatter)(Html, row)); #line default #line hidden WriteLiteral("</td>\r\n"); #line 68 "..\..\Chart\Views\ChartResultsTable.cshtml" } #line default #line hidden WriteLiteral(" "); #line 69 "..\..\Chart\Views\ChartResultsTable.cshtml" foreach (var col in queryResult.Columns) { var value = row[col]; var ft = formatters[col.Index]; #line default #line hidden WriteLiteral(" <td "); #line 73 "..\..\Chart\Views\ChartResultsTable.cshtml" Write(ft.WriteDataAttribute(value)); #line default #line hidden WriteLiteral(">"); #line 73 "..\..\Chart\Views\ChartResultsTable.cshtml" Write(ft.Formatter(Html, value)); #line default #line hidden WriteLiteral("</td>\r\n"); #line 74 "..\..\Chart\Views\ChartResultsTable.cshtml" } #line default #line hidden WriteLiteral(" </tr>\r\n"); #line 76 "..\..\Chart\Views\ChartResultsTable.cshtml" } } } #line default #line hidden WriteLiteral(" </tbody>\r\n </table>\r\n</div>\r\n"); }