-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfrmMaim.cs
80 lines (75 loc) · 2.56 KB
/
frmMaim.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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Spire.Xls;
using Spire.Xls.Core;
using Spire.Xls.Core.Spreadsheet.Shapes;
namespace 干掉Excel多余文本框
{
public partial class frmMaim : Form
{
public frmMaim()
{
InitializeComponent();
}
private void frmMaim_Load(object sender, EventArgs e)
{
Output("程序载入完成,请拖入文件(支持多文件)");
}
private void Output(string text)
{
txtOutput.Text += DateTime.Now.ToString() + " " + text + "\r\n";
}
private void frmMaim_DragDrop(object sender, DragEventArgs e)
{
int i = 0;
while (((System.Array)e.Data.GetData(DataFormats.FileDrop)).Length > i)
{
string filename = ((System.Array)e.Data.GetData(DataFormats.FileDrop)).GetValue(i).ToString();
Output("接收到目标文件:" + filename);
Workbook workbook = new Workbook();
try
{
workbook.LoadFromFile(filename);
}
catch
{
Output("您看看"+filename+"这是Excel文件嘛");
return;
}
Worksheet sheet = workbook.Worksheets[0];
int j = 0;
while (sheet.TextBoxes.Count>j)
{
sheet.TextBoxes[j].Remove();
j++;
}
sheet.Dispose();
GC.Collect();
Output("已经干掉" + j.ToString() + "个文本框");
string newfilename = System.IO.Path.GetDirectoryName(filename) + @"\" + System.IO.Path.GetFileNameWithoutExtension(filename) + "-去文本框.xlsx";
workbook.SaveToFile(newfilename, ExcelVersion.Version2007);
Output("已经保存为新文件:" + newfilename);
workbook.Dispose();
GC.Collect();
i++;
}
Output("任务完毕,共处理"+i.ToString()+"个文件");
}
private void frmMaim_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.All;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
}