none
导出excel的问题!请教各位! RRS feed

  • 问题

  • using Microsoft.Office.Interop.Excel;

     ApplicationClass ex = new ApplicationClass();

                ex.Visible = true;//显示Excel
                if (ex == null)
                {
                    //无法显示时报错
                    HttpContext.Current.Response.Write("<script>alert('加载Excel失败!');</script>");
                    return;
                }
                string[] tles = para.TitleStr.Split(",".ToCharArray());
                string[] Imps = para.ImpStr.Split(",".ToCharArray());
                string[] tlbs = para.TitleStr.Split(",".ToCharArray());
                //获得工作薄
                Workbooks wbs = ex.Workbooks;
                Workbook wb = wbs.Add(XlWBATemplate.xlWBATWorksheet);
                    Worksheet ws = (Worksheet)wb.Worksheets[z];
     for (int y = 0; y <= dt.Rows.Count - 1; y += 1)
                    {
                        System.Data.DataRow dr = dt.Rows[y];
                        int n2 = 1;
                        foreach (string imp in Imps)
                        {
                            string[] im = imp.Split("|".ToCharArray());

                            if ((im[0]=="编号")&&(im[1]=="BoardNo"))
                            {
                                ws.Cells[para.locR + 1 + y, para.locC + n2] ="特殊处理"+ Convert.ToString(dr[im[1].ToUpper()]);
    //问题就在这,导出数据都没问题,但我的编号比如"00001234",在excel 里显示的是"1234",前面的0怎么才能保持,编号的位数并不固定,我像上面那样每个编号都加了几个汉字,都可以显示,笨办法!,我想在程序里面怎么处理才能不省略前面的0呢?
                            }
                        }

    2010年1月27日 8:31

答案

全部回复