質問するログイン新規登録

質問編集履歴

1

コードを修正・追加しました

2019/04/09 04:07

投稿

rain_x_sun
rain_x_sun

スコア10

title CHANGED
File without changes
body CHANGED
@@ -8,17 +8,53 @@
8
8
  ### 該当のソースコード
9
9
 
10
10
  ```C#
11
+ using System;
12
+ using System.IO;
13
+ using System.Text;
14
+ using System.Text.RegularExpressions;
15
+ using System.Threading;
16
+ using System.Threading.Tasks;
17
+ using System.Web;
18
+ using System.Windows.Forms;
19
+ using ClosedXML.Excel;
20
+
21
+ namespace AuxiliaryTool
22
+ {
23
+
24
+
25
+ public partial class Main : Form
26
+ {
27
+ public int TopCell;
28
+ public int LastCell;
29
+ public int WorkTopCell;
30
+ public int WorkLastCell;
31
+ public string Movie_change_word_default;
32
+ public string Copy_text;
33
+ public string TestXLPath /*= "C:\TestData\contact_test_data\test.xlsx"*/;
11
34
  public IXLWorkbook XLData;
12
35
  public IXLWorksheet WorkXL;
36
+ public int num_ = 5000;
37
+ public Task task;
13
38
 
39
+
14
- private void XLSetup(string a, IXLWorksheet xl)//Excelデータの処理
40
+ public Main()
15
41
  {
16
- WorkXL = XLOpen(a,xl);
42
+ InitializeComponent();
17
- if(WorkXL != null)
43
+ PriInitialize();
44
+ }
45
+
46
+ private void PriInitialize()//起動処理
18
- {
47
+ {
19
- XLDataSet();
48
+ XLSetup(TestXLPath,WorkXL);
49
+ text_main.WatermarkText = "/*省略*/";
50
+ string[] str = { "A", "B", "C", "D","E" };
51
+ CmbObject[] obj_ = new CmbObject[str.Length];
20
- XLInitialize();
52
+ int num__ = 0;
53
+ foreach(String str_ in str){
54
+ obj_[num__] = new CmbObject(num__++, str_);
21
55
  }
56
+ Condition.Items.AddRange(obj_);
57
+ //Condition.SelectedIndex = 0;
22
58
  }
23
59
 
24
60
  private void XLInitialize()
@@ -29,6 +65,47 @@
29
65
  Work_range_max.Text = WorkLastCell.ToString();
30
66
  }
31
67
 
68
+ private string InfoList(int a)//Excel内の情報を読み込む
69
+ {
70
+ int row = a - TopCell + 2;
71
+ if(WorkXL != null)
72
+ {
73
+ Reason.Text = WorkXL.Cell(Cell_row(), 12).Value.ToString();
74
+ return WorkXL.Cell(row,4).Value.ToString() + " " + WorkXL.Cell(row, 5).Value.ToString() + " " + WorkXL.Cell(row, 6).Value.ToString();
75
+ }else { return "#N/A"; }
76
+
77
+ }
78
+
79
+ private int Cell_row()
80
+ {
81
+ return Search_num() - TopCell + 2;
82
+ }
83
+
84
+ private int Cell_row(int a)
85
+ {
86
+ return Search_num() - TopCell + 2 + a;
87
+ }
88
+
89
+ private int Search_num()//現在値を返す
90
+ {
91
+ return decimal.ToInt32(num.Value);
92
+ }
93
+
94
+ private int Search_num(int a)
95
+ {
96
+ return decimal.ToInt32(num.Value) + a;
97
+ }
98
+
99
+ private void XLSetup(string a, IXLWorksheet xl)//Excelデータの処理
100
+ {
101
+ WorkXL = XLOpen(a,xl);
102
+ if(WorkXL != null)
103
+ {
104
+ XLDataSet();
105
+ XLInitialize();
106
+ }
107
+ }
108
+
32
109
  private IXLWorksheet XLOpen(string a,IXLWorksheet xl)//Excelを開く処理
33
110
  {
34
111
  try
@@ -92,16 +169,58 @@
92
169
  {
93
170
 
94
171
  }
95
-
172
+ }
96
173
 
97
174
 
175
+ private void Config()
176
+ {
177
+ Movie_change_word_default = "/*省略*/";
98
178
  }
99
179
 
180
+ private void URL_prev()//前に戻る処理
181
+ {
182
+ num_ = decimal.ToInt32(num.Value);
183
+ if (num.Minimum < num.Value)
184
+ {
185
+ num_--;
186
+ Search_word.Text = InfoList(Search_num() - 1);
187
+ //Reason.Text = WorkXL.Cell(Cell_row(-1),12).Value.ToString();
188
+ }
189
+
190
+ num.Value = num_;
191
+ var task = Task.Run(() => Thread.Sleep(0));
192
+ Thread.Sleep(10);
193
+ if (task.IsCompleted)
194
+ {
195
+ task = XL_save();
196
+ }
197
+ }
198
+
199
+ private void URL_next()//次
200
+ {
201
+ num_ = decimal.ToInt32(num.Value);
202
+ if (num.Maximum > num.Value)
203
+ {
204
+ num_++;
205
+ Search_word.Text = InfoList(Search_num() + 1);
206
+ }
207
+
208
+ num.Value = num_;
209
+ var task = Task.Run(() => Thread.Sleep(0));
210
+ Thread.Sleep(10);
211
+ if (task.IsCompleted)
212
+ {
213
+ task = XL_save();
214
+ }
215
+ }
216
+
100
217
  private Task XL_save()
101
218
  {
102
219
  string str = File_path.Text.ToString();
103
- string path = str.Substring(0, str.Length - 5) + "_cfat" + ".xlsx";
220
+ string path = str.Substring(0, str.Length - 5) + "/*省略*/" + ".xlsx";
104
221
 
222
+ //var task = Task.Run(() => Thread.Sleep(0));
223
+ //Thread.Sleep(100);
105
224
  try
106
225
  {
107
226
  if(task.IsCompleted || task.IsFaulted || task.IsCanceled)
@@ -114,6 +233,7 @@
114
233
  {
115
234
  task = Task.Run(() => XL_save_async(path));
116
235
  }
236
+ //task.Wait();
117
237
  return Task.WhenAll(task);
118
238
  }
119
239
 
@@ -129,8 +249,46 @@
129
249
  XLData = new XLWorkbook(path);
130
250
  //XLSetup(path, WorkXL);
131
251
  return Task.CompletedTask;
252
+ }
253
+
254
+ private void File_path_DragDrop(object sender, DragEventArgs e)
255
+ {
256
+ string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
257
+ XLSetup(files[0], WorkXL);
258
+ File_path.Text = files[0];
259
+ XLData.SaveAs(File_path.Text.ToString().Substring(0, File_path.Text.ToString().Length - 5) + "_cfat" + ".xlsx");
132
260
  }
133
261
 
262
+ private void File_path_DragEnter(object sender, DragEventArgs e)
263
+ {
264
+ if (e.Data.GetDataPresent(DataFormats.FileDrop))
265
+ {
266
+
267
+ // ドラッグ中のファイルやディレクトリの取得
268
+ string[] drags = (string[])e.Data.GetData(DataFormats.FileDrop);
269
+
270
+ foreach (string d in drags)
271
+ {
272
+ if (!System.IO.File.Exists(d))
273
+ {
274
+ // ファイル以外であればイベント・ハンドラを抜ける
275
+ return;
276
+ }
277
+ }
278
+ e.Effect = DragDropEffects.Copy;
279
+ }
280
+ }
281
+
282
+ private void Main_FormClosed(object sender, FormClosedEventArgs e)
283
+ {
284
+ if(XLData != null)
285
+ {
286
+ var task = XL_save();
287
+ task.Wait();
288
+ }
289
+
290
+ }
291
+
134
292
  private void Reason_SelectedIndexChanged(object sender, EventArgs e)
135
293
  {
136
294
  if (WorkXL.Cell(Cell_row(), 12).Value.ToString() != Reason.Text)
@@ -139,5 +297,25 @@
139
297
  }
140
298
  }
141
299
 
300
+ }
142
301
 
302
+ class CmbObject
303
+ {
304
+ public int Key { get; set; }
305
+ public string Value { get; set; }
306
+
307
+ public CmbObject(int Key, string Value)
308
+ {
309
+ this.Key = Key;
310
+ this.Value = Value;
311
+ }
312
+
313
+ public override string ToString()
314
+ {
315
+ return Value;
316
+ }
317
+ }
318
+
319
+ }
320
+ }
143
321
  ```