-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMicrosoftExcel.cs
54 lines (41 loc) · 1.26 KB
/
MicrosoftExcel.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
using Microsoft.Office.Interop.Excel;
using System.Reflection;
namespace MicrosoftExcel {
public class Excel {
Application app = new Application();
Workbook Workbook;
Sheets Sheets;
public Excel(string fn = null) {
if (fn != null) {
FileName = fn;
Workbook = app.Workbooks.Open(FileName);
Sheets = Workbook.Sheets;
}
}
~Excel () {
if (Workbook != null) {
Workbook.Close();
System.Windows.MessageBox.Show("Des");
}
}
readonly object M = Missing.Value;
public string this[int book, int row, int column] {
get {
var sheet = (Worksheet)Sheets.Item[book];
return sheet.Cells[row, column].Value.ToString();
}
}
public string FileName { get; }
public int SheetCount {
get => Sheets.Count;
}
public int RowCount (int sheet) {
var s = (Worksheet)Sheets.Item[sheet];
return s.Rows.Count;
}
public int ColumnCount (int sheet) {
var s = (Worksheet)Sheets.Item[sheet];
return s.Columns.Count;
}
}
}