这是我编写excel表的代码: 请建议如何将邮政编码列转换为测试格式,并在该列中允许前导零。
for (int r = 0; r < dsExportData.Tables[0].Rows.Count; r++)
{
sContent = sContent.Append(" <tr> ");
for (int c = 0; c < dsExportData.Tables[0].Columns.Count; c++)
{
//string s1 = dsExportData.Tables[0].Rows[r][c].ToString();
//string XMLstring = dsExportData.Tables[0].Rows[r][c].ToString();
//XMLstring = XMLstring.Trim().Replace("&", "&").Replace(">", ">").Replace("<", "<");
//sContent.Append("<Cell ss:StyleID=\"StringLiteral\">" + "<Data ss:Type=\"String\">");
if (dsExportData.Tables[0].Columns[c].ColumnName == "Postal Code")
{
sContent = sContent.Append(" <td> ");
string XMLstring = dsExportData.Tables[0].Rows[r][c].ToString();
XMLstring = XMLstring.Trim().Replace("&", "&").Replace(">", ">").Replace("<", "<");
//
//
sContent.AppendFormat( XMLstring.ToString(), ("<Cell ss:StyleID=\"StringLiteral\">" + "<Data ss:Type=\"String\">" ));
sContent = sContent.Append(" </td> ");
}
else
{
sContent = sContent.Append(" <td> ");
string XMLstring = dsExportData.Tables[0].Rows[r][c].ToString();
XMLstring = XMLstring.Trim().Replace("&", "&").Replace(">", ">").Replace("<", "<");
sContent.Append("<Cell ss:StyleID=\"StringLiteral\">" + "<Data ss:Type=\"String\">" + XMLstring.ToString());
sContent = sContent.Append(" </td> ");
}
}
sContent = sContent.Append(" </tr> ");
}
sContent = sContent.Append(" </table> ");