Spread For ASP.NET开发之一

一、FarPoint _Spread简介

(1)Spread For ASP.NET是一个综合性的,用于.NET平台的ASP.NET应用程序开发的表格控件。他集成了丰富的表格功能,工作表功能,并可与多种数据源绑定;
(2)一个Spread控件可以支持多大20亿个工作表,每个工作表可以处理20亿行和20列,并且支持夸工作表的数据引用和公式引用;
(3)Spread有Web版本和WinForm版本;
(4)下面以FarPoint.Web.Spread3为例简单介绍一下如何使用。

二、FarPoint.Web.Spread的使用

1、准备

(1)首先需要下载FarPoint.Web.Spread3相关的动态库,下载地址:点击打开链接
(2)在项目中引用动态库,包括:FarPoint.CalcEngine.dll、FarPoint.Excel.dll、FarPoint.Web.Spread.dll;
(3)为了使用方便,可以将其添加到工具栏菜单中;

2、Spread Web功能模型图

Spread For ASP.NET开发之一_第1张图片

3、基本功能介绍

(1)支持单元格内的编辑和验证,支持.NET2.0以上;
(2)支持绑定和非绑定模式(无需数据库);
(3)支持AJAX;
(4)支持Excel的导入和导出;
(5)支持客户端行/列缩放、多重表、搜索、筛选、多重单元格类型、验证、单元格合并、多表头、排序、单元格级的全面定制;
(6)支持分层显示
(7)提供丰富的打印工能;

4、实例

(1)前台代码
     Height="200" Style="position: absolute;" Width="400">
      
      
         

         
      
    
  
(2)后台代码
#region Event Methods

        protected void Page_Load(object sender, EventArgs e)
        {
            InitialFarPoint(this.fpSpread);
        }

        #endregion

        #region Private Methods

        private void InitialFarPoint(FpSpread spread)
        {
            //设置表格的高度、宽度、列数、行数
            spread.Height = 600;
            spread.Width = 1000;
            spread.ActiveSheetView.ColumnCount = 100;
            spread.ActiveSheetView.RowCount = 100;
            spread.ActiveSheetView.AllowColumnMove = true;
            //设置操作Cell的方式(可读写)
            spread.ActiveSheetView.OperationMode = OperationMode.RowMode;
            //是否可以使用复制粘贴
            spread.UseClipboard = true;
            //是否显示工具栏
            spread.CommandBar.Visible = false;
            //spread.CommandBarOnBottom = true;
            //spread.CommandBar.ButtonShadowColor = Color.Gold;

            //spread.ActiveSheetView.AllowSort = true;
            //设置列标题的默认高度
            spread.ActiveSheetView.ColumnHeaderHeight = 30;
            //设置单元格的默认高度
            spread.ActiveSheetView.Rows.Default.Height = 15;
            //设置水平和垂直滚动条
            spread.HorizontalScrollBarPolicy = ScrollBarPolicy.AsNeeded;
            spread.VerticalScrollBarPolicy = ScrollBarPolicy.AsNeeded;
            //设置工作表的Corner的样式
            spread.ActiveSheetView.SheetCornerStyle.BackColor = Color.FromArgb(169, 196, 233);
            //spread.ActiveSheetView.SheetCornerStyleName = "全选";      

            //获取或设置是否可以分页
            spread.ActiveSheetView.AllowPage = false;

            //设置外部边框的样式
            spread.BorderColor = Color.FromArgb(120, 100, 90);
            spread.BorderStyle = BorderStyle.Solid;
            spread.BorderWidth = 2;

            //设置工作表的背景色
            spread.ActiveSheetView.BackColor = Color.White;
            //Color.FromArgb(110,200,180);

            //设置选中单元格的背景色
            spread.ActiveSheetView.SelectionBackColor = Color.Red;
            //spread.ActiveSheetView.DataSource

            int pRowCount = spread.ActiveSheetView.RowCount;
            int pColumnCount = spread.ActiveSheetView.ColumnCount;
            //设置列标题
            spread.Sheets[0].ColumnHeader.RowCount = 2;
            spread.Sheets[0].RowHeader.ColumnCount = 1;
            spread.ActiveSheetView.ColumnHeader.DefaultStyle.BackColor = Color.FromArgb(228, 236, 247);
            spread.ActiveSheetView.RowHeader.DefaultStyle.BackColor = Color.FromArgb(228, 236, 247);
            for (int i = 0; i < pColumnCount; i++)
            {
                spread.ActiveSheetView.ColumnHeader.Cells[0, i].Text = "第" + (++i) + "列";
                i--;
                //spread.ActiveSheetView.ColumnHeaderVisible = false;
                //spread.ActiveSheetView.all
            }
            //设置单元格的值
            for (int i = 0; i < pRowCount; i++)
            {
                for (int j = 1; j < pColumnCount; j++)
                {
                    //设置单元格的类型
                    spread.ActiveSheetView.Cells[i, --j].CellType = new IntegerCellType("有非数字");
                    spread.ActiveSheetView.Columns[0].CellType = new IntegerCellType();
                    //日期类型
                    //spread.ActiveSheetView.Cells[i, j].CellType = new DateTimeCellType();
                    //单选框类型
                    //spread.ActiveSheetView.Cells[i, j].CellType = new CheckBoxCellType();
                    //文本类型
                    //spread.ActiveSheetView.Cells[i, j].CellType = new GeneralCellType();
                    j++;

                    spread.ActiveSheetView.Cells[i, 0].Text = (++i).ToString();
                    i--;
                    spread.ActiveSheetView.Cells[i, j].Text = (i * j).ToString();
                }
            }

            //Protect属性设置单元格是否需要被锁定,当Locked为true时,他必须为true,默认为true
            //spread.ActiveSheetView.Protect = true;
            for (int i = 0; i < pRowCount; i++)
            {
                //锁定单元格
                spread.ActiveSheetView.Cells[i, 0].Locked = true;
                spread.ActiveSheetView.Rows[i].VerticalAlign = VerticalAlign.Middle;
                spread.ActiveSheetView.Rows[i].HorizontalAlign = HorizontalAlign.Left;
            }
            //设置被锁住单元格的背景色和前景色
            spread.ActiveSheetView.LockBackColor = Color.Gray;
            spread.ActiveSheetView.LockForeColor = Color.Red;

            //spread.ActiveSheetView.PageSize = spread.Rows.Count + 10;
            //spread.OpenExcel(@"E:\工作\待解决.xlsx", 0, 0);

            //冻结行列
            //spread.ActiveSheetView.FrozenColumnCount = 1;
            //spread.ActiveSheetView.FrozenRowCount = 1;

            选择引用样式
            //spread.ActiveSheetView.ReferenceStyle = ReferenceStyle.R1C1;
            设置单元格公司
            //spread.ActiveSheetView.Cells[0, 9].Formula = "RC[-1]-RC[-2]";
            //for (int i = 1; i < 10; i++)
            //{
            //    //设置公式,同一列的上面一行减去同一行的左边第二列加上同一行的左边第一列
            //    spread.ActiveSheetView.Cells[i, 9].Formula = "R[-1]C-RC[-2]+RC[-1]";
            //}

            合并单元格
            //spread.ActiveSheetView.AddSpanCell(1, 2, 3, 4);
        }

        #endregion
(3)展示
Spread For ASP.NET开发之一_第2张图片




你可能感兴趣的:(报表组件)