ICellStyle cellStyle = workbook.CreateCellStyle(); cellStyle.DataFormat = HSSFDataFormat.GetBuiltinFormat("0.00%"); SumRow.CreateCell(17).CellStyle = cellStyle;
SumRow.CreateCell(17).SetCellValue(Convert.ToDouble(sumExamineGrossRate)); 我是这么加样式的为什么不起作用啊?
SumRow.CreateCell(17).SetCellValue(Convert.ToDouble(sumExamineGrossRate)); 我是这么加样式的为什么不起作用啊?
解决方案 »
- 如何在ASP:TEXTBOX上添加HTML中input的name属性值
- 做网站,怎么记住用户下次登录时不需要再输入?
- jquery 操作文本框问题
- 把大正方形分解为小正方形,急
- forms验证为什么要用身份验证票 直接用一个cookie保存不行吗?
- 未能加载文件或程序集“App_Licenses”或它的某一个依赖项。拒绝访问。大家遇到过这个问题么?
- 字体颜色效果!
- 如何用c#中的正则匹配下面的字符?
- 如何把前台JAVASCRIPT脚本中的变量值传给后台的变量??急!!
- 为什么使用dataAdapter.Fill(dataset, string)这个函数会报错"函数的参数过多"
- .net链接access数据库的问题
- ASP.NET MVC HTTP问题
/// <summary>
/// 获取单元格样式
/// </summary>
/// <param name="hssfworkbook">Excel操作类</param>
/// <param name="font">单元格字体</param>
/// <param name="fillForegroundColor">图案的颜色</param>
/// <param name="fillPattern">图案样式</param>
/// <param name="fillBackgroundColor">单元格背景</param>
/// <param name="ha">垂直对齐方式</param>
/// <param name="va">垂直对齐方式</param>
/// <returns></returns>
public static ICellStyle GetCellStyle(HSSFWorkbook hssfworkbook, IFont font, HSSFColor fillForegroundColor, FillPatternType fillPattern, HSSFColor fillBackgroundColor, HorizontalAlignment ha, VerticalAlignment va)
{
ICellStyle cellstyle = hssfworkbook.CreateCellStyle();
cellstyle.FillPattern = fillPattern;
cellstyle.Alignment = ha;
cellstyle.VerticalAlignment = va;
if (fillForegroundColor != null)
{
cellstyle.FillForegroundColor = fillForegroundColor.GetIndex();
}
if (fillBackgroundColor != null)
{
cellstyle.FillBackgroundColor = fillBackgroundColor.GetIndex();
}
if (font != null)
{
cellstyle.SetFont(font);
}
//有边框
cellstyle.BorderBottom = CellBorderType.THIN;
cellstyle.BorderLeft = CellBorderType.THIN;
cellstyle.BorderRight = CellBorderType.THIN;
cellstyle.BorderTop = CellBorderType.THIN;
return cellstyle;
}
//设置字体
Font font1 = hssfworkbook.CreateFont();
font1.Color = HSSFColor.RED.index;
font1.IsItalic = false;
font1.FontHeightInPoints = 10;cellStyle.SetFont(font1);
//设置边框背景等
cellStyle.BorderLeft = CellBorderType.THIN;
cellStyle.LeftBorderColor = HSSFColor.GREY_40_PERCENT.index;
cellStyle.BorderRight = CellBorderType.THIN;
cellStyle.RightBorderColor = HSSFColor.GREY_40_PERCENT.index;
cellStyle.FillForegroundColor = NPOI.HSSF.Util.HSSFColor.GREY_40_PERCENT.index;
cellStyle.FillPattern = FillPatternType.SOLID_FOREGROUND;
SumRow.CreateCell(17).CellStyle = cellStyle;
改为
ICell t = SumRow.CreateCell(17);
t.CellStyle = cellStyle;
t.SetCellValue(Convert.ToDouble(sumExamineGrossRate)); 这样才行