重置列excel报告

时间:2013-10-08 15:35:29

标签: c# excel reporting

我正在尝试从我的代码创建一个excel报告,基本上当我到达第二个if语句时,数据会转到第一个的不同列,基本上它从列B开始,这应该始终是开始专栏,我该怎么做?

arrData = clsData.GetReport(strStartDate, strEndDate);

dataCount = arrData.Count;
string col = "B";

foreach (string item in arrData)
{
    string[] stuff = item.Split('\t');


    if (stuff[0].Equals("Machine1"))
    {
         if (stuff[5].Equals("M")) 
         {
            row = 5;
            ws.Cells[row, col] = stuff[1];                   // Morning Shift Total 
            col = IncCol(col);
         }
    }
    else 
    {
         if (stuff[5].Equals("N")) 
         {
            row = 6;
            ws.Cells[row, col] = stuff[1];                   //Night Shift Total 
            col = IncCol(col);
         }
    }


    if (stuff[0].Equals("Machine2"))
    {
        if (stuff[5].Equals("M"))
        {
            row = 10;
             ws.Cells[row, col] = stuff[1];                   //Morning Shift Total 
            col = IncCol(col);
        }
    }
    else
    {
        if (stuff[5].Equals("N"))
        {
            row = 11;
            ws.Cells[row, col] = stuff[1];                   //Night Shift Total 
            col = IncCol(col);
        }
    }

1 个答案:

答案 0 :(得分:0)

夜班/早班的else部分应该在if

Machine1/Machine2条件范围内
arrData = clsData.GetReport(strStartDate, strEndDate);

dataCount = arrData.Count;
string col = "B";

foreach (string item in arrData)
{
    string[] stuff = item.Split('\t');
    if (stuff[0].Equals("Machine1"))
    {
        if (stuff[5].Equals("M")) 
        {
            row = 5;
            ws.Cells[row, col] = stuff[1];                   // Morning Shift Total 
            col = IncCol(col);
        }
        else 
        {
            if (stuff[5].Equals("N")) 
            {
                row = 6;
                ws.Cells[row, col] = stuff[1];               //Night Shift Total 
                col = IncCol(col);
            }
        }
    }              
    else 
    {
        if (stuff[0].Equals("Machine2"))
        {
            if (stuff[5].Equals("M"))
            {
                row = 10;
                ws.Cells[row, col] = stuff[1];               //Morning Shift Total 
                col = IncCol(col);
            }
            else
            {
                if (stuff[5].Equals("N"))
                {
                    row = 11;
                    ws.Cells[row, col] = stuff[1];           //Night Shift Total 
                    col = IncCol(col);
                }
            }
        }
    }
}