-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHelloControl.cs
More file actions
50 lines (41 loc) · 1.68 KB
/
HelloControl.cs
File metadata and controls
50 lines (41 loc) · 1.68 KB
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
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;
using Office = Microsoft.Office.Core;
using Excel = Microsoft.Office.Interop.Excel;
namespace ExcelTests {
partial class HelloControl : UserControl {
public HelloControl() {
InitializeComponent();
}
private void button1_click(object sender, EventArgs e) {
CommonUtils.SwapRowCol();
}
private void HelloControl_Load(object sender, EventArgs e) {
}
private void button2_Click(object sender, EventArgs e) {
//MessageBox.Show("hello world 2");
// 功能:从另外一个表中找数据,然后把它前一列的数据填到自己的前一列
Excel.Range reference = Globals.Sheet2.Range["B2", "B113"];
Excel.Range rg = Globals.ThisWorkbook.Application.Selection;
HashSet<string> changed = new HashSet<string>();
foreach (Excel.Range r in rg) {
Excel.Range refer = reference.Find(r.Value);
if (refer != null) {
Excel.Range leftCell = reference.Worksheet.Cells[refer.Row, refer.Column - 1];
if (leftCell.Value != null) {
int val = (int)leftCell.Value;
//Debug.WriteLine(val);
Excel.Range targetCell = r.Worksheet.Cells[r.Row, r.Column - 1];
targetCell.Value = val;
}
}
}
}
private void button3_click(object sender, EventArgs e) {
MessageBox.Show("hello world 3");
}
}
}