-
Notifications
You must be signed in to change notification settings - Fork 1
/
RowAndColumnActions.cs
61 lines (50 loc) · 2.54 KB
/
RowAndColumnActions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using System;
using DevExpress.Spreadsheet;
namespace SpreadsheetControl_API_Part03
{
public static class RowAndColumnActions
{
static void DeleteRowsBasedOnCondition(IWorkbook workbook)
{
#region #DeleteRowsBasedOnCondition
workbook.LoadDocument("Documents\\Document.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Create a function specifying the condition to remove worksheet rows.
Func<int, bool> rowRemovalCondition = x => worksheet.Cells[x, 0].Value.NumericValue > 3.0 && worksheet.Cells[x, 0].Value.NumericValue < 14.0;
// Fill cells with data.
for (int i = 0; i < 15; i++)
{
worksheet.Cells[i, 0].Value = i + 1;
worksheet.Cells[0, i].Value = i + 1;
}
// Delete all rows that meet the specified condition.
//worksheet.Rows.Remove(rowRemovalCondition);
// Delete rows that meet the specified condition starting from the 7th row.
worksheet.Rows.Remove(7, rowRemovalCondition);
// Delete rows that meet the specified condition starting from the 5th row to the 14th row.
//worksheet.Rows.Remove(5, 14, rowRemovalCondition);
#endregion #DeleteRowsBasedOnCondition
}
static void DeleteColumnssBasedOnCondition(IWorkbook workbook)
{
#region #DeleteColumnsBasedOnCondition
workbook.LoadDocument("Documents\\Document.xlsx");
Worksheet worksheet = workbook.Worksheets[0];
// Create a function specifying the condition to remove worksheet columns.
Func<int, bool> columnRemovalCondition = x => worksheet.Cells[0, x].Value.NumericValue > 3.0 && worksheet.Cells[0, x].Value.NumericValue < 14.0;
// Fill cells with data.
for (int i = 0; i < 15; i++)
{
worksheet.Cells[i, 0].Value = i + 1;
worksheet.Cells[0, i].Value = i + 1;
}
// Delete all columns that meet the specified condition.
//worksheet.Columns.Remove(columnRemovalCondition);
// Delete columns that meet the specified condition starting from the 7th column.
worksheet.Columns.Remove(7, columnRemovalCondition);
// Delete columns that meet the specified condition starting from the 5th column to the 14th column.
//worksheet.Columns.Remove(5, 14, columnRemovalCondition);
#endregion #DeleteColumnsBasedOnCondition
}
}
}