日期列也正在合并 [英] Date column is also getting merged

查看:77
本文介绍了日期列也正在合并的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我只是开发中的首发。实际上,我正在开发一个生产时间的应用程序。众所周知,在一天之内我们会从事不同的项目。在那,我试图在excel表中的一些员工的日期之间获取数据。员工的一些基本细节在每一行都会重复出现。所以我把代码编写为



 public string ConvertDataTableToHTMLTable()
{
StringBuilder sbuilder = new StringBuilder( );

sbuilder.Append(< html>< title>< / title>< head>< / head>< body>);
sbuilder.Append();
sbuilder.Append(< table border = 1>< tr>);

for(int i = 0; i< dt.Columns.Count; i ++)
{
sbuilder.Append(< td> + dt .Columns [i] .ColumnName +< / td>);
}

sbuilder.Append(< / tr>);

string strToken = string.Empty;
string strDate = string.Empty;

foreach(DataRow drRow in dt.Select(,TokenNo asc))
{
sbuilder.Append(< tr>);
if(strToken!= drRow [TokenNo]。ToString())
{
strToken = drRow [TokenNo]。ToString();
strDate = drRow [Date]。ToString();
DataRow [] drRows = dt.Select(TokenNo ='+ strToken +');
int len = drRows.Length;
DataRow [] drRows1 = dt.Select(Date ='+ strDate +');
int len1 = drRows1.Length;
sbuilder.Append(< td rowspan ='+ len +'>);
sbuilder.Append(drRow [Name]。ToString()+< / td>);
sbuilder.Append(< td rowspan ='+ len +'>);
sbuilder.Append(drRow [TokenNo]。ToString()+< / td>);
sbuilder.Append(< td rowspan ='+ len +'>);
sbuilder.Append(drRow [TeamLeader]。ToString()+< / td>);
sbuilder.Append(< td rowspan ='+ len +'>);
sbuilder.Append(drRow [Date]。ToString()+< / td>);
sbuilder.Append(< td rowspan ='+ len +'>);
sbuilder.Append(drRow [Shift]。ToString()+< / td>);
}
sbuilder.Append(< td>+ drRow [FabricationType]。ToString()+< / td>);
sbuilder.Append(< td>+ drRow [Stage]。ToString()+< / td>);

sbuilder.Append(< / tr>);
}

sbuilder.Append(< / table>);
//sbuilder.Append(\"<p> Thanks& Regards,< p>);
//sbuilder.Append(\"<p>+ uname1 +< / p>);
sbuilder.Append(< / body>< / html>);
返回sbuilder.ToString();

}





在这个日期合并,它只显示一个日期,但没有不同约会。



问候,

Avinash G.

解决方案

这是发生的原因是您只添加了单个令牌值。因此,当迭代具有相同令牌的行时,它不会为您的日期值添加td



< pre> 
if(strToken!= drRow [TokenNo]。ToString())//此行不允许具有相同令牌的行包含在您的表中
{
strToken = drRow [ TokenNo]的ToString();
strDate = drRow [Date]。ToString();
.......
}







如果你想要连接相同令牌的所有日期迭代具有相同令牌的行并创建一个包含所有日期的字符串。


是的,我只需要它。因为每条线都会重复这种常见数据。所以我只显示一次公共数据。正常显示Remaing。



但实际上我需要的是日期列不应该合并。



例如:

如果我生成2天或更多天的报告,则日期列仅显示第一个日期。 />


所以现在我需要检查令牌号和日期。如果令牌号相同,它应该只显示一次,并且与日期相同。



你能指导我在这里做什么。

Hi,

I'm just a starter in development. Actually, i'm developing an application for the productive hours. As everyone knows that, in a day we work on different projects. In that,i am trying to fetch the data between dates for some of the employees in excel sheet. Some basic details of the employee is getting repeated in each and every line. So i've written the code as

public string ConvertDataTableToHTMLTable()
        {
            StringBuilder sbuilder = new StringBuilder();
            
            sbuilder.Append("<html><title></title><head></head><body>");
            sbuilder.Append("");
            sbuilder.Append("<table border=1><tr>");

            for (int i = 0; i < dt.Columns.Count; i++)
            {
                sbuilder.Append("<td>" + dt.Columns[i].ColumnName + "</td>");
            }

            sbuilder.Append("</tr>");

            string strToken = string.Empty;
            string strDate = string.Empty;
            
            foreach (DataRow drRow in dt.Select(" ", "TokenNo asc"))
            {
                sbuilder.Append("<tr>");
                if (strToken != drRow["TokenNo"].ToString())
                {
                      strToken = drRow["TokenNo"].ToString();
                      strDate = drRow["Date"].ToString();
                        DataRow[] drRows = dt.Select("TokenNo='" + strToken + "'");
                        int len = drRows.Length;
                        DataRow[] drRows1 = dt.Select("Date='" + strDate + "'");
                        int len1 = drRows1.Length;
                        sbuilder.Append("<td rowspan='" + len + "'>");
                        sbuilder.Append(drRow["Name"].ToString() + "</td>");
                        sbuilder.Append("<td rowspan='" + len + "'>");
                        sbuilder.Append(drRow["TokenNo"].ToString() + "</td>");
                        sbuilder.Append("<td rowspan='" + len + "'>");
                        sbuilder.Append(drRow["TeamLeader"].ToString() + "</td>");
                        sbuilder.Append("<td rowspan='" + len + "'>");
                        sbuilder.Append(drRow["Date"].ToString() + "</td>");
                        sbuilder.Append("<td rowspan='" + len + "'>");
                        sbuilder.Append(drRow["Shift"].ToString() + "</td>");
                }
                sbuilder.Append("<td>" + drRow["FabricationType"].ToString() + "</td>");
                sbuilder.Append("<td>" + drRow["Stage"].ToString() + "</td>");
                
                sbuilder.Append("</tr>");
            }

            sbuilder.Append("</table>");
            //sbuilder.Append("<p> Thanks & Regards, <p>");
            //sbuilder.Append("<p>" + uname1 + "</p>");
            sbuilder.Append("</body></html>");
            return sbuilder.ToString();

        }



In this date is getting merged and it is showing only only one date, but not different dates.

Regards,
Avinash G.

解决方案

This is happening because you are only adding single token value. so, when the row with same token is iterated it doesn't add a td for your date value

<pre>  
                if (strToken != drRow["TokenNo"].ToString()) // this line won't allow row with same token to be included in your table
                {
                      strToken = drRow["TokenNo"].ToString();
                      strDate = drRow["Date"].ToString();
                       .......
                }




If you want to concatenate all dates for the same token iterate the rows with same token and create a string with all dates.


Yes, i need that only. Because for every line this common data is getting repeated. So i've displaying the common data only once. Remaing are displayed normally.

But actually what i need is the date column should not get merged.

For example :
If I generate the report for 2 or more days, the date column is showing only the first date.

So now I need to check both Token Number and Date. If the Token Number is same, it should display only once and same as with the date as well.

Can you please guide me what i can do here.


这篇关于日期列也正在合并的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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