如何在邮政编码列值中包含前导零?

时间:2016-05-09 14:00:28

标签: asp.net c#-4.0

这是我编写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("&", "&amp;").Replace(">", "&gt;").Replace("<", "&lt;");
                    //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("&", "&amp;").Replace(">", "&gt;").Replace("<", "&lt;");
                        //

                        //
                        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("&", "&amp;").Replace(">", "&gt;").Replace("<", "&lt;");
                        sContent.Append("<Cell ss:StyleID=\"StringLiteral\">" + "<Data ss:Type=\"String\">" + XMLstring.ToString());
                        sContent = sContent.Append(" </td> ");

                    }

                }
                sContent = sContent.Append(" </tr> ");
            }
            sContent = sContent.Append(" </table> ");

0 个答案:

没有答案