当前位置: 首页 > 工具软件 > Spread > 使用案例 >

Spread基本知识(二)

淳于昊然
2023-12-01

Spread基本知识(二)

7 Focus移动(跨列)

public frmProdSetDetail()
  {
   InitializeComponent();
   IsMod = flag;

   FarPoint.Win.Spread.InputMap im;
   im = spdResult.GetInputMap(InputMapMode.WhenFocused);
   im.Put(new Keystroke(Keys.Enter,Keys.None),SpreadActions.MoveToNextColumnWrap);
   im.Put(new Keystroke(Keys.Tab,Keys.None),SpreadActions.MoveToNextColumnWrap);

   im = spdResult.GetInputMap(InputMapMode.WhenAncestorOfFocused);
   im.Put(new Keystroke(Keys.Enter,Keys.None),SpreadActions.MoveToNextColumnWrap);
   im.Put(new Keystroke(Keys.Tab,Keys.None),SpreadActions.MoveToNextColumnWrap);
  }

指定单元格获得焦点      

this.fpSpread1.ActiveSheet.SetActiveCell(row,column);

8 事件触发顺序                            

 _Enter    _EnterCell      _EditModeOn      _EditChange      _EditModeOff      _LeaveCell

9 用隐藏列保存原始数据  

10 设定列类型

private void SpreadSetting()
  {
   string[] ProductHandleTypeList = new string[]{" ","1 販売/仕入","2 販売","3 仕入"};
  
   FarPoint.Win.Spread.CellType.ComboBoxCellType cb3 = new FarPoint.Win.Spread.CellType.ComboBoxCellType();
   cb3.ListWidth = 100;
   cb3.Editable = true;
   cb3.MaxDrop = 5;
   cb3.MaxLength = 1;
   cb3.Items = ProductHandleTypeList;

   this.spdResult.ActiveSheet.Columns[5].CellType = cb3;
 
   //设置一般数据型

   FarPoint.Win.Spread.CellType.NumberCellType nmbrcell = new FarPoint.Win.Spread.CellType.NumberCellType();
   nmbrcell.ShowSeparator = false;
   nmbrcell.DecimalPlaces = 0;
   nmbrcell.LeadingZero = FarPoint.Win.Spread.CellType.LeadingZero.UseRegional;
   nmbrcell.MaximumValue = 9999;
   nmbrcell.MinimumValue = 1;
   this.spdResult.ActiveSheet.Columns[13].CellType = nmbrcell;

   //设置JAN

   FarPoint.Win.Spread.CellType.NumberCellType nmbrcellJan = new FarPoint.Win.Spread.CellType.NumberCellType();
   nmbrcellJan.ShowSeparator = false;
   nmbrcellJan.DecimalPlaces = 0;
   nmbrcellJan.LeadingZero = FarPoint.Win.Spread.CellType.LeadingZero.UseRegional;
   nmbrcellJan.MaximumValue = 9999999999999;
   nmbrcellJan.MinimumValue = 0;
   this.fpSpread1.ActiveSheet.Columns[0].CellType = nmbrcellJan;
   this.fpSpread1.ActiveSheet.Columns[0].HorizontalAlignment = FarPoint.Win.Spread.CellHorizontalAlignment.Left;

   //

   FarPoint.Win.Spread.CellType.NumberCellType numberCellType1 = new FarPoint.Win.Spread.CellType.NumberCellType();
   numberCellType1.ShowSeparator = true;
   numberCellType1.DecimalPlaces = 0;
   numberCellType1.LeadingZero = FarPoint.Win.Spread.CellType.LeadingZero.UseRegional;
   numberCellType1.MaximumValue = 99999999;
   numberCellType1.MinimumValue = 0;
   this.spdResult.ActiveSheet.Columns[20].CellType = numberCellType1;

   //%数的设定

   FarPoint.Win.Spread.CellType.PercentCellType prctcell = new FarPoint.Win.Spread.CellType.PercentCellType();
   prctcell.PercentSign = "%";
   this.spdResult.ActiveSheet.Columns[33].CellType = prctcell;
   
   //日期的设定

   FarPoint.Win.Spread.CellType.DateTimeCellType datecell = new FarPoint.Win.Spread.CellType.DateTimeCellType();
   datecell.MaximumDate = new System.DateTime(2050, 12, 31, 0, 0, 0, 0);
   datecell.MinimumDate = new System.DateTime(2001, 1, 1, 0, 0, 0, 0);

   this.spdResult.ActiveSheet.Columns[27,30].CellType = datecell;
 }

11 列、单元格锁定

//锁定

this.fpSpread1.ActiveSheet.Columns[0,4].Locked = true;//锁定列范围

this.fpSpread1.ActiveSheet.Columns[0].Locked = true;//锁定单列


//解锁

this.fpSpread1.ActiveSheet.Columns[0,4].Locked = false;//解锁列范围

this.fpSpread1.ActiveSheet.Columns[0].Locked = false;

12 Spread追加行、列

//追加行

int rowindex = this.fpSpread1.ActiveSheet.Rows.Count;
   this.fpSpread1.ActiveSheet.Rows.Add(rowindex,1);

//追加列

int columnindex = this.fpSpread1.ActiveSheet.Columns.Count;
   this.fpSpread1.ActiveSheet.Columns.Add(columnindex,1);

13 行、列删除

//删除行

this.fpSpread1.ActiveSheet.Rows.Remove(startindex,count);

//追加列

this.fpSpread1.ActiveSheet.Columns.Remove(startindex,count);

14 button事件

private void spdSetList_ButtonClicked(object sender, FarPoint.Win.Spread.EditorNotifyEventArgs e)
  {
   int rowCount = e.Row;
   int columnCount = e.Column;

   if (e.Column == 16)
   {
    if (message.ShowMessage("ConfirmDelete", "選択したライン") == DialogResult.Yes)
    {
     string DeleteTag = this.spdSetList.ActiveSheet.Cells[rowCount, columnCount+1].Text.Trim();
     if (DeleteTag == "0" || DeleteTag == "2")
     {
      this.spdSetList.ActiveSheet.Cells[rowCount, columnCount+1].Text = "3";
      this.spdSetList.ActiveSheet.Cells[rowCount,columnCount+1].BackColor = clrWater;
      this.spdSetList.ActiveSheet.Rows[rowCount].Visible = false;
     }
     else if (DeleteTag == "1")
     {
      this.spdSetList.ActiveSheet.Rows[rowCount].Remove();
     }
    }
   }
  }

 
 类似资料: