質問編集履歴

1

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

2019/04/09 04:07

投稿

rain_x_sun
rain_x_sun

スコア10

test CHANGED
File without changes
test CHANGED
@@ -18,10 +18,180 @@
18
18
 
19
19
  ```C#
20
20
 
21
+ using System;
22
+
23
+ using System.IO;
24
+
25
+ using System.Text;
26
+
27
+ using System.Text.RegularExpressions;
28
+
29
+ using System.Threading;
30
+
31
+ using System.Threading.Tasks;
32
+
33
+ using System.Web;
34
+
35
+ using System.Windows.Forms;
36
+
37
+ using ClosedXML.Excel;
38
+
39
+
40
+
41
+ namespace AuxiliaryTool
42
+
43
+ {
44
+
45
+
46
+
47
+
48
+
49
+ public partial class Main : Form
50
+
51
+ {
52
+
53
+ public int TopCell;
54
+
55
+ public int LastCell;
56
+
57
+ public int WorkTopCell;
58
+
59
+ public int WorkLastCell;
60
+
61
+ public string Movie_change_word_default;
62
+
63
+ public string Copy_text;
64
+
65
+ public string TestXLPath /*= "C:\TestData\contact_test_data\test.xlsx"*/;
66
+
21
67
  public IXLWorkbook XLData;
22
68
 
23
69
  public IXLWorksheet WorkXL;
24
70
 
71
+ public int num_ = 5000;
72
+
73
+ public Task task;
74
+
75
+
76
+
77
+
78
+
79
+ public Main()
80
+
81
+ {
82
+
83
+ InitializeComponent();
84
+
85
+ PriInitialize();
86
+
87
+ }
88
+
89
+
90
+
91
+ private void PriInitialize()//起動処理
92
+
93
+ {
94
+
95
+ XLSetup(TestXLPath,WorkXL);
96
+
97
+ text_main.WatermarkText = "/*省略*/";
98
+
99
+ string[] str = { "A", "B", "C", "D","E" };
100
+
101
+ CmbObject[] obj_ = new CmbObject[str.Length];
102
+
103
+ int num__ = 0;
104
+
105
+ foreach(String str_ in str){
106
+
107
+ obj_[num__] = new CmbObject(num__++, str_);
108
+
109
+ }
110
+
111
+ Condition.Items.AddRange(obj_);
112
+
113
+ //Condition.SelectedIndex = 0;
114
+
115
+ }
116
+
117
+
118
+
119
+ private void XLInitialize()
120
+
121
+ {
122
+
123
+ num.Value = WorkTopCell;
124
+
125
+ Search_word.Text = InfoList(Search_num());
126
+
127
+ Work_range_min.Text = WorkTopCell.ToString();
128
+
129
+ Work_range_max.Text = WorkLastCell.ToString();
130
+
131
+ }
132
+
133
+
134
+
135
+ private string InfoList(int a)//Excel内の情報を読み込む
136
+
137
+ {
138
+
139
+ int row = a - TopCell + 2;
140
+
141
+ if(WorkXL != null)
142
+
143
+ {
144
+
145
+ Reason.Text = WorkXL.Cell(Cell_row(), 12).Value.ToString();
146
+
147
+ return WorkXL.Cell(row,4).Value.ToString() + " " + WorkXL.Cell(row, 5).Value.ToString() + " " + WorkXL.Cell(row, 6).Value.ToString();
148
+
149
+ }else { return "#N/A"; }
150
+
151
+
152
+
153
+ }
154
+
155
+
156
+
157
+ private int Cell_row()
158
+
159
+ {
160
+
161
+ return Search_num() - TopCell + 2;
162
+
163
+ }
164
+
165
+
166
+
167
+ private int Cell_row(int a)
168
+
169
+ {
170
+
171
+ return Search_num() - TopCell + 2 + a;
172
+
173
+ }
174
+
175
+
176
+
177
+ private int Search_num()//現在値を返す
178
+
179
+ {
180
+
181
+ return decimal.ToInt32(num.Value);
182
+
183
+ }
184
+
185
+
186
+
187
+ private int Search_num(int a)
188
+
189
+ {
190
+
191
+ return decimal.ToInt32(num.Value) + a;
192
+
193
+ }
194
+
25
195
 
26
196
 
27
197
  private void XLSetup(string a, IXLWorksheet xl)//Excelデータの処理
@@ -44,22 +214,6 @@
44
214
 
45
215
 
46
216
 
47
- private void XLInitialize()
48
-
49
- {
50
-
51
- num.Value = WorkTopCell;
52
-
53
- Search_word.Text = InfoList(Search_num());
54
-
55
- Work_range_min.Text = WorkTopCell.ToString();
56
-
57
- Work_range_max.Text = WorkLastCell.ToString();
58
-
59
- }
60
-
61
-
62
-
63
217
  private IXLWorksheet XLOpen(string a,IXLWorksheet xl)//Excelを開く処理
64
218
 
65
219
  {
@@ -186,80 +340,242 @@
186
340
 
187
341
  }
188
342
 
343
+ }
344
+
345
+
346
+
347
+
348
+
349
+ private void Config()
350
+
351
+ {
352
+
353
+ Movie_change_word_default = "/*省略*/";
354
+
355
+ }
356
+
357
+
358
+
359
+ private void URL_prev()//前に戻る処理
360
+
361
+ {
362
+
363
+ num_ = decimal.ToInt32(num.Value);
364
+
365
+ if (num.Minimum < num.Value)
366
+
367
+ {
368
+
369
+ num_--;
370
+
371
+ Search_word.Text = InfoList(Search_num() - 1);
372
+
373
+ //Reason.Text = WorkXL.Cell(Cell_row(-1),12).Value.ToString();
374
+
375
+ }
376
+
377
+
378
+
379
+ num.Value = num_;
380
+
381
+ var task = Task.Run(() => Thread.Sleep(0));
382
+
383
+ Thread.Sleep(10);
384
+
385
+ if (task.IsCompleted)
386
+
387
+ {
388
+
389
+ task = XL_save();
390
+
391
+ }
392
+
393
+ }
394
+
395
+
396
+
397
+ private void URL_next()//次
398
+
399
+ {
400
+
401
+ num_ = decimal.ToInt32(num.Value);
402
+
403
+ if (num.Maximum > num.Value)
404
+
405
+ {
406
+
407
+ num_++;
408
+
409
+ Search_word.Text = InfoList(Search_num() + 1);
410
+
411
+ }
412
+
413
+
414
+
415
+ num.Value = num_;
416
+
417
+ var task = Task.Run(() => Thread.Sleep(0));
418
+
419
+ Thread.Sleep(10);
420
+
421
+ if (task.IsCompleted)
422
+
423
+ {
424
+
425
+ task = XL_save();
426
+
427
+ }
428
+
429
+ }
430
+
431
+
432
+
433
+ private Task XL_save()
434
+
435
+ {
436
+
437
+ string str = File_path.Text.ToString();
438
+
439
+ string path = str.Substring(0, str.Length - 5) + "/*省略*/" + ".xlsx";
440
+
441
+
442
+
443
+ //var task = Task.Run(() => Thread.Sleep(0));
444
+
445
+ //Thread.Sleep(100);
446
+
447
+ try
448
+
449
+ {
450
+
451
+ if(task.IsCompleted || task.IsFaulted || task.IsCanceled)
452
+
453
+ {
454
+
455
+ task = Task.Run(() => XL_save_async(path));
456
+
457
+ }
458
+
459
+
460
+
461
+ }
462
+
463
+ catch (NullReferenceException)
464
+
465
+ {
466
+
467
+ task = Task.Run(() => XL_save_async(path));
468
+
469
+ }
470
+
471
+ //task.Wait();
472
+
473
+ return Task.WhenAll(task);
474
+
475
+ }
476
+
477
+
478
+
479
+ private Task XL_save_async(string path)
480
+
481
+ {
482
+
483
+ App_status.Text = "セーブ中";
484
+
485
+ XLData.SaveAs(path);
486
+
487
+ if (path != File_path.Text.ToString())
488
+
489
+ {
490
+
491
+
492
+
493
+ }
494
+
495
+ App_status.Text = "セーブ完了";
496
+
497
+ XLData = new XLWorkbook(path);
498
+
499
+ //XLSetup(path, WorkXL);
500
+
501
+ return Task.CompletedTask;
502
+
503
+ }
504
+
505
+
506
+
507
+ private void File_path_DragDrop(object sender, DragEventArgs e)
508
+
509
+ {
510
+
511
+ string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
512
+
513
+ XLSetup(files[0], WorkXL);
514
+
515
+ File_path.Text = files[0];
516
+
517
+ XLData.SaveAs(File_path.Text.ToString().Substring(0, File_path.Text.ToString().Length - 5) + "_cfat" + ".xlsx");
518
+
519
+ }
520
+
521
+
522
+
523
+ private void File_path_DragEnter(object sender, DragEventArgs e)
524
+
525
+ {
526
+
527
+ if (e.Data.GetDataPresent(DataFormats.FileDrop))
528
+
529
+ {
530
+
531
+
532
+
533
+ // ドラッグ中のファイルやディレクトリの取得
534
+
535
+ string[] drags = (string[])e.Data.GetData(DataFormats.FileDrop);
536
+
537
+
538
+
539
+ foreach (string d in drags)
540
+
541
+ {
542
+
543
+ if (!System.IO.File.Exists(d))
544
+
545
+ {
546
+
547
+ // ファイル以外であればイベント・ハンドラを抜ける
548
+
549
+ return;
550
+
551
+ }
552
+
553
+ }
554
+
555
+ e.Effect = DragDropEffects.Copy;
556
+
557
+ }
558
+
559
+ }
560
+
561
+
562
+
563
+ private void Main_FormClosed(object sender, FormClosedEventArgs e)
564
+
565
+ {
566
+
567
+ if(XLData != null)
568
+
569
+ {
570
+
571
+ var task = XL_save();
572
+
573
+ task.Wait();
574
+
575
+ }
576
+
189
577
 
190
578
 
191
-
192
-
193
-
194
-
195
- }
196
-
197
-
198
-
199
- private Task XL_save()
200
-
201
- {
202
-
203
- string str = File_path.Text.ToString();
204
-
205
- string path = str.Substring(0, str.Length - 5) + "_cfat" + ".xlsx";
206
-
207
-
208
-
209
- try
210
-
211
- {
212
-
213
- if(task.IsCompleted || task.IsFaulted || task.IsCanceled)
214
-
215
- {
216
-
217
- task = Task.Run(() => XL_save_async(path));
218
-
219
- }
220
-
221
-
222
-
223
- }
224
-
225
- catch (NullReferenceException)
226
-
227
- {
228
-
229
- task = Task.Run(() => XL_save_async(path));
230
-
231
- }
232
-
233
- return Task.WhenAll(task);
234
-
235
- }
236
-
237
-
238
-
239
- private Task XL_save_async(string path)
240
-
241
- {
242
-
243
- App_status.Text = "セーブ中";
244
-
245
- XLData.SaveAs(path);
246
-
247
- if (path != File_path.Text.ToString())
248
-
249
- {
250
-
251
-
252
-
253
- }
254
-
255
- App_status.Text = "セーブ完了";
256
-
257
- XLData = new XLWorkbook(path);
258
-
259
- //XLSetup(path, WorkXL);
260
-
261
- return Task.CompletedTask;
262
-
263
579
  }
264
580
 
265
581
 
@@ -280,6 +596,46 @@
280
596
 
281
597
 
282
598
 
283
-
599
+ }
600
+
601
+
602
+
603
+ class CmbObject
604
+
605
+ {
606
+
607
+ public int Key { get; set; }
608
+
609
+ public string Value { get; set; }
610
+
611
+
612
+
613
+ public CmbObject(int Key, string Value)
614
+
615
+ {
616
+
617
+ this.Key = Key;
618
+
619
+ this.Value = Value;
620
+
621
+ }
622
+
623
+
624
+
625
+ public override string ToString()
626
+
627
+ {
628
+
629
+ return Value;
630
+
631
+ }
632
+
633
+ }
634
+
635
+
636
+
637
+ }
638
+
639
+ }
284
640
 
285
641
  ```