用友华表Cell一些用法小结(cs.net版本)

  

  //从Color类型得到RGB类型,也可以用ColorTranslator.ToOle()方法
  public int GetRGBFromColor(Color color)
  {
    byte r = color.R;
    byte g = color.G;
    byte b = color.B;
    //转化为32bit RGB值:
    int rgb = (r & 0xff) | ((g & 0xff) << 8) | ((b & 0xff) << 16);
    return rgb;
  }

  // 注册Cell,并初始化cell属性天畅科技
  private bool RegisterCell()
  {
    try
    {
      //注册Cell
      int loginresult = axCell1.Login("北京", "11100101954", "7640-1017-7650-5004");
      if (loginresult == 0)
      {
        FrmTZTip.Show("错误提示", "注册Cell失败", TipType.waring);
        return false;
      }
      axCell1.LocalizeControl(0x804);
      axCell1.ShowHScroll(1, axCell1.GetCurSheet());//横向滚轮
      axCell1.ShowVScroll(1, axCell1.GetCurSheet());//纵向滚轮
      this.axCell1.SetGridCursor(0, 1);//设置鼠标样式
      axCell1.AllowCopy = false;//不允许复制
      axCell1.AllowCut = false;// 不允许剪切
      axCell1.AllowExtend = false;//不允许用鼠标拖动选中单元格的右下角进行扩展操作
      axCell1.AllowDragdrop = false;//不允许拖拽单元格
      return true;
    }
    catch
    {
      FrmTZTip.Show("错误提示", "注册Cell失败", TipType.waring);
      return false;
    }
  }

  InsertRow2方法最后一个参数用法:
  0:插入空白行(和InsertCleanRow功能一样)
  // 1:插入行,自动复制上一行的某些属性(和InsertRow功能一样),不包括单元格的合并
  // 2:插入行,自动复制上一行的某些属性,会自动独立合并startrow行上的某列(根据上一行的合并情况)
  // 3:插入行,自动添加到上一行的合并单元格中
     // >3:如3雷同...

      //批量导入公式
   axCell1.SetAllFormulas(str_公式,false);

   //得到公式

   str_公式 = axCell1.GetAllFormulas();

   //是否为公式单元格

   IsFormulaCell方法

   //不显示公式编辑
        private void axCell1_AllowInputFormula(object sender, AxCELL50Lib._DCell2000Events_AllowInputFormulaEvent e)
        {
            e.approve = 0;
        }

   //放大缩小,注意最后的100一定要带上.0,也可以把数据装换成double类型
        axCell1.SetScreenScale(axCell1.GetCurSheet(), Convert.ToInt32(combBigger.SelectedItem.ToString().TrimEnd('%')) / 100.0);

    /// <summary>
        /// 插入行,并继承公式zdc,自写的一个插入行可以继承公式的方法
        /// </summary>
        /// <param name="startrow">要插入行的行号</param>
        /// <param name="count">插入几行</param>
        /// <param name="axcell">cell控件对象</param>
        public void InsertRow3(int startrow,int count,AxCELL50Lib.AxCell axcell)
        {
            axcell.InsertRow2(axcell.GetCurrentRow(), 1, axcell.GetCurSheet(), 2);

            //遍历插入行上面一行的所有单元格,如果为公式行,选中这一个单元格和下面的一个(SelectRange),然后再用FormulaFillSerial()方法,用FormulaFillSerial方法能按最上面单元格的公式继承
            for (int j = 1; j <= axcell.GetCols(axcell.GetCurSheet()); j++)
            {
                if (axcell.IsFormulaCell(j, startrow - 1, axcell.GetCurSheet()) > 0)
                {
                    axcell.SelectRange(j, startrow - 1, j, startrow);
                    axcell.FormulaFillSerial();
                }
            }
        }

   //帮助文档上说的设置单元格为下拉窗体xml数据源的,试了用第一种方法直接读取xml地址的不行,用第二种

   XmlDocument xmldoc = new XmlDocument();
            xmldoc.Load(@"E:测试ReportTestReportTest est.xml");
           
            string xml= xmldoc.OuterXml;
            int n = axCell1.RSDefXmlSet("setname", xml, 2);
            axCell1.SetDropwndCell(9,4,axCell1.GetCurSheet(),n,2,2);

   CalcNumFormula方法,用于手动验证公式时,

   如:CalcNumFormula("CurCell()>I8",Convert.ToInt32(col) - 64, row, axCell1.GetCurSheet(), ref type),后面的列、行、表,是用于如果出现CurCell()等当前行,当前列,当前单元格时,定位这个当前参数用的

单元格添加下拉树形控件(SetDroptreeCell方法)

xml格式如下:

<?xml version="1.0" encoding="utf-8"?>
<XML>
  <CONFIG>
    <name name="SORT" value="sot"/>
    <name name="CHANGE" value="chg"/>
    <name name ="DISPLAY" value="hyname"/>
    <name name="RETURN" value="rtn"/>
    <name name="DEFAULTHEIGHT" value="0"/>
    <name name="DEFAULTWIDHT" value="0"/>
    <name name="KEYFIELD" value="key"/>
  </CONFIG>
  <VALUE>
    <tree0 hyname="农副食品加工业" rtn="" chg="cgh3" sot="a" key="ddd">
      <subtree hyname="谷物磨制" rtn="轻工" chg="cgh3" sot="a" key="ddd" />
      <subtree hyname="饲料加工" rtn="轻工" chg="cgh3" sot="a" key="ddd" />
      <subtree hyname="植物油加工" rtn="轻工" chg="cgh3" sot="a" key="ddd" />
    </tree0>
    <tree4 hyname="食品制造业" rtn="" chg="cgh3" sot="a" key="ddd">
      <subtree hyname="焙烤食品制造" rtn="轻工" chg="cgh3" sot="a" key="ddd" />
      <subtree hyname="糖果、巧克力及蜜饯制造" rtn="轻工" chg="cgh3" sot="a" key="ddd" />
      <subtree hyname="方便食品制造" rtn="轻工" chg="cgh3" sot="a" key="ddd" />
      <subtree hyname="乳制品制造" rtn="轻工" chg="cgh3" sot="a" key="ddd" />
    </tree4>
  </VALUE>
</XML>

axCell1.SetDroptreeCell(2, 19, axCell1.GetSheetIndex("SB10401_003_1"), Str, -1, -1, 1);

效果如下:

原文地址:https://www.cnblogs.com/dachuang/p/4616584.html