-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonUtils.cs
More file actions
33 lines (28 loc) · 1.03 KB
/
CommonUtils.cs
File metadata and controls
33 lines (28 loc) · 1.03 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
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;
using System.Diagnostics;
using Microsoft.Office.Tools.Excel;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Excel = Microsoft.Office.Interop.Excel;
using Office = Microsoft.Office.Core;
namespace ExcelTests {
public class CommonUtils {
public static void SwapRowCol() {
Excel.Range rg = Globals.ThisWorkbook.Application.Selection;
HashSet<string> changed = new HashSet<string>();
foreach (Excel.Range r in rg) {
if (r.Row == r.Column || changed.Contains(r.Address)) continue;
Excel.Range toChange = Globals.ThisWorkbook.Application.ActiveSheet.Cells[r.Column, r.Row];
var val = toChange.Value;
toChange.Value = r.Value;
r.Value = val;
changed.Add(toChange.Address);
}
}
}
}