1.獲得當前行的行號,列號,總列數,總行數
int rowCount = fpSpread1.ActiveSheet.RowCount;
int colCount = fpSpread1.ActiveSheet.Columns.Count;
int activeRow = fpSpread1.ActiveSheet.ActiveRowIndex;
int activeCol = fpSpread1.ActiveSheet.ActiveColumnIndex;
2.設定儲存格格式時候用 MultiColumnComboBoxCellType 是注意:只能用字元類型欄位的選擇。要想用數字欄位選擇的話須將數字類型轉換為字元型即可。
Code
FarPoint.Win.Spread.CellType.MultiColumnComboBoxCellType mCombox = new FarPoint.Win.Spread.CellType.MultiColumnComboBoxCellType();
mCombox.ColumnEditName = "customerCode";
mCombox.DataColumnName = "customerCode";
mCombox.ListWidth = 556;
mCombox.MaxDrop = 8;
mCombox.DataSourceList = dataset;
fpSpread1.ActiveSheet.Columns[0].Label = "customerCode";
fpSpread1.ActiveSheet.Columns[0].CellType = mCombox;
3.問題:當下拉mCombox 中的資料少時會出現空白儲存格,目前還不知道咋回事!
4.增加和刪除行
fpSpread1.ActiveSheet.Rows.Add(rowCount, rows);rowCount是添加行的起始位置,rows是添加的行數。
fpSpread1.ActiveSheet.Rows.Remove(rowCount, rows);rowCount是刪除行的起始位置,rows刪除的行數。
5.
if (fpSpread1.ActiveSheet.ActiveRow.Index == fpSpread1.ActiveSheet.RowCount - 1) //如果是到最後一行則增加一行
{
if (e.KeyCode == Keys.Down)
{
DetailAdd();
}
}
if (e.KeyCode == Keys.Delete) //按delete鍵可刪除當前活動單元格內容
{
fpSpread1.ActiveSheet.ActiveCell.ResetValue();
}
if (e.KeyCode == Keys.Enter) //按Enter鍵跳到下一單元格
{
int rowCount = fpSpread1.ActiveSheet.RowCount;
int colCount = fpSpread1.ActiveSheet.Columns.Count;
int activeRow = fpSpread1.ActiveSheet.ActiveRowIndex;
int activeCol = fpSpread1.ActiveSheet.ActiveColumnIndex;
if (activeCol != (colCount-1))
{
fpSpread1.ActiveSheet.SetActiveCell(activeRow, activeCol + 1);
}
else if( activeRow != (rowCount - 1))
{
fpSpread1.ActiveSheet.SetActiveCell(activeRow+1,0);
}
}
6.移除選擇的多行
int rowCount = fpSpread1.ActiveSheet.RowCount;
for (int row = 0; row < rowCount; row++) //移除選擇行
{
if (fpSpread1.ActiveSheet.IsSelected(row, 1) == true)
{ fpSpread1.ActiveSheet.Rows.Remove(row, 1); }
}
7.剪下,複製,粘貼
//剪下:
FarPoint.Win.Spread.UndoRedo.ClipboardCutUndoAction cutAction = new FarPoint.Win.Spread.UndoRedo.ClipboardCutUndoAction();
fpSpread1.UndoManager.PerformUndoAction(cutAction);
//複製
detail.ActiveSheet.ClipboardCopy();
//粘貼
FarPoint.Win.Spread.UndoRedo.ClipboardPasteUndoAction pasteAction = new FarPoint.Win.Spread.UndoRedo.ClipboardPasteUndoAction(ClipboardPasteOptions.All);
detail.UndoManager.PerformUndoAction(pasteAction);
Code
SheetView sv = fpSpread1.ActiveSheet;
if (sv == null)
return;
int activeRow = sv.ActiveRowIndex;
int activeColumn = sv.ActiveColumnIndex;
if (sender == menuCut) //剪下
{
FarPoint.Win.Spread.UndoRedo.ClipboardCutUndoAction cutAction = new FarPoint.Win.Spread.UndoRedo.ClipboardCutUndoAction();
fpSpread1.UndoManager.PerformUndoAction(cutAction);
}
else if (sender == menuCopy) //複製
{
sv.ClipboardCopy();
}
else if (sender == menuPaste) //粘貼
{
FarPoint.Win.Spread.UndoRedo.ClipboardPasteUndoAction pasteAction = new FarPoint.Win.Spread.UndoRedo.ClipboardPasteUndoAction(ClipboardPasteOptions.All);
fpSpread1.UndoManager.PerformUndoAction(pasteAction);
}
else if (sender == menuInsertRow) //插入一行
{
sv.Rows.Add(activeRow, 1);
}
else if (sender == menuInsertColumn)//插入一列
{
sv.Columns.Add(activeColumn, 1);
}
else if (sender == menuRemoveRow)//刪除一行
{
sv.Rows.Remove(activeRow, 1);
}
else if (sender == menuRemoveColumn)//刪除一列
{
sv.Columns.Remove(activeColumn, 1);
}
else if (sender == menuClearContents) //清除內容
{
FarPoint.Win.Spread.UndoRedo.ClipboardCutUndoAction cutAction = new FarPoint.Win.Spread.UndoRedo.ClipboardCutUndoAction();
fpSpread1.UndoManager.PerformUndoAction(cutAction);
}
8.撤銷,恢複
Code
//撤銷
FarPoint.Win.Spread.InputMap im;
im = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused);
im.Put(new FarPoint.Win.Spread.Keystroke(Keys.U, Keys.None), FarPoint.Win.Spread.SpreadActions.Undo);
//恢複
FarPoint.Win.Spread.InputMap im;
im = fpSpread1.GetInputMap(FarPoint.Win.Spread.InputMapMode.WhenAncestorOfFocused);
im.Put(new FarPoint.Win.Spread.Keystroke(Keys.E, Keys.None), FarPoint.Win.Spread.SpreadActions.Redo);
9.Find,Filter,Sort
Code
//允許列排序
this.fpSpread1_Sheet1.Columns.Get(0).AllowAutoSort = true;
//允許列過濾
fpSpread1.ActiveSheet.Columns.Get(1).AllowAutoFilter = true;
//尋找
fpSpread1.SearchWithDialogAdvanced(0, 4, "This", true, true, false, false, 0, 0);