回复 5楼p332718873的帖子
4# 第一个问题请使用以下代码实现:
- private void button1_Click(object sender, RoutedEventArgs e)
- {
- List<CellRange> list = this.gcSpreadSheet1.Sheets[0].Selections.OrderBy<CellRange, int>(delegate(CellRange item)
- {
- return (item.Column + item.ColumnCount);
- }).Reverse<CellRange>().ToList<CellRange>();
- HashSet<int> set = new HashSet<int>();
- for (int i = 0; i < list.Count; i++)
- {
- CellRange cellRange = list[i];
- int count = 0;
- for (int j = 0; j < cellRange.ColumnCount; j++)
- {
- if (!set.Contains(cellRange.Column + j))
- {
- set.Add(cellRange.Column + j);
- count++;
- }
- }
- this.gcSpreadSheet1.Sheets[0].AddColumns(this.gcSpreadSheet1.Sheets[0].ColumnCount, count);
- this.MoveCellRangeRight(cellRange);
- }
- }
- private void MoveCellRangeRight(CellRange cellRange)
- {
- CellRange range = new CellRange(cellRange.Row, cellRange.Column, cellRange.RowCount, this.gcSpreadSheet1.Sheets[0].ColumnCount - cellRange.Column);
- CellRange range2 = new CellRange(cellRange.Row, cellRange.Column + cellRange.ColumnCount, (this.gcSpreadSheet1.Sheets[0].ColumnCount - cellRange.Column) - cellRange.ColumnCount, cellRange.ColumnCount);
- this.gcSpreadSheet1.Sheets[0].MoveTo(range.Row, range.Column, range2.Row, range2.Column, range.RowCount, range.ColumnCount - cellRange.ColumnCount, CopyToOption.All);
- }
复制代码
请问插入行操作(如同excel中插入行,选择活动单元格下移),这个操作的代码是什么?更改一个枚举值:
- private void button1_Click(object sender, RoutedEventArgs e)
- {
- int activeRowIndex=this.GCSpreadSheet1.Sheets[0].ActiveRowIndex;
- int activeColIndex = this.GCSpreadSheet1.Sheets[0].ActiveColumnIndex;
- //插入行
- //this.GCSpreadSheet1.Sheets[0].AddRows(activeRowIndex, 1);
- this.GCSpreadSheet1.ActiveSheet.AddRows(0, 2, GrapeCity.Windows.SpreadSheet.Data.SheetArea.Cells );
- //活跃单元格下移动
- this.GCSpreadSheet1.Sheets[0].SetActiveCell(activeRowIndex + 1, activeColIndex);
- }
复制代码 |