-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRowColumnHelper.cs
65 lines (50 loc) · 2.06 KB
/
RowColumnHelper.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
62
63
64
65
using iDiTect.Excel.Licensing;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace iDiTect.Excel.Demo
{
public static class RowColumnHelper
{
public static void RowAndColumn()
{
var excelApp = new Application();
var worksheet = excelApp.Workbook.Worksheets.Add("RowAndColumn");
//Insert 1 row from the first row
worksheet.InsertRow(1, 1);
//Select the first row
var row = worksheet.Row(1);
//Set row style
row.Style.Fill.PatternType = Style.FillStyle.Solid;
row.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Yellow);
//height is in units of pounds (1cm = 28.6 pounds)
row.Height = 20;
//Insert 1 column from the sencond column
worksheet.InsertColumn(2, 1);
//Select the second column (Column B)
var column = worksheet.Column(2);
//Set column style
column.Style.Fill.PatternType = Style.FillStyle.Solid;
column.Style.Fill.BackgroundColor.SetColor(System.Drawing.Color.Green);
//width is in units of 1/10 inch (2.54 millimeters)
column.Width = 12;
//Select C2 as a Range
var range1 = worksheet.Cells["C2"];
range1.Value = "this is long text";
range1.AutoFitColumns();
//Get a Range from cells C3:E5
var range2 = worksheet.Cells[3, 3, 5, 5];
range2.Merge = true;
range2.Value = "merged cells";
range2.Style.HorizontalAlignment = Style.HorizontalAlignment.Center;
range2.Style.VerticalAlignment = Style.VerticalAlignment.Center;
//Select all cells in worksheet
var range3 = worksheet.Cells["A: XFD"];
//Set range style
range3.Style.Font.Color.SetColor(System.Drawing.Color.Gray);
excelApp.Save("row-column.xlsx");
}
}
}