public void AddAttributesToRender_Null_WebControl() { TableItemStyle tis = new TableItemStyle(); tis.AddAttributesToRender(null, new TableRow()); // no exception }
public void AddAttributesToRender() { TableItemStyle tis = GetTableItemStyle(); HtmlTextWriter writer = new HtmlTextWriter(new StringWriter()); tis.AddAttributesToRender(writer, new Table()); Assert.AreEqual(String.Empty, writer.InnerWriter.ToString(), "empty"); }
private void WriteTableCell(HtmlTextWriter htmlTextWriter, string cellValue) { if (_itemStyle != null) { _itemStyle.AddAttributesToRender(htmlTextWriter); } htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Td); htmlTextWriter.Write(HttpUtility.HtmlEncode(cellValue)); htmlTextWriter.RenderEndTag(); }
private void WriteHeaderCell(HtmlTextWriter htmlTextWriter, string columnTitle) { if (_headerStyle != null) { _headerStyle.AddAttributesToRender(htmlTextWriter); } htmlTextWriter.RenderBeginTag(HtmlTextWriterTag.Th); htmlTextWriter.Write(HttpUtility.HtmlEncode(columnTitle)); htmlTextWriter.RenderEndTag(); }
protected override void WriteFile(HttpResponseBase response) { // Create HtmlTextWriter StringWriter sw = new StringWriter(); HtmlTextWriter tw = new HtmlTextWriter(sw); // Build HTML Table from Items if (tableStyle != null) { tableStyle.AddAttributesToRender(tw); } tw.RenderBeginTag(HtmlTextWriterTag.Table); // Create Title Row tw.RenderBeginTag(HtmlTextWriterTag.Tr); tw.AddAttribute(HtmlTextWriterAttribute.Colspan, (dt.Columns.Count - 2).ToString()); tw.RenderBeginTag(HtmlTextWriterTag.Td); tw.Write(Title); tw.RenderEndTag(); tw.AddAttribute(HtmlTextWriterAttribute.Colspan, "2"); tw.RenderBeginTag(HtmlTextWriterTag.Td); //if (string.IsNullOrEmpty(TitleExportDate)) // tw.WriteLineNoTabs(string.Format(TitleExportDate, DateTime.Now.ToString("dd.MM.yyyy"))); tw.RenderEndTag(); // Create Header Row tw.RenderBeginTag(HtmlTextWriterTag.Tr); DataColumn col = null; for (Int32 i = 0; i <= dt.Columns.Count - 1; i++) { col = dt.Columns[i]; if (headerStyle != null) { headerStyle.AddAttributesToRender(tw); } tw.RenderBeginTag(HtmlTextWriterTag.Th); tw.RenderBeginTag(HtmlTextWriterTag.Strong); tw.WriteLineNoTabs(col.ColumnName); tw.RenderEndTag(); tw.RenderEndTag(); } tw.RenderEndTag(); // Create Data Rows foreach (DataRow row in dt.Rows) { tw.RenderBeginTag(HtmlTextWriterTag.Tr); for (Int32 i = 0; i <= dt.Columns.Count - 1; i++) { if (itemStyle != null) { itemStyle.AddAttributesToRender(tw); } tw.RenderBeginTag(HtmlTextWriterTag.Td); tw.WriteLineNoTabs(HttpUtility.HtmlEncode(row[i])); tw.RenderEndTag(); } tw.RenderEndTag(); // /tr } tw.RenderEndTag(); // /table // Write result to output-stream Stream outputStream = response.OutputStream; byte[] byteArray = Encoding.Default.GetBytes(sw.ToString()); response.OutputStream.Write(byteArray, 0, byteArray.GetLength(0)); }
public override void ExecuteResult(ControllerContext context) { // Create HtmlTextWriter StringWriter sw = new StringWriter(); HtmlTextWriter tw = new HtmlTextWriter(sw); // Build HTML Table from Items if (_tableStyle != null) { _tableStyle.AddAttributesToRender(tw); } tw.RenderBeginTag(HtmlTextWriterTag.Table); // Generate headers from table if (_headers == null) { _headers = _dataContext.Mapping.GetMetaType(_rows.ElementType).PersistentDataMembers.Select(m => m.Name).ToArray(); } // Create Header Row tw.RenderBeginTag(HtmlTextWriterTag.Thead); foreach (String header in _headers) { if (_headerStyle != null) { _headerStyle.AddAttributesToRender(tw); } tw.RenderBeginTag(HtmlTextWriterTag.Th); tw.Write(header); tw.RenderEndTag(); } tw.RenderEndTag(); // Create Data Rows tw.RenderBeginTag(HtmlTextWriterTag.Tbody); foreach (Object row in _rows) { tw.RenderBeginTag(HtmlTextWriterTag.Tr); foreach (string header in _headers) { string strValue = ""; if (row.GetType().GetProperty(header).GetValue(row, null) != null) { strValue = row.GetType().GetProperty(header).GetValue(row, null).ToString(); } strValue = ReplaceSpecialCharacters(strValue); if (_itemStyle != null) { _itemStyle.AddAttributesToRender(tw); } tw.RenderBeginTag(HtmlTextWriterTag.Td); tw.Write(HttpUtility.HtmlEncode(strValue)); tw.RenderEndTag(); } tw.RenderEndTag(); } tw.RenderEndTag(); // tbody tw.RenderEndTag(); // table WriteFile(_fileName, "application/ms-excel", sw.ToString()); }
public override void ExecuteResult(ControllerContext context = null) { // Create HtmlTextWriter var sw = new StringWriter(); var tw = new HtmlTextWriter(sw); // Build HTML Table from Items if (_TableStyle != null) { _TableStyle.AddAttributesToRender(tw); } tw.RenderBeginTag(HtmlTextWriterTag.Table); // Generate headers from table if (_Headers == null) { _Headers = _Rows.ElementType.GetProperties() .Select(p => p.Name).ToArray(); } // Create Header Row tw.RenderBeginTag(HtmlTextWriterTag.Thead); foreach (var header in _Headers) { if (_HeaderStyle != null) { _HeaderStyle.AddAttributesToRender(tw); } tw.RenderBeginTag(HtmlTextWriterTag.Th); tw.Write(header.SplitCamelCase()); tw.RenderEndTag(); } tw.RenderEndTag(); // Create Data Rows tw.RenderBeginTag(HtmlTextWriterTag.Tbody); foreach (var row in _Rows) { tw.RenderBeginTag(HtmlTextWriterTag.Tr); foreach (var header in _Headers) { object propertyValue = null; Type type = null; if (row.GetType().IsA <IDynamicMetaObjectProvider>()) { var dict = row as IDictionary <string, object>; if (dict != null) { propertyValue = dict[header]; type = propertyValue.GetType(); } } else { var property = row.GetType().GetProperty(header); type = property.ReflectedType; propertyValue = property.GetValue(row, null); } string strValue; if (type == typeof(DateTime) && propertyValue != null) { strValue = ((DateTime)propertyValue).ToShortDateString(); } else { strValue = ReplaceSpecialCharacters(propertyValue.AsSafeString()); } _ItemStyle.AddAttributesToRender(tw); tw.RenderBeginTag(HtmlTextWriterTag.Td); tw.Write(HttpUtility.HtmlEncode(strValue)); tw.RenderEndTag(); } tw.RenderEndTag(); } tw.RenderEndTag(); // tbody tw.RenderEndTag(); // table WriteFileAction(_FileName, "application/ms-excel", sw.ToString()); }
public override void ExecuteResult(ControllerContext context) { // Create HtmlTextWriter StringWriter sw = new StringWriter(); HtmlTextWriter tw = new HtmlTextWriter(sw); // Build HTML Table from Items if (_tableStyle != null) { _tableStyle.AddAttributesToRender(tw); } tw.RenderBeginTag(HtmlTextWriterTag.Table); for (int j = 0; j < _headers.Length; j++) { tw.RenderBeginTag(HtmlTextWriterTag.Tr); for (int i = 0; i < _headers[j].Length; i++) { if (_headerStyle != null) { _headerStyle.AddAttributesToRender(tw); } if (_headers.Length == 3 && j == 0) { int beginSpace = 3; int colSpan = _headers[1].Count(); if (_fileName == "LocalRetreatRegistrationTable.xls") { beginSpace = 5; colSpan = _headers[1].Count() * _headers[2].Count(); } if (i < beginSpace || i > beginSpace && beginSpace == 5) { tw.RenderBeginTag("th rowspan = 3"); } else { tw.RenderBeginTag("th colspan = " + colSpan.ToString()); } } else { tw.RenderBeginTag(HtmlTextWriterTag.Th); } string Header = ReplaceHeader(_headers[j][i]); tw.Write(Header); tw.RenderEndTag(); } tw.RenderEndTag(); } // Create Data Rows tw.RenderBeginTag(HtmlTextWriterTag.Tbody); int iRow = 0; foreach (Object row in _rows) { tw.RenderBeginTag(HtmlTextWriterTag.Tr); iRow++; string[] Header = _headers[0]; if (_headers.Length > 1 && !_fileName.StartsWith("LocalRetreatRegistrationTable")) { List <string> headerList = Header.ToList(); for (int i = 1; i < _headers[1].Length; i++) { headerList.Add(i.ToString()); } Header = headerList.ToArray(); } int iColumn = 0; foreach (string header in Header) { if (_itemStyle != null) { _itemStyle.AddAttributesToRender(tw); } if ((iRow % 2 == 0) && (_fileName.StartsWith("AttendanceTable") || _fileName.StartsWith("OrdinaryMemberInfo"))) { tw.AddStyleAttribute(HtmlTextWriterStyle.BackgroundColor, "#D8D8D8"); } tw.RenderBeginTag(HtmlTextWriterTag.Td); if (_fileName.StartsWith("LocalRetreatRegistrationTable")) { if (iColumn == 4) { tw.AddStyleAttribute(HtmlTextWriterStyle.TextAlign, "center"); } string item = ((List <string>)row)[iColumn]; if (!string.IsNullOrEmpty(item)) { string[] volunterJobs = item.Split('\n'); for (int vi = 0; vi < volunterJobs.Count(); vi++) { tw.Write(volunterJobs[vi]); if (vi < volunterJobs.Count()) { tw.WriteBreak(); } } } } else { WriteItem(tw, row, header); } iColumn++; tw.RenderEndTag(); } tw.RenderEndTag(); } tw.RenderEndTag(); // tbody tw.RenderEndTag(); // table WriteFile(_fileName, "application/ms-excel", sw.ToString()); }
public override void ExecuteResult(ControllerContext context) { // Create HtmlTextWriter StringWriter sw = new StringWriter(); HtmlTextWriter tw = new HtmlTextWriter(sw); // Create html tag tw.RenderBeginTag(HtmlTextWriterTag.Html); // Write head tag tw.Write("<head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" /></head>"); // Create body tag tw.RenderBeginTag(HtmlTextWriterTag.Body); // Build HTML Table from Items if (_tableStyle != null) { _tableStyle.AddAttributesToRender(tw); } // Create table tag tw.RenderBeginTag(HtmlTextWriterTag.Table); // Generate headers from table if (_headers == null) { foreach (Object row in _rows) { _headers = row.GetType().GetProperties().Select(m => m.Name).ToArray <string>(); break; } } // Create caption tag if (_title != null) { tw.RenderBeginTag(HtmlTextWriterTag.Caption); tw.Write(_title); tw.RenderEndTag(); } // Create Header Row tw.RenderBeginTag(HtmlTextWriterTag.Thead); foreach (String header in _headers) { if (_headerStyle != null) { _headerStyle.AddAttributesToRender(tw); } tw.RenderBeginTag(HtmlTextWriterTag.Th); //string encodeHeader = System.Web.HttpUtility.UrlEncode(header); tw.Write(header); tw.RenderEndTag(); } tw.RenderEndTag(); // Create Data Rows tw.RenderBeginTag(HtmlTextWriterTag.Tbody); foreach (Object row in _rows) { tw.RenderBeginTag(HtmlTextWriterTag.Tr); if (_properties != null) { if (_properties.Length == _headers.Length) { foreach (string prop in _properties) { var obj = row.GetType().GetProperty(prop).GetValue(row, null); string strValue = obj != null?obj.ToString() : null; //strValue = ReplaceSpecialCharacters(strValue); if (_itemStyle != null) { _itemStyle.AddAttributesToRender(tw); } tw.RenderBeginTag(HtmlTextWriterTag.Td); tw.Write(HttpUtility.HtmlEncode(strValue) + " "); tw.RenderEndTag(); } } } else { if (row.GetType().GetProperties().Count() == _headers.Length) { foreach (var prop in row.GetType().GetProperties()) { string strValue = prop.GetValue(row, null).ToString(); //strValue = ReplaceSpecialCharacters(strValue); if (_itemStyle != null) { _itemStyle.AddAttributesToRender(tw); } tw.RenderBeginTag(HtmlTextWriterTag.Td); tw.Write(HttpUtility.HtmlEncode(strValue) + " "); tw.RenderEndTag(); } } } tw.RenderEndTag(); } tw.RenderEndTag(); // tbody tw.RenderEndTag(); // table tw.RenderEndTag(); // body tw.RenderEndTag(); // html WriteFile(_fileName, "application/ms-excel", sw.ToString()); }