int index = 0, rownum = 0;
string ProjNo = "";
for (i = 0; i < table.Rows.Count; i++)
{
ProjNo = table.Rows[index]["PROJNO"].ToString();
if (table.Rows[i]["PROJNO"].ToString() == ProjNo)
{
wksheet.Cells[3 + i, 1] = rownum + 1;
wksheet.Cells[3 + i, 2] = "'" + table.Rows[i]["PROJNO"]; //加上单引号保证以0开头的字符原样输出
wksheet.Cells[3 + i, 3] = "'" + table.Rows[i]["PROJNAME"];
wksheet.Cells[3 + i, 4] = "'" + table.Rows[i]["PA_NAME"];
wksheet.Cells[3 + i, 5] = "'" + table.Rows[i]["BIDER_NAME"];
wksheet.Cells[3 + i, 6] = table.Rows[i]["BAIL_AMOUNT"];
wksheet.Cells[3 + i, 7] = table.Rows[i]["NOT_BACK"];
wksheet.get_Range(wksheet.Cells[3 + i, 1], wksheet.Cells[3 + i, 7]).Borders.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Black);
continue;
}
index = i;
rownum++;
i--;
}
下面合并前三列相同内容的单元:
复制代码 代码如下:
//合并前三列操作
int m = 1, rowid = 3, k;
string projName = "";
for (k = 3; k <= i + 2; k++)
{
if (Convert.ToInt32(wksheet.get_Range(wksheet.Cells[k, 1], wksheet.Cells[k, 1]).Value2) == m)
{
ProjNo = wksheet.get_Range(wksheet.Cells[k, 2], wksheet.Cells[k, 2]).Value2.ToString();
projName = wksheet.get_Range(wksheet.Cells[k, 3], wksheet.Cells[k, 3]).Value2.ToString();
wksheet.get_Range(wksheet.Cells[k, 1], wksheet.Cells[k, 1]).Value2 = "";
wksheet.get_Range(wksheet.Cells[k, 2], wksheet.Cells[k, 2]).Value2 = "";
wksheet.get_Range(wksheet.Cells[k, 3], wksheet.Cells[k, 3]).Value2 = "";
continue;
}
wksheet.get_Range(wksheet.Cells[rowid, 1], wksheet.Cells[k - 1, 1]).Merge(Missing.Value);
wksheet.get_Range(wksheet.Cells[rowid, 1], wksheet.Cells[rowid, 1]).Value2 = m;
wksheet.get_Range(wksheet.Cells[rowid, 2], wksheet.Cells[k - 1, 2]).Merge(Missing.Value);
wksheet.get_Range(wksheet.Cells[rowid, 2], wksheet.Cells[rowid, 2]).Value2 = "'" + ProjNo;
wksheet.get_Range(wksheet.Cells[rowid, 3], wksheet.Cells[k - 1, 3]).Merge(Missing.Value);
wksheet.get_Range(wksheet.Cells[rowid, 3], wksheet.Cells[rowid, 3]).Value2 = "'" + projName;
m++;
rowid = k;
k--;
}
//跳出循环后合并最后一个招标项目
wksheet.get_Range(wksheet.Cells[rowid, 1], wksheet.Cells[k - 1, 1]).Merge(Missing.Value);
wksheet.get_Range(wksheet.Cells[rowid, 1], wksheet.Cells[rowid, 1]).Value2 = m;
wksheet.get_Range(wksheet.Cells[rowid, 2], wksheet.Cells[k - 1, 2]).Merge(Missing.Value);
wksheet.get_Range(wksheet.Cells[rowid, 2], wksheet.Cells[rowid, 2]).Value2 = "'" + ProjNo;
wksheet.get_Range(wksheet.Cells[rowid, 3], wksheet.Cells[k - 1, 3]).Merge(Missing.Value);
wksheet.get_Range(wksheet.Cells[rowid, 3], wksheet.Cells[rowid, 3]).Value2 = "'" + projName;
下面合并标段列
复制代码 代码如下: