首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

asp.net导出Excel,怎么改变单元格中的字体

2013-05-02 
asp.net导出Excel,如何改变单元格中的字体 stringBuilder.Append(?xml version\1.0\ encoding\UTF-

asp.net导出Excel,如何改变单元格中的字体
 stringBuilder.Append("<?xml version="1.0" encoding="UTF-8"?>\n");
            stringBuilder.Append("<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"\n");
            stringBuilder.Append("xmlns:x="urn:schemas-microsoft-com:office:excel"\n");
            stringBuilder.Append("xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"\n");
            stringBuilder.Append("xmlns:html="http://www.w3.org/TR/REC-html40">\n");
            stringBuilder.Append("<Worksheet ss:Name="Table1">\n");
            stringBuilder.Append("<Table>\n");
            stringBuilder.Append("<Column ss:Index="1" ss:AutoFitWidth="0" ss:Width="110"/>\n");
            stringBuilder.Append("<Row>\n");
            stringBuilder.Append("<Cell><Data ss:Type="String">订单号</Data></Cell>\n");
 stringBuilder.Append("</Row>\n");
下面的代码需要设置输出字体的颜色
stringBuilder.Append("<Row>\n");
                    stringBuilder.Append("<Cell><Data ss:Type="String">" + tradelist[i].Tid + "</Data></Cell>\n");
                    stringBuilder.Append("<Cell><Data ss:Type="String">" + tradelist[i].BuyerNick + "</Data></Cell>\n");
stringBuilder.Append("</Row>\n");
ASP.NET Excel String Office spreadsheet
[解决办法]
百度搜索  myxls

可以修改字体 大小 以及多sheet合并单元格等操作
[解决办法]
  <Style ss:ID="s22">
   <Interior ss:Color="#FFFF00" ss:Pattern="Solid"/>
  </Style>

   <Row>
    <Cell ss:StyleID="s21"><Data ss:Type="String">A</Data></Cell>
    <Cell ss:StyleID="s22"><Data ss:Type="String">B</Data></Cell>
   </Row>
[解决办法]
试一试这样:
 <Styles>
  <Style ss:ID="s22">
   <Interior ss:Color="#FFFF00" ss:Pattern="Solid"/>
  </Style>
 </Styles>
<table>
    <Row>
    <Cell ss:StyleID="s22"><Data ss:Type="String">B</Data></Cell>
   </Row>
</table>

------解决方案--------------------


        protected void gvPersonnelInfo_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("style", "vnd.ms-excel.numberformat:@");
            }
        }

热点排行