下面的代码是我从数据库里面获取数据对Spread表格控件进行数据绑定的代码其中还包括了一些设置
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void btnScreen_Click(object sender, EventArgs e)
{
string subjectid = this.ddlParentSubjectID.SelectedValue;
// 根据父节点查询所有最底层的子节点
DataTable data = Model.BudgetInfo.GetDataByParentSubjectID(subjectid, this.SiteID, "1");
//关闭自动生成列属性
this.CompanyBudgetFpSpread.Sheets[0].AutoGenerateColumns = false;
// 绑定数据源
this.CompanyBudgetFpSpread.DataSource = data;
#region 按例绑定
this.CompanyBudgetFpSpread.Sheets[0].Columns[1].DataField = "所属部门";
this.CompanyBudgetFpSpread.Sheets[0].Columns[2].DataField = "预算事项名称";
this.CompanyBudgetFpSpread.Sheets[0].Columns[3].DataField = "预算科目代码";
this.CompanyBudgetFpSpread.Sheets[0].Columns[4].DataField = "预算科目名称";
this.CompanyBudgetFpSpread.Sheets[0].Columns[5].DataField = "年度";
this.CompanyBudgetFpSpread.Sheets[0].Columns[6].DataField = "1月";
this.CompanyBudgetFpSpread.Sheets[0].Columns[7].DataField = "2月";
this.CompanyBudgetFpSpread.Sheets[0].Columns[8].DataField = "3月";
this.CompanyBudgetFpSpread.Sheets[0].Columns[9].DataField = "4月";
this.CompanyBudgetFpSpread.Sheets[0].Columns[10].DataField = "5月";
this.CompanyBudgetFpSpread.Sheets[0].Columns[11].DataField = "6月";
this.CompanyBudgetFpSpread.Sheets[0].Columns[12].DataField = "7月";
this.CompanyBudgetFpSpread.Sheets[0].Columns[13].DataField = "8月";
this.CompanyBudgetFpSpread.Sheets[0].Columns[14].DataField = "9月";
this.CompanyBudgetFpSpread.Sheets[0].Columns[15].DataField = "10月";
this.CompanyBudgetFpSpread.Sheets[0].Columns[16].DataField = "11月";
this.CompanyBudgetFpSpread.Sheets[0].Columns[17].DataField = "12月";
this.CompanyBudgetFpSpread.Sheets[0].Columns[18].DataField = "编号";
this.CompanyBudgetFpSpread.Sheets[0].Columns[18].Visible = false;
this.CompanyBudgetFpSpread.Sheets[0].Columns[20].DataField ="预算事项编码";
//this.CompanyBudgetFpSpread.Sheets[0].Columns[19].DataField ="锁定状态";
#endregion
// 设置复选框主
this.CompanyBudgetFpSpread.Sheets[0].Columns[0].CellType = new FarPoint.Web.Spread.CheckBoxCellType();
// 设置例数
this.CompanyBudgetFpSpread.Sheets[0].ColumnCount = data.Columns.Count - 1;
#region 设置单元格的宽度
this.CompanyBudgetFpSpread.Sheets[0].Columns[0].Width = 20;
this.CompanyBudgetFpSpread.Sheets[0].Columns[1].Width = 100;
this.CompanyBudgetFpSpread.Sheets[0].Columns[2].Width = 160;
this.CompanyBudgetFpSpread.Sheets[0].Columns[3].Width = 120;
this.CompanyBudgetFpSpread.Sheets[0].Columns[4].Width = 250;
this.CompanyBudgetFpSpread.Sheets[0].Columns[5].Width = 50;
this.CompanyBudgetFpSpread.Sheets[0].Columns[6].Width = 50;
this.CompanyBudgetFpSpread.Sheets[0].Columns[7].Width = 50;
this.CompanyBudgetFpSpread.Sheets[0].Columns[8].Width = 50;
this.CompanyBudgetFpSpread.Sheets[0].Columns[9].Width = 50;
this.CompanyBudgetFpSpread.Sheets[0].Columns[10].Width = 50;
this.CompanyBudgetFpSpread.Sheets[0].Columns[11].Width = 50;
this.CompanyBudgetFpSpread.Sheets[0].Columns[12].Width = 50;
this.CompanyBudgetFpSpread.Sheets[0].Columns[13].Width = 50;
this.CompanyBudgetFpSpread.Sheets[0].Columns[14].Width = 50;
this.CompanyBudgetFpSpread.Sheets[0].Columns[15].Width = 50;
this.CompanyBudgetFpSpread.Sheets[0].Columns[16].Width = 50;
this.CompanyBudgetFpSpread.Sheets[0].Columns[17].Width = 50;
#endregion
// 行选择模式,并在单击单元格时直接进入编辑状态
CompanyBudgetFpSpread.ActiveSheetView.OperationMode = FarPoint.Web.Spread.OperationMode.RowMode;
CompanyBudgetFpSpread.EditModePermanent = true;
// 设置spread 表格头部字体的大小
this.CompanyBudgetFpSpread.Sheets[0].ColumnHeader.DefaultStyle.Font.Size = 10;
this.CompanyBudgetFpSpread.Sheets[0].Cells[0, 0].Text = "";
} |
|