【发布时间】:2013-10-08 15:35:28
【问题描述】:
我正在尝试从我的代码创建一个 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);
}
}
【问题讨论】:
-
你到底在问什么,从你的代码中你似乎明白该怎么做。您是否使用 Excel 库来生成报告?
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
是的...您可以从两个 if 语句中看到我有早班和夜班,我需要将它们放入 Excel 表中的 B-5 列和 B-6 列中,但此刻它不是,它转到下一个可用列