我的html表在mircosoft office outlook 2007中显示不正确 [英] My html table is not display correct in mircosoft office outlook 2007

查看:79
本文介绍了我的html表在mircosoft office outlook 2007中显示不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI,



我创建了一个窗口应用程序,用于向我们的用户发送电子邮件。我在我的程序中创建了一个html表,并通过电子邮件发送。





我的html表格电子邮件在浏览器中正确显示但在Microsoft办公室outlook 2007显示完全可怕。



请参阅图片附件。



1.显示HTml表格这在Microsoft Office Outlook 2007中

图像 [ ^ ]



2.显示网页上的html表格看起来不错。

图片 [ ^ ]

调用这两个函数



I am created a window app for sending email to our user. I have created a html table in my program aand sending via email .


My html table email display correctly in browser but in Microsoft office outlook 2007 is display completely horrible.

Please see image attachment.

1. Display HTml table like this in Microsoft office outlook 2007
image[^]

2. Display html table in web looking good.
image[^]
Calling Both function

sb.Append(_clsManageConnection.CreateTableHeader(_ds, 1, 3, "", SkipColumn, false, false, inLineStyle, false, true, countHeader-1, tbodyStyle, true, blankHeaderText, true,SkipColumn.Length-1));

                        
sb.Append(_clsManageConnection.BindDataIntoTable(_ds, "", SkipColumn, false, false, false, 0,false, 0, false, countHeader - 1, true, "", _htRowChange, "NodeType", RowMargeColumn,true,1));









创建标题的代码





Code for creating header

public string CreateTableHeader(DataSet _dtRecord, int databaseIndex, int totalHeader, string CheckColumn, string[] SkipColumn, bool isSerialNo, bool isBlankColumn, string inlineStyle, bool _isColumnRemove, bool _isHeaderBlank, int _headerBlankLength, string tbodyStyle, bool IsBlankHeaderNotRowSpan, string BlankHeaderText, bool IsPrintTextInBlank, int SubStractMargingHeaderRowCount)
       {
           if (databaseIndex > 1)
           {
               for (int i = 1; i < databaseIndex; i++)
               {
                   _dtRecord.Tables.RemoveAt(0);
                   _dtRecord.AcceptChanges();
               }
           }
           StringBuilder sbHeader = new StringBuilder();
           bool isMultiLastColumn = false;
           sbHeader.Append("<table width='1024px' border='1' id='excelTable" + databaseIndex + "' cellspacing='0' style='" + inlineStyle + "'>");
           sbHeader.Append("<thead style='" + tbodyStyle + "font-family:verdana;font-size:8pt;'>");
           ArrayList _arrColumnAddedList = new ArrayList();
           bool _isSerialNumber = isSerialNo;
           for (int _totalHeader = 0; _totalHeader < totalHeader; _totalHeader++)
           {
               string _serialNamePrint = string.Empty;
               bool isSerialNamePrint = false;
               if (_totalHeader == (totalHeader - 1) && _isSerialNumber)
               {
                   _serialNamePrint = "No";
                   isSerialNamePrint = true;
               }
               if (isMultiLastColumn)
                   isMultiLastColumn = false;
               if (_dtRecord.Tables[0].Columns.Count > 0)
               {
                   sbHeader.Append("<tr style='" + tbodyStyle + "font-family:verdana;font-size:8pt;'>");
                   string previousCol = string.Empty;
                   int _totalCol = 0;
                   bool _isFirstRow = true, _isBlankColumn = isBlankColumn, _isSerialNo = isSerialNo;
                   string fontWeightStyle = string.Empty;
                   for (int headerCount = (_isSerialNo == true ? -1 : 0); headerCount < _dtRecord.Tables[0].Columns.Count; headerCount++)
                   {
                       if (_isSerialNo)
                       {
                           if (_totalHeader == (totalHeader - 1) && isSerialNamePrint == true && _isSerialNumber)
                           {
                               sbHeader.Append("<th style='background-color:#002060;color:white;font-family:verdana;font-size:8pt;'>" + _serialNamePrint + "</th>");
                               isSerialNamePrint = false;
                           }
                           else
                               sbHeader.Append("<th style='background-color:#002060;color:white;font-family:verdana;font-size:8pt;'></th>");
                           _isSerialNo = false;
                           continue;
                       }
                       if (_isBlankColumn == true && !SkipColumn.Contains(_dtRecord.Tables[0].Columns[headerCount].ColumnName.ToString().Trim()))
                       {
                           if (_totalHeader == (totalHeader - 1) && _isBlankColumn && !_arrColumnAddedList.Contains(_dtRecord.Tables[0].Columns[headerCount].ColumnName))
                           {
                               sbHeader.Append("<th style='background-color:#002060;color:white;font-family:verdana;font-size:8pt;'>" + _dtRecord.Tables[0].Columns[headerCount].ColumnName.ToString().Trim() + "</th>");
                               _arrColumnAddedList.Add(_dtRecord.Tables[0].Columns[headerCount].ColumnName);
                           }
                           else
                               sbHeader.Append("<th style='background-color:#002060;color:white;font-family:verdana;font-size:8pt;'></th>");
                           continue;
                       }
                       if (_dtRecord.Tables[0].Columns[headerCount].ColumnName.ToString().Trim() == CheckColumn)
                           _isBlankColumn = false;
                       if (_isHeaderBlank && headerCount < _headerBlankLength)
                       {

                           if (!SkipColumn.Contains(_dtRecord.Tables[0].Columns[headerCount].ColumnName.ToString().Trim()))
                           {
                               if (BlankHeaderText != string.Empty && headerCount == _headerBlankLength - 1)
                               {
                                   sbHeader.Append("<th colspan='" + (_headerBlankLength - SubStractMargingHeaderRowCount) + "' style='font-size:8pt;background-color:#002060;color:white;font-family:verdana;text-align;left;'>" + BlankHeaderText + "</th>");
                                   BlankHeaderText = string.Empty;
                               }
                               else if (IsPrintTextInBlank && BlankHeaderText == string.Empty)
                               {
                                   if (!_arrColumnAddedList.Contains(_dtRecord.Tables[0].Columns[headerCount].ColumnName))
                                       sbHeader.Append("<th style='font-size:8pt;background-color:#002060;color:white;font-weight:normal;font-family:verdana;'>" + _dtRecord.Tables[0].Columns[headerCount].ColumnName.ToString().Trim() + "</th>");
                                   else
                                       sbHeader.Append("<th style='font-size:8pt;background-color:#002060;color:white;font-weight:normal;font-family:verdana;'></th>");
                                   _arrColumnAddedList.Add(_dtRecord.Tables[0].Columns[headerCount].ColumnName);
                               }
                               else if (BlankHeaderText == string.Empty && !IsPrintTextInBlank)
                                   sbHeader.Append("<th style='font-size:8pt;background-color:#002060;color:white;font-family:verdana;'></th>");
                           }
                           continue;
                       }
                       if (_isColumnRemove == true && SkipColumn.Contains(_dtRecord.Tables[0].Columns[headerCount].ColumnName.ToString().Trim()))
                           continue;
                       if (!_dtRecord.Tables[0].Columns[headerCount].ColumnName.Contains("^") && _isBlankColumn == false && !SkipColumn.Contains(_dtRecord.Tables[0].Columns[headerCount].ColumnName.ToString().Trim()))
                       {
                           if (isMultiLastColumn)
                           {
                               sbHeader.Append("<th colspan='" + _totalCol + "' style='font-size:8pt;background-color:#2E75B6;color:white;font-family:verdana;text-align:left;'>" + previousCol + "</th>");
                               isMultiLastColumn = false;
                               _totalCol = 0;
                               previousCol = string.Empty;
                               _isFirstRow = true;
                           }
                           if (totalHeader > 1)
                           {
                               if (_dtRecord.Tables[0].Columns[headerCount].ColumnName.ToString().Trim() != CheckColumn && !_arrColumnAddedList.Contains(_dtRecord.Tables[0].Columns[headerCount].ColumnName))
                               {
                                   sbHeader.Append("<th rowspan='" + totalHeader + "' style='font-size:8pt;background-color:#2E75B6;color:white;font-family:verdana;text-align:left;'>" + _dtRecord.Tables[0].Columns[headerCount].ColumnName + "</th>");
                                   _arrColumnAddedList.Add(_dtRecord.Tables[0].Columns[headerCount].ColumnName);
                               }
                           }
                           else if (_dtRecord.Tables[0].Columns[headerCount].ColumnName.ToString().Trim() != CheckColumn)
                               sbHeader.Append("<th style='font-size:8pt;background-color:#2E75B6;color:white;font-weight:normal;font-family:verdana;text-align:left;'>" + _dtRecord.Tables[0].Columns[headerCount].ColumnName + "</th>");
                       }
                       fontWeightStyle = string.Empty;
                       if (_dtRecord.Tables[0].Columns[headerCount].ColumnName.Contains("^"))
                       {
                           if (_totalHeader >=1)
                           {
                               fontWeightStyle = "font-weight:normal;";
                           }
                           char[] _char = new char[1];
                           _char[0] = '^';
                           string[] columns = _dtRecord.Tables[0].Columns[headerCount].ColumnName.Split(_char);
                           if (previousCol == (columns[_totalHeader] == "" ? columns[0] : columns[_totalHeader]))
                           {
                               _totalCol++;
                           }
                           else
                           {
                               if (!_isFirstRow)
                               {
                                   sbHeader.Append("<th colspan='" + _totalCol + "' style='font-size:8pt;font-family:verdana;background-color:#2E75B6;color:white;" + fontWeightStyle + "'>" + (columns[_totalHeader] == "" ? columns[_totalHeader]: _dtRecord.Tables[0].Columns[headerCount-1].ColumnName.Split(_char)[_totalHeader]==""?"":previousCol)  + "</th>");
                               }
                               _totalCol = 0;
                               previousCol = string.Empty;
                           }
                           if (previousCol == string.Empty)
                           {
                               previousCol = (columns[_totalHeader]==""?columns[0]:columns[_totalHeader]);
                               _totalCol++;
                           }
                           _isFirstRow = false;
                           isMultiLastColumn = true;
                       }
                   }
                   if (isMultiLastColumn)
                   {
                       if (_totalHeader >=1)
                       {
                           fontWeightStyle = "font-weight:normal;";
                       }
                       sbHeader.Append("<th colspan='" + _totalCol + "' style='font-size:8pt;font-family:verdana;background-color:#2E75B6;color:white;" + fontWeightStyle + "'>" + previousCol + "</th>");
                       isMultiLastColumn = false;
                       _totalCol = 0;
                       previousCol = string.Empty;
                       _isFirstRow = true;
                   }
                   sbHeader.Append("</tr>");
               }
               //Reset Value Again
               if (_totalHeader == totalHeader)
               {
                   isBlankColumn = false;
               }
           }
           sbHeader.Append("</thead>");
           return sbHeader.ToString();
       }





创建html表格的代码





Code for creating body of html table

public string BindDataIntoTable(DataSet _dtRecord, string CheckColumn, string[] SkipColumn, bool isSerialNo, bool isBlankColumn, bool isGrouping, int totalGroupTable, bool isLastColumnHighlight, int totalLastColumnHighLight, bool isDisplayPercentage, int blankHeaderColumn, bool IsRowCellsMarge, string rowGroupingColumnName, Hashtable _htRowChange, string RowChangeColumnName, string[] rowGroupingColumnNameList, bool IsRowhighligth, int totalRowHighLight)
        {

            StringBuilder sbBody = new StringBuilder();
            int _rowCount = 0, groupRowCount = 0, _totalCol = 0, _totalRow = 0, _rowCountForMarge = 0;
            string rowGroupName = string.Empty, previousCol = string.Empty, previousRow = string.Empty;
            bool _isFirstRow = true, isGroupRow = false, _isRowMarge = false, isNextRow = false;
            ArrayList _arrSkipColumnList = new ArrayList();
            int rowGroupCount = 0;
            if (_dtRecord.Tables[0].Rows.Count > 0)
            {
                sbBody.Append("<tbody style='font-size:7pt;border:1px solid #0242A1;font-family:verdana;border-collapse: collapse;border-spacing: 0px;text-align:center;font-weight:normal;padding:3pt;'>");
                for (int j = 0; j < _dtRecord.Tables[0].Rows.Count; j++)
                {
                    _rowCount++;
                    if (!isGrouping)
                    {

                        if (isLastColumnHighlight && _rowCount > _dtRecord.Tables[0].Rows.Count - totalLastColumnHighLight)
                            sbBody.Append("<tr style='background-color:#2E75B6;color:white !important;font-weight:bold;font-family:verdana;'>");
                        else if (IsRowhighligth && _rowCount <= totalRowHighLight)
                            sbBody.Append("<tr style='background-color:#2E75B6;color:white !important;font-weight:bold;font-family:verdana;'>");
                        else if (_dtRecord.Tables[0].Rows[j][RowChangeColumnName].ToString() == "10" && _dtRecord.Tables[0].Rows[j]["FlgToHide"].ToString() != "1")
                            sbBody.Append("<tr style='background-color:#DFECF7;color:black !important;font-weight:normal;font-family:verdana;'>");
                        else if (_dtRecord.Tables[0].Rows[j][RowChangeColumnName].ToString() == "6")
                            sbBody.Append("<tr style='background-color:#ACCCEA;color:black !important;font-weight:normal;font-family:verdana;'>");
                        else if (_dtRecord.Tables[0].Rows[j][RowChangeColumnName].ToString() == "10" && _dtRecord.Tables[0].Rows[j]["FlgToHide"].ToString() == "1")
                        {
                            //sbBody.Append("<tr height='1' style='background-color:#D0D3D5;font-size:1px; mso-line-height-alt:0; mso-margin-top-alt:1px; color:black !important;font-weight:normal;font-family:verdana;'>");
                            //sbBody.Append("<td height='1' style='font-size: 1px; line-height: 1px;mso-line-height-rule:exactly;' colspan='" + (_dtRecord.Tables[0].Columns.Count - (SkipColumn.Length + 1)) + "'></td></tr>");
                            continue;
                        }
                        else
                            sbBody.Append("<tr>");
                        int rowSkip = 0, rowSkipCount = 0;
                        bool IsFirst = true;
                        bool isNextSpan = false;
                        int skipColumn = 0;
                        string textAlign = string.Empty;
                        for (int i = (isSerialNo == true ? -1 : 0); i < _dtRecord.Tables[0].Columns.Count; i++)
                        {
                            if (i < blankHeaderColumn)
                            {
                                textAlign = "text-align:left;";
                            }
                            else
                                textAlign = "text-align:right;padding-right:5px;";
                            if (isSerialNo)
                            {
                                sbBody.Append("<td nowrap>" + _rowCount + "</td>");
                                isSerialNo = false;
                                continue;
                            }
                            if (!SkipColumn.Contains(_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim()))
                            {
                                if (_arrSkipColumnList.Contains(_dtRecord.Tables[0].Rows[j][i].ToString().Trim()) && skipColumn < rowGroupingColumnNameList.Length && isNextRow)
                                {
                                    //rowGroupCount++;
                                    if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == rowGroupingColumnNameList[0])
                                        rowGroupCount++;
                                    skipColumn++;
                                    continue;
                                }
                                else
                                    isNextRow = false;

                                if (IsRowCellsMarge && previousRow == string.Empty && rowGroupingColumnNameList.Contains(_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim()))
                                {
                                    previousRow = _dtRecord.Tables[0].Rows[j][rowGroupingColumnNameList[rowGroupCount]].ToString().Trim();

                                    if (rowGroupCount == 0)
                                        _totalRow = _dtRecord.Tables[0].Select("[" + rowGroupingColumnNameList[rowGroupCount] + "]='" + previousRow + "'").Count();
                                    else if (rowGroupingColumnNameList.Length > 1)
                                    {
                                        string colFilter = string.Empty;
                                        for (int col = 0; col <= rowGroupCount; col++)
                                        {
                                            colFilter += "[" + rowGroupingColumnNameList[col] + "]='" + _dtRecord.Tables[0].Rows[j][rowGroupingColumnNameList[col]].ToString().Trim() + "' and ";
                                        }
                                        _totalRow = _dtRecord.Tables[0].Select(colFilter.Substring(0, colFilter.Length - 5)).Count();
                                    }
                                    _isRowMarge = true;

                                }
                                if (IsRowhighligth && _rowCount <= totalRowHighLight)
                                {
                                    rowSkip = int.Parse(_htRowChange[_dtRecord.Tables[0].Rows[j][RowChangeColumnName].ToString()].ToString());
                                    if (rowSkip > 0 && rowSkipCount <= rowSkip)
                                    {
                                        rowSkipCount++;
                                        if (IsFirst)
                                        {
                                            sbBody.Append("<td style='color:white;" + textAlign + "' class='td'  colspan='" + (rowSkip + 1) + "'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Contains("%") && _dtRecord.Tables[0].Rows[j][i].ToString().Trim() != string.Empty && isDisplayPercentage == true ? " %" : "") + "</td>");
                                            IsFirst = false;
                                        }
                                        else
                                            continue;
                                    }
                                    else
                                        sbBody.Append("<td style='color:white;" + textAlign + "' class='td'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Contains("%") && _dtRecord.Tables[0].Rows[j][i].ToString().Trim() != string.Empty && isDisplayPercentage == true ? " %" : "") + "</td>");
                                }
                                else if (isLastColumnHighlight && _rowCount > _dtRecord.Tables[0].Rows.Count - totalLastColumnHighLight)
                                {
                                    try
                                    {
                                        rowSkip = int.Parse(_htRowChange[_dtRecord.Tables[0].Rows[j][RowChangeColumnName].ToString()].ToString());
                                    }
                                    catch (Exception exrow)
                                    { }
                                    if (rowSkip > 0 && rowSkipCount <= rowSkip)
                                    {
                                        rowSkipCount++;
                                        if (IsFirst)
                                        {
                                            sbBody.Append("<td nowrap style='color:white;" + textAlign + "' class='td'  colspan='" + (rowSkip + 1) + "'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Contains("%") && _dtRecord.Tables[0].Rows[j][i].ToString().Trim() != string.Empty && isDisplayPercentage == true ? " %" : "") + "</td>");
                                            IsFirst = false;
                                        }
                                        else
                                            continue;
                                    }
                                    else
                                        sbBody.Append("<td nowrap style='color:white;" + textAlign + "' class='td'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Contains("%") && _dtRecord.Tables[0].Rows[j][i].ToString().Trim() != string.Empty && isDisplayPercentage == true ? " %" : "") + "</td>");
                                }
                                else
                                {
                                    try
                                    {
                                        rowSkip = int.Parse(_htRowChange[_dtRecord.Tables[0].Rows[j][RowChangeColumnName].ToString()].ToString());
                                    }
                                    catch (Exception exRow)
                                    {

                                    }
                                    if (rowSkip > 0 && rowSkipCount <= rowSkip)
                                    {
                                        rowSkipCount++;
                                        if (IsFirst)
                                        {
                                            if (_dtRecord.Tables[0].Rows[j][RowChangeColumnName].ToString() == "10")
                                            {
                                                sbBody.Append("<td  colspan='" + (rowSkip + 1) + "' nowrap style='" + textAlign + "'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Contains("%") && _dtRecord.Tables[0].Rows[j][i].ToString().Trim() != string.Empty && isDisplayPercentage == true ? " %" : "") + "</td>");
                                                isNextSpan = true;

                                            }
                                            else
                                                sbBody.Append("<td  colspan='" + (rowSkip + 1) + "' nowrap style='" + textAlign + "'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Contains("%") && _dtRecord.Tables[0].Rows[j][i].ToString().Trim() != string.Empty && isDisplayPercentage == true ? " %" : "") + "</td>");

                                            IsFirst = false;
                                        }
                                        //else if (isNextSpan)
                                        //{
                                        //    sbBody.Append("<td  colspan='" + (rowSkip + 1) + "' nowrap>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Contains("%") && _dtRecord.Tables[0].Rows[j][i].ToString().Trim() != string.Empty && isDisplayPercentage == true ? " %" : "") + "</td>");
                                        //    isNextSpan = false;
                                        //}
                                        else
                                            continue;
                                    }
                                    else
                                    {
                                        if (IsRowCellsMarge && _isRowMarge)
                                        {
                                            if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == rowGroupingColumnNameList[rowGroupCount])
                                            {
                                                sbBody.Append("<td rowspan='" + _totalRow + "' align='center' valign='middle' style='vertical-align: middle;" + textAlign + "'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "</td>");
                                                _isRowMarge = false;
                                                previousRow = string.Empty;
                                                if (rowGroupCount == 0)
                                                    _arrSkipColumnList.Clear();

                                                _arrSkipColumnList.Add(_dtRecord.Tables[0].Rows[j][i].ToString().Trim());
                                                if (rowGroupCount + 1 != rowGroupingColumnNameList.Length)
                                                    rowGroupCount++;

                                            }
                                            else
                                                sbBody.Append("<td  align='center' style='" + textAlign + "'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "</td>");
                                        }
                                        else
                                        {
                                            if (!_isRowMarge && IsRowCellsMarge && _dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == rowGroupingColumnNameList[rowGroupCount])
                                                continue;
                                            else
                                            {
                                                if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == "Route" && _dtRecord.Tables[0].Rows[j]["flgOnRoute"].ToString().Trim() == "0")
                                                    sbBody.Append("<td nowrap style='font-family:verdana;" + textAlign + "'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "<span style='color:red;font-size:7px;'>*</span></td>");
                                                else
                                                    sbBody.Append("<td  nowrap style='font-family:verdana;" + textAlign + "'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "</td>");
                                            }
                                        }

                                    }
                                }
                            }
                        }
                        sbBody.Append("</tr>");
                        {
                            previousRow = string.Empty;
                            _rowCountForMarge = 0;
                            _totalRow = 0;
                            isNextRow = true;
                            rowGroupCount = 0;
                        }
                    }

                    if (isGrouping)
                    {
                        if (previousCol == _dtRecord.Tables[0].Rows[j][CheckColumn].ToString())
                            _totalCol++;
                        else
                        {
                            if (!_isFirstRow)
                            {
                                isGroupRow = true;
                                rowGroupName = previousCol;
                            }
                            _totalCol = 0;
                            previousCol = string.Empty;
                        }
                        if (previousCol == string.Empty)
                        {
                            previousCol = _dtRecord.Tables[0].Rows[j][CheckColumn].ToString();
                            _totalCol++;
                        }
                        _isFirstRow = false;
                        if (IsRowCellsMarge && previousRow == string.Empty)
                        {
                            previousRow = _dtRecord.Tables[0].Rows[j][rowGroupingColumnName].ToString().Trim();
                            _totalRow = _dtRecord.Tables[0].Select("" + rowGroupingColumnName + "='" + previousRow + "'").Count();
                            _isRowMarge = true;
                        }
                        //_rowCountForMarge++;
                        _rowCountForMarge++;
                        if (!isGroupRow)
                        {
                            sbBody.Append("<tr style='font-family:verdana;'>");
                            bool _isSerialNo = isSerialNo;
                            string textAlign = string.Empty;
                            for (int i = (_isSerialNo == true ? -1 : 0); i < _dtRecord.Tables[0].Columns.Count; i++)
                            {
                                if (i < 9)
                                    textAlign = "text-align:left;";
                                else
                                    textAlign = "text-align:right;padding-right:5px;";
                                if (_isSerialNo)
                                {
                                    sbBody.Append("<td nowrap>" + _rowCount + "</td>");
                                    _isSerialNo = false;
                                    continue;
                                }
                                if (!SkipColumn.Contains(_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim()))
                                {
                                    if (IsRowCellsMarge && _isRowMarge)
                                    {
                                        if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == rowGroupingColumnName)
                                        {
                                            sbBody.Append("<td rowspan='" + _totalRow + "' align='center' valign='middle' style='font-family:verdana;vertical-align: middle;text-align:left;'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "</td>");
                                            _isRowMarge = false;
                                        }
                                        else
                                            sbBody.Append("<td style='text-align:left;'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "</td>");
                                    }
                                    else
                                    {
                                        if (!_isRowMarge && IsRowCellsMarge && _dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == rowGroupingColumnName)
                                            continue;
                                        else
                                        {
                                            if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == "Route" && _dtRecord.Tables[0].Rows[j]["flgOnRoute"].ToString().Trim() == "0")
                                                sbBody.Append("<td nowrap style='font-family:verdana;" + textAlign + "'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "<span style='color:red;font-size:7px;'>*</span></td>");
                                            else
                                                sbBody.Append("<td nowrap style='font-family:verdana;" + textAlign + "'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "</td>");
                                        }
                                    }
                                }
                            }
                            sbBody.Append("</tr>");
                            if (_totalRow == _rowCountForMarge)
                            {
                                previousRow = string.Empty;
                                _rowCountForMarge = 0;
                                _totalRow = 0;
                            }
                        }
                        if (isGroupRow)
                        {
                            sbBody.Append("<tr style='background-color:#A6BDE1;color:black;font-weight:bold;font-family:verdana;'>");
                            DataRow[] drw = _dtRecord.Tables[1].Select("" + CheckColumn + "='" + rowGroupName + "'");
                            bool isMarge = false;
                            bool _isSerialNo = isSerialNo;
                            for (int i = (_isSerialNo == true ? -1 : 0); i < drw[0].ItemArray.Length; i++)
                            {
                                if (_isSerialNo)
                                {
                                    sbBody.Append("<td nowrap></td>");
                                    _isSerialNo = false;
                                    continue;
                                }
                                if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() != CheckColumn && isMarge == false)
                                    groupRowCount++;
                                //else if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == CheckColumn)
                                //{
                                //    sbBody.Append("<td nowrap colspan='" + (groupRowCount != 0 ? groupRowCount : (blankHeaderColumn - 2)) + "'  style='color:black !important;font-family:verdana;'> Total : " + rowGroupName + "</td>");
                                //    isMarge = true;
                                //    groupRowCount = 0;
                                //}
                                else if (i > blankHeaderColumn)
                                    sbBody.Append("<td nowrap  style='color:black !important;font-family:verdana;text-align:right;padding-removed5px;'>" + drw[0][i].ToString().Trim() + "</td>");
                            }
                            sbBody.Append("</tr>");
                            sbBody.Append("<tr style='font-family:verdana;'>");
                            _isSerialNo = isSerialNo;
                            string textAlign = string.Empty;
                            for (int i = (_isSerialNo == true ? -1 : 0); i < _dtRecord.Tables[0].Columns.Count; i++)
                            {
                                if (i < 9)
                                    textAlign = "text-align:left;";
                                else
                                    textAlign = "text-align:right;padding-right:5px;";
                                if (_isSerialNo)
                                {
                                    sbBody.Append("<td nowrap>" + _rowCount + "</td>");
                                    _isSerialNo = false;
                                    continue;
                                }
                                //if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() != CheckColumn)
                                //    sbBody.Append("<td nowrap>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "</td>");
                                if (!SkipColumn.Contains(_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim()))
                                {
                                    //if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == "Route" && _dtRecord.Tables[0].Rows[j]["flgOnRoute"].ToString().Trim() == "0")
                                    //    sbBody.Append("<td nowrap>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "<span style='color:red;font-size:7px;font-family:verdana;'>*</span></td>");
                                    //else
                                    //    sbBody.Append("<td nowrap style='font-family:verdana;'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "</td>");
                                    if (IsRowCellsMarge && _isRowMarge)
                                    {
                                        if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == rowGroupingColumnName)
                                        {
                                            sbBody.Append("<td rowspan='" + _totalRow + "' align='center' valign='middle' style='font-family:verdana;vertical-align: middle;text-align:left;'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "</td>");
                                            _isRowMarge = false;
                                        }
                                        else
                                            sbBody.Append("<td style='font-family:verdana;text-align:left;'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "</td>");
                                    }
                                    else
                                    {
                                        if (!_isRowMarge && IsRowCellsMarge && _dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == rowGroupingColumnName)
                                            continue;
                                        else
                                        {
                                            if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == "Route" && _dtRecord.Tables[0].Rows[j]["flgOnRoute"].ToString().Trim() == "0")
                                                sbBody.Append("<td nowrap style='font-family:verdana;" + textAlign + "'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "<span style='color:red;font-size:7px;'>*</span></td>");
                                            else
                                                sbBody.Append("<td nowrap style='font-family:verdana;" + textAlign + "'>" + _dtRecord.Tables[0].Rows[j][i].ToString().Trim() + "</td>");
                                        }
                                    }
                                };
                            }
                            isGroupRow = false;
                            sbBody.Append("</tr>");
                            if (_totalRow == _rowCountForMarge)
                            {
                                previousRow = string.Empty;
                                _rowCountForMarge = 0;
                                _totalRow = 0;
                            }
                        }
                    }
                }

                if (isGrouping)
                {
                    if (_rowCount == _dtRecord.Tables[0].Rows.Count)
                    {
                        bool _isSerialNo = isSerialNo;
                        sbBody.Append("<tr style='background-color:#A6BDE1;color:black;font-weight:bold;font-family:verdana;'>");
                        DataRow[] drw = _dtRecord.Tables[1].Select("" + CheckColumn + "='" + previousCol + "'");
                        bool isMarge = false;
                        for (int i = (_isSerialNo == true ? -1 : 0); i < drw[0].ItemArray.Length; i++)
                        {
                            if (_isSerialNo)
                            {
                                sbBody.Append("<td nowrap></td>");
                                _isSerialNo = false;
                                continue;
                            }
                            if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() != CheckColumn && isMarge == false)
                                groupRowCount++;
                            //else if (_dtRecord.Tables[0].Columns[i].ColumnName.ToString().Trim() == CheckColumn)
                            //{
                            //    sbBody.Append("<td nowrap colspan='" + (groupRowCount != 0 ? groupRowCount : (blankHeaderColumn - 2)) + "' style='color:black !important;font-family:verdana;'>Total : " + previousCol + "</td>");
                            //    //sb.Append("<td style='color:white !important;'>" + drw[0][i].ToString().Trim() + "</td>");
                            //    isMarge = true;
                            //    groupRowCount = 0;
                            //}
                            else if (i > blankHeaderColumn)
                                sbBody.Append("<td nowrap style='color:black !important;font-family:verdana;text-align:right;padding-removed5px;'>" + drw[0][i].ToString().Trim() + "</td>");
                        }
                        sbBody.Append("</tr>");
                        isGroupRow = false;
                    }

                    // Last Table Grouping
                    if (_dtRecord.Tables[2].Rows.Count > 0)
                    {
                        sbBody.Append("<tr style='background-color:#507EC5;color:white;font-weight:bold;font-family:verdana;'>");
                        bool isMarge = false;
                        bool _isSerialNo = isSerialNo;
                        for (int i = (_isSerialNo == true ? -1 : 0); i < _dtRecord.Tables[2].Columns.Count; i++)
                        {
                            if (_isSerialNo)
                            {
                                groupRowCount++;
                                _isSerialNo = false;
                                continue;
                            }
                            if (_dtRecord.Tables[2].Columns[i].ColumnName.ToString().Trim() != CheckColumn && isMarge == false)
                                groupRowCount++;
                            else if (_dtRecord.Tables[2].Columns[i].ColumnName.ToString().Trim() == CheckColumn)
                            {
                                sbBody.Append("<td nowrap colspan='" + (groupRowCount != 0 ? groupRowCount : (blankHeaderColumn - 2)) + "' align='right' style='color:white; text-align:center;font-family:verdana;'>" + "Grand Total" + "</td>");
                                isMarge = true;
                                groupRowCount = 0;
                            }
                            else if (i > blankHeaderColumn)
                                sbBody.Append("<td nowrap style='color:white;font-family:verdana;text-align:right;padding-removed5px;'>" + _dtRecord.Tables[2].Rows[0][i].ToString().Trim() + "</td>");
                        }
                        sbBody.Append("</tr>");
                    }
                }
                sbBody.Append("</tbody>");
                sbBody.Append("</table>");
            }
            return sbBody.ToString();
        }





Please help me and provide a better solutions.



Thanks



What I have tried:



I am try to display actual html table in microsoft office outlook 2007. Please review also my code which is mention above.



Please help me and provide a better solutions.

Thanks

What I have tried:

I am try to display actual html table in microsoft office outlook 2007. Please review also my code which is mention above.

推荐答案

Can you post an example of the HTML table that your program produces?
Can you post an example of the HTML table that your program produces?


这篇关于我的html表在mircosoft office outlook 2007中显示不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆