找回密码
 立即注册

QQ登录

只需一步,快速开始

xujingtian

论坛元老

28

主题

115

帖子

5359

积分

论坛元老

积分
5359

活字格认证

[已处理] 条件格式化

xujingtian
论坛元老   /  发表于:2013-11-17 15:52  /   查看:4892  /  回复:1
我想在 如下EXCEL中的 测试六的的单元格里显示一个 感叹号的 图片
http://gcdn.grapecity.com/showtopic-10884.html

看了在线DEMO 后
http://www.gcpowertools.com.cn/L ... tting/Overview.aspx

怎么也设置不成功
            FarPoint.Web.Spread.ConditionalFormatting cf3 = new FarPoint.Web.Spread.ConditionalFormatting(
                                    new FarPoint.Web.Spread.Model.CellRange(3, 8, 1, 1));
                                FarPoint.Web.Spread.IconSetConditionalFormattingRule rule3 = new FarPoint.Web.Spread.IconSetConditionalFormattingRule(FarPoint.Web.Spread.ConditionalFormattingIconSetStyle.ThreeColoredArrows);
                                cf3.Add(rule3);

                                excelFpSpread.ActiveSheetView.ConditionalFormatting.Add(cf3);


请问要如何处理

1 个回复

倒序浏览
iceman
社区贡献组   /  发表于:2013-11-18 10:53:00
沙发
回复 1楼xujingtian的帖子

这个是 Demo 的实现源码,你可以参考下,比较下和你现在代码的差异,如果没解决问题可以继续沟通:

  1. public partial class Overview : SpreadDemoPage
  2.   {
  3.     protected void Page_Load(object sender, EventArgs e)
  4.     {
  5.       if (IsPostBack)
  6.       {
  7.         return;
  8.       }

  9.       InitSpread(FpSpread1);
  10.       InitSpreadStyles(FpSpread1.Sheets[0]);
  11.       this.FpSpread1.UseClipboard = false;
  12.     }

  13.     private void InitSpread(FarPoint.Web.Spread.FpSpread spread)
  14.     {
  15.       using (OleDbConnection connection = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\Northwind.mdb;Persist Security Info=True"))
  16.       {
  17.         using (OleDbDataAdapter adapter = new OleDbDataAdapter("SELECT TOP 9 Products.ProductName as 产品, Products.UnitPrice as [单价], Products.UnitsOnOrder as [订单], Products.UnitsInStock as [存货] FROM Products", connection))
  18.         {
  19.           DataTable products = new DataTable("Products");
  20.           adapter.Fill(products);
  21.           FpSpread1.DataSource = products;
  22.         }
  23.       }

  24.       spread.CssClass = "spreadStyle";
  25.       spread.UseClipboard = false;
  26.     }

  27.     private void InitSpreadStyles(FarPoint.Web.Spread.SheetView sheet)
  28.     {
  29.       sheet.ColumnCount = 4;
  30.       sheet.Columns[0].Width = 150;
  31.       sheet.Columns[1].Width = 80;
  32.       sheet.Columns[2].Width = 100;
  33.       sheet.Columns[3].Width = 80;

  34.       DataTable dt = (DataTable)sheet.DataSource;
  35.       sheet.AddUnboundRows(sheet.RowCount, 1);
  36.       FarPoint.Web.Spread.Cell cell = sheet.Cells[sheet.RowCount - 1, 0];
  37.       cell.Value = "平均值:";

  38.       FarPoint.Web.Spread.Row row = sheet.Rows[sheet.RowCount - 1];
  39.       row.Locked = true;
  40.       row.Font.Italic = true;
  41.       row.BackColor = System.Drawing.Color.Yellow;
  42.       row.Border.BorderColorTop = Color.Green;
  43.       row.Border.BorderSizeTop = 2;
  44.       row.Border.BorderStyleTop = BorderStyle.Solid;

  45.       for (int i = 1; i < sheet.ColumnCount; i++)
  46.       {
  47.         string col = Convert.ToString((char)(65 + i));
  48.         sheet.Cells[sheet.RowCount - 1, i].Formula = "AVERAGE(" + col + "1:" + col + Convert.ToString(sheet.RowCount - 1) + ")";
  49.       }

  50.       FarPoint.Web.Spread.ConditionalFormatting cf = new FarPoint.Web.Spread.ConditionalFormatting(new FarPoint.Web.Spread.Model.CellRange(0, 1, sheet.RowCount - 1, 1));
  51.       FarPoint.Web.Spread.DatabarConditionalFormattingRule rule = new FarPoint.Web.Spread.DatabarConditionalFormattingRule();
  52.       rule.BorderColor = System.Drawing.Color.Silver;
  53.       rule.ShowBorder = true;
  54.       rule.Gradient = true;
  55.       rule.Minimum = new FarPoint.Web.Spread.ConditionalFormattingValue(0, FarPoint.Web.Spread.ConditionalFormattingValueType.Number);
  56.       rule.Maximum = new FarPoint.Web.Spread.ConditionalFormattingValue(100, FarPoint.Web.Spread.ConditionalFormattingValueType.Max);
  57.       cf.Add(rule);
  58.       sheet.ConditionalFormatting.Add(cf);

  59.       FarPoint.Web.Spread.ConditionalFormatting cf1 = new FarPoint.Web.Spread.ConditionalFormatting(new FarPoint.Web.Spread.Model.CellRange(0, 2, sheet.RowCount - 1, 2));
  60.       FarPoint.Web.Spread.DatabarConditionalFormattingRule rule1 = new FarPoint.Web.Spread.DatabarConditionalFormattingRule();
  61.       rule1.BorderColor = System.Drawing.Color.Silver;
  62.       rule1.ShowBorder = true;
  63.       rule1.Gradient = true;
  64.       rule1.Minimum = new FarPoint.Web.Spread.ConditionalFormattingValue(0, FarPoint.Web.Spread.ConditionalFormattingValueType.Number);
  65.       rule1.Maximum = new FarPoint.Web.Spread.ConditionalFormattingValue(120, FarPoint.Web.Spread.ConditionalFormattingValueType.Max);
  66.       cf1.Add(rule1);
  67.       sheet.ConditionalFormatting.Add(cf1);

  68.       FarPoint.Web.Spread.ConditionalFormatting cf2 = new FarPoint.Web.Spread.ConditionalFormatting(new FarPoint.Web.Spread.Model.CellRange(0, 3, sheet.RowCount - 1, 3));
  69.       FarPoint.Web.Spread.IconSetConditionalFormattingRule rule2 = new FarPoint.Web.Spread.IconSetConditionalFormattingRule(FarPoint.Web.Spread.ConditionalFormattingIconSetStyle.ThreeCircledSymbols);

  70.       cf2.Add(rule2);
  71.       sheet.ConditionalFormatting.Add(cf2);

  72.       FarPoint.Web.Spread.ConditionalFormatting cf3 = new FarPoint.Web.Spread.ConditionalFormatting(new FarPoint.Web.Spread.Model.CellRange(sheet.RowCount - 1, 1, 1, sheet.ColumnCount));
  73.       FarPoint.Web.Spread.IconSetConditionalFormattingRule rule3 = new FarPoint.Web.Spread.IconSetConditionalFormattingRule(FarPoint.Web.Spread.ConditionalFormattingIconSetStyle.ThreeColoredArrows);
  74.       cf3.Add(rule3);
  75.       sheet.ConditionalFormatting.Add(cf3);
  76.     }
  77.   }

复制代码
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 立即注册
返回顶部