请教,现在比方说,
我生成的EXCEL的某个单元格的内容是
asddsad<red>keyword1</red>sadsadhjkasd<red>keyword2</red>sdsd
要的结果是
asddsadkeyword1sadsadhjkasdkeyword2sdsd
也就是把标记之内字体颜色变红,
这个怎么做啊

解决方案 »

  1.   

    就是导出被。.   datagrid  或者gridveiw   你先把 这2个里面的字边成红色, 导出去就是红色了
      

  2.   

    你这到底是导入Excel还是导出?
      

  3.   

    我没说清楚,
    从数据库导到EXCEL,
    数据库中的数据为asddsad<red>keyword1</red>sadsadhjkasd<red>keyword2</red>sdsd
    EXCEL显示上为asddsadkeyword1sadsadhjkasdkeyword2sdsd
    能明白了吗
      

  4.   

    ActiveCell.Characters(Start:=1, Length:=4).Font.ColorIndex = 3
      

  5.   

    导入时对导入内容进行解析,如:以<red>开头,</red>结尾就为红色
    然后将<red>和</red>去掉,设置单元格的字体颜色
    ActiveCell.FormulaR1C1   =  ...
    With   
        ActiveCell.Characters(Start:=1,   Length:=5).Font.ColorIndex   =   3   //3表示红色
    End   With
      

  6.   

    public void ExortExcel() //从GridView中导出Excel的函数
        {
            if (this.Gv.Rows.Count != 0)
            {
                HttpContext.Current.Response.Clear();
                HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=" + DateTime.Now.ToString("yyyyMMddHHmmss") + ".xls");     //这里是用日期做名称
                HttpContext.Current.Response.Charset = "utf-8";
                HttpContext.Current.Response.ContentType = "application/excel";
                System.IO.StringWriter stringWrite = new System.IO.StringWriter();
                System.Web.UI.HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
                this.Gv.AllowPaging = false;                 //GridView不启用分页
                Gv.RenderControl(htmlWrite);
                HttpContext.Current.Response.Write(stringWrite.ToString());
            }
    }private void ToExcel() //从GridView导出Excel函数2 (这两个方法可任选其一)
        {
            string style = @"<style> .text { mso-number-format:\@; } </script> ";
            string Ftile = System.DateTime.Now.Year.ToString() + System.DateTime.Now.Month.ToString() + System.DateTime.Now.Day.ToString() + System.DateTime.Now.Hour.ToString();
            Response.Clear();
            Response.Buffer = true;
            Response.Charset = "GB2312";
            Response.AppendHeader("Content-Disposition", "attachment;filename=COM_" + Ftile + ".xls");
          //  Response.ContentEncoding = System.Text.Encoding.GetEncoding("GB2312");//设置输出流为简体中文
            Response.ContentEncoding = System.Text.Encoding.UTF7;
            Response.ContentType = "application/ms-excel";//设置输出文件类型为excel文件。
     //       Response.Write("<meta http-equiv=Content-Type content=\"text/html; charset=GB2312\">");
            this.EnableViewState = false;
            System.Globalization.CultureInfo myCItrad = new System.Globalization.CultureInfo("ZH-CN", true);
            System.IO.StringWriter oStringWriter = new System.IO.StringWriter(myCItrad);
            System.Web.UI.HtmlTextWriter oHtmlTextWriter = new System.Web.UI.HtmlTextWriter(oStringWriter);
            this.Gvexel.RenderControl(oHtmlTextWriter);//GVDY 是Gridview的ID名称
            Response.Write(style);   
            Response.Write(oStringWriter.ToString());
            Response.End();
        }本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hongjiaoli/archive/2009/10/23/4716844.aspx