質問編集履歴

5

追記

2019/02/01 04:15

投稿

cutedog
cutedog

スコア177

test CHANGED
File without changes
test CHANGED
@@ -72,17 +72,19 @@
72
72
 
73
73
 
74
74
 
75
- LIST<T>使うっいうのはこういことですか?
75
+ List形式からObject[,]への変換まで書いみました。
76
+
77
+ なんとかできました。ありがとうございました。
76
78
 
77
79
  ```C#
78
80
 
79
- IList<Object[]> objList = new List<Object[]>();
81
+ var objList = new List<List<object>>();
80
-
82
+
81
- objList.Add(new object[] { "UniqId", "UniqId", 70, false, 11111, 22222, "LABEL_CHAR" });
83
+ objList.Add(new List<object>() { "UniqId", "UniqId", 70, false, 11111, 22222, "LABEL_CHAR" });
82
-
84
+
83
- objList.Add(new object[] { "職員名", "ShokuinName", 320, true, 11111, 22222, "LABEL_CHAR" });
85
+ objList.Add(new List<object>() { "職員名", "ShokuinName", 320, true, 11111, 22222, "LABEL_CHAR" });
84
-
86
+
85
- objList.Add(new object[] { "科目コード", "AAA", 80, true, 11111, 22222, "MONEY" });
87
+ objList.Add(new List<object>() { "科目コード", "AAA", 80, true, 11111, 22222, "MONEY" });
86
88
 
87
89
 
88
90
 
@@ -90,31 +92,193 @@
90
92
 
91
93
  {
92
94
 
93
-
94
-
95
+
96
+
95
- objList.Add(new object[] { "ほげほげ" + i, "Hogehoge" + i, 80, true, 11111, 22222, "MONEY" });
97
+ objList.Add(new List<object>() { "ほげほげ" + i, "Hogehoge" + i, 80, true, 11111, 22222, "MONEY" });
96
98
 
97
99
 
98
100
 
99
101
  }
100
102
 
103
+
104
+
105
+ //これだとObject[][]になってしまう
106
+
107
+ //var parsedList = objList
108
+
109
+ // .Select(val => val
110
+
111
+ // .Select(val2 => val2).ToArray()
112
+
113
+ // ).ToArray();
114
+
115
+
116
+
117
+ var rowCount = objList.Count;
118
+
119
+ var colCount = 7;
120
+
121
+
122
+
123
+ var r = new Object[objList.Count, 7];
124
+
125
+
126
+
127
+ for (int y = 0; y < rowCount; y++)
128
+
129
+ {
130
+
131
+ var src = objList[y];
132
+
133
+ for (int x = 0; x < colCount; x++)
134
+
135
+ {
136
+
137
+ r[y, x] = objList[x];
138
+
139
+ }
140
+
141
+ }
142
+
101
143
  ```
102
144
 
103
145
 
104
146
 
105
- List形式からObject[,]への変換までを書いてみました。
106
-
107
- なんとかできまた。ありがとうございました。
147
+ 実装てみました。
148
+
149
+ うまくいきました。
108
150
 
109
151
  ```C#
110
152
 
111
- var objList = new List<List<object>>();
112
-
113
- objList.Add(new List<object>() { "UniqId", "UniqId", 70, false, 11111, 22222, "LABEL_CHAR" });
114
-
115
- objList.Add(new List<object>() { "職員名", "ShokuinName", 320, true, 11111, 22222, "LABEL_CHAR" });
116
-
117
- objList.Add(new List<object>() { "科目コード", "AAA", 80, true, 11111, 22222, "MONEY" });
153
+
154
+
155
+ using System;
156
+
157
+ using System.Collections.Generic;
158
+
159
+ using System.Linq;
160
+
161
+ using System.Text;
162
+
163
+ using System.Threading.Tasks;
164
+
165
+
166
+
167
+ namespace WindowsFormsApplication1
168
+
169
+ {
170
+
171
+ public class Poco
172
+
173
+ {
174
+
175
+ public string Name;
176
+
177
+ public string Id;
178
+
179
+ public int Width;
180
+
181
+ public bool IsValid;
182
+
183
+ public int Valign;
184
+
185
+ public int Halign;
186
+
187
+ public string Label;
188
+
189
+ public Poco(string name, string id, int width, bool isvalid, int valign, int halign, string label)
190
+
191
+ {
192
+
193
+ Name = name; Id = id; Width = width; IsValid = isvalid; Valign = valign; Halign = halign; Label = label;
194
+
195
+ }
196
+
197
+
198
+
199
+
200
+
201
+ public static IList<Poco> ToList(object[,] hatchpotch)
202
+
203
+ {
204
+
205
+ var innerLen = 7;
206
+
207
+ var outerLen = hatchpotch.Length / innerLen;
208
+
209
+ return Enumerable.Range(0, outerLen).Select(i => new Poco((string)hatchpotch[i, 0], (string)hatchpotch[i, 1], (int)hatchpotch[i, 2], (bool)hatchpotch[i, 3], (int)hatchpotch[i, 4], (int)hatchpotch[i, 5], (string)hatchpotch[i, 6])).ToList();
210
+
211
+ }
212
+
213
+
214
+
215
+ public static object[,] ToRect(IList<Poco> data) //理解しやすくするためList<Poco>としてます。実用では副作用に注意しましょう
216
+
217
+ {
218
+
219
+ var ret = new object[data.Count(), 7];
220
+
221
+ for (var i = 0; i < data.Count(); i++)
222
+
223
+ {
224
+
225
+ ret[i, 0] = (object)data[i].Name;
226
+
227
+ ret[i, 1] = (object)data[i].Id;
228
+
229
+ ret[i, 2] = (object)data[i].Width;
230
+
231
+ ret[i, 3] = (object)data[i].IsValid;
232
+
233
+ ret[i, 4] = (object)data[i].Valign;
234
+
235
+ ret[i, 5] = (object)data[i].Halign;
236
+
237
+ ret[i, 6] = (object)data[i].Label;
238
+
239
+ }
240
+
241
+ return ret;
242
+
243
+ }
244
+
245
+
246
+
247
+
248
+
249
+ }
250
+
251
+
252
+
253
+ }
254
+
255
+
256
+
257
+
258
+
259
+
260
+
261
+ //実行部
262
+
263
+ sub main()
264
+
265
+ {
266
+
267
+ Object[,] Obj = {
268
+
269
+ { "UniqId", "UniqId", 70, false, 11111, 22222, "LABEL_CHAR" },
270
+
271
+ { "職員名", "ShokuinName", 320, true, 11111, 22222, "LABEL_CHAR" },
272
+
273
+ { "科目コード", "AAA", 80, true, 11111, 22222, "MONEY" },
274
+
275
+ };
276
+
277
+
278
+
279
+ IList<Poco> PocoList = Poco.ToList(Obj);
280
+
281
+
118
282
 
119
283
 
120
284
 
@@ -122,334 +286,270 @@
122
286
 
123
287
  {
124
288
 
125
-
126
-
127
- objList.Add(new List<object>() { "ほげほげ" + i, "Hogehoge" + i, 80, true, 11111, 22222, "MONEY" });
289
+ Poco _Poco = new Poco("ほげほげ" + i, "Hogehoge" + i, 80, true, 11111, 22222, "MONEY");
290
+
128
-
291
+ PocoList.Add(_Poco);
129
-
130
292
 
131
293
  }
132
294
 
133
295
 
134
296
 
135
- //これだとObject[][]になってしまう
136
-
137
- //var parsedList = objList
138
-
139
- // .Select(val => val
140
-
141
- // .Select(val2 => val2).ToArray()
142
-
143
- // ).ToArray();
144
-
145
-
146
-
147
- var rowCount = objList.Count;
148
-
149
- var colCount = 7;
150
-
151
-
152
-
153
- var r = new Object[objList.Count, 7];
154
-
155
-
156
-
157
- for (int y = 0; y < rowCount; y++)
297
+
298
+
299
+ Object[,] Obj2 = Poco.ToRect(PocoList);
300
+
301
+ }
302
+
303
+
304
+
305
+ ```
306
+
307
+ 元々コボラーの独学なので
308
+
309
+ 低レベルなコーディングでお目汚しですが
310
+
311
+ 毎回、案件ごとにSPREAD定義を一から書くのが億劫だったので
312
+
313
+ SPREAD for WinFormsもASP.NETでも同じように
314
+
315
+ 以下のような関数に[,]を食わせて定義してます。
316
+
317
+ ```C#
318
+
319
+ /// <summary>
320
+
321
+ /// スプレッドシート設定
322
+
323
+ /// </summary>
324
+
325
+ /// <param name="sheet"></param>
326
+
327
+ /// <param name="hd"></param>
328
+
329
+ /// <param name="FrozenColumnCount"></param>
330
+
331
+ /// <param name="FrozenRowCount"></param>
332
+
333
+ /// <param name="rowHeader"></param>
334
+
335
+ /// <param name="columnHeader"></param>
336
+
337
+ /// <param name="allowGroup"></param>
338
+
339
+ /// <param name="columnHeaderSet"></param>
340
+
341
+ /// <param name="AlternatingSw"></param>
342
+
343
+ public void InitSpreadStyles(FarPoint.Web.Spread.SheetView sheet,
344
+
345
+ Object[,] hd = null,
346
+
347
+ int FrozenColumnCount = 0,
348
+
349
+ int FrozenRowCount = 0,
350
+
351
+ Boolean rowHeader = true,
352
+
353
+ Boolean columnHeader = true,
354
+
355
+ Boolean allowGroup = false,
356
+
357
+ Boolean columnHeaderSet = true,
358
+
359
+ Boolean AlternatingSw = true)
360
+
361
+ {
362
+
363
+
364
+
365
+ FarPoint.Web.Spread.Inset mg = new FarPoint.Web.Spread.Inset(3, 0, 3, 0);
366
+
367
+
368
+
369
+ // 余白の設定をシートに適用
370
+
371
+ sheet.DefaultStyle.Margin = mg;
372
+
373
+
374
+
375
+ sheet.GridLines = GridLines.Both;
376
+
377
+
378
+
379
+ sheet.DefaultStyle.Border.BorderColor = Color.LightBlue;
380
+
381
+ sheet.DefaultStyle.Border.BorderSize = 1;
382
+
383
+ sheet.DefaultStyle.Border.BorderStyle = BorderStyle.Solid;
384
+
385
+
386
+
387
+ //選択行の色
388
+
389
+ sheet.SelectionBackColor = System.Drawing.Color.Silver;
390
+
391
+
392
+
393
+ // 縦方向の揃え位置を中央に設定
394
+
395
+ sheet.DefaultStyle.VerticalAlign = VerticalAlign.Middle;
396
+
397
+
398
+
399
+ //バインドしたデータでのカラム作成を抑止する
400
+
401
+ sheet.AutoGenerateColumns = false;
402
+
403
+
404
+
405
+ //カラム移動を可能にする
406
+
407
+ sheet.AllowColumnMove = false;
408
+
409
+
410
+
411
+ if (hd != null)
158
412
 
159
413
  {
160
414
 
415
+ //カラムを作成
416
+
161
- var src = objList[y];
417
+ sheet.ColumnCount = hd.GetLength(0);
162
-
418
+
163
- for (int x = 0; x < colCount; x++)
419
+ for (int x = 0; x <= hd.GetLength(0) - 1; ++x)
164
420
 
165
421
  {
166
422
 
423
+ if (columnHeaderSet)
424
+
425
+ {
426
+
427
+ // カラムヘッダを設定します。
428
+
429
+ sheet.ColumnHeader.Cells[0, x].Text = (String)hd[x, 0];
430
+
431
+ }
432
+
433
+
434
+
435
+ sheet.Columns[x].DataField = (String)hd[x, 1];
436
+
437
+
438
+
439
+ sheet.Columns[x].Width = (int)hd[x, 2];
440
+
441
+
442
+
443
+ sheet.Columns[x].Visible = (Boolean)hd[x, 3];
444
+
445
+
446
+
447
+ sheet.Columns[x].VerticalAlign = (VerticalAlign)hd[x, 4];
448
+
449
+
450
+
451
+ sheet.Columns[x].HorizontalAlign = (HorizontalAlign)hd[x, 5];
452
+
453
+
454
+
455
+ sheet.Columns[x].Font.Name = "Meiryo UI";
456
+
457
+
458
+
459
+ //セルタイプをセット
460
+
167
- r[y, x] = objList[x];
461
+ String cellType = (String)hd[x, 6];
462
+
463
+
464
+
465
+ if (String.IsNullOrEmpty(cellType))
466
+
467
+ {
468
+
469
+ sheet.Columns[x].CanFocus = false;
470
+
471
+ sheet.Columns[x].Locked = true;
472
+
473
+ }
474
+
475
+
476
+
477
+ if ("LABEL_NUM".Equals(cellType))
478
+
479
+ {
480
+
481
+ LabelCellType celltype = new LabelCellType();
482
+
483
+ celltype.AllowWrap = false;
484
+
485
+ sheet.Columns[x].CellType = celltype;
486
+
487
+ }
488
+
489
+
490
+
491
+
492
+
493
+ ・いろんなcelltypeの設定を定義してます
494
+
495
+
496
+
497
+
498
+
499
+
500
+
501
+
168
502
 
169
503
  }
170
504
 
171
505
  }
172
506
 
507
+
508
+
509
+ // グルーピング設定
510
+
511
+ sheet.AllowGroup = allowGroup;
512
+
513
+ sheet.GroupBarVisible = allowGroup;
514
+
515
+
516
+
517
+ if (AlternatingSw)
518
+
519
+ {
520
+
521
+ // 1行おきにスタイルを設定します
522
+
523
+ sheet.AlternatingRows.Count = 2;
524
+
525
+ System.Drawing.Color fc = System.Drawing.Color.FromName("OldLace");
526
+
527
+ sheet.AlternatingRows[1].BackColor = fc;
528
+
529
+ }
530
+
531
+
532
+
533
+ // 行ヘッダ表示制御
534
+
535
+ sheet.RowHeader.Visible = rowHeader;
536
+
537
+ // 列ヘッダ表示制御
538
+
539
+ sheet.ColumnHeader.Visible = columnHeader;
540
+
541
+ // 列の固定
542
+
543
+ sheet.FrozenColumnCount = FrozenColumnCount;
544
+
545
+ // 行の固定
546
+
547
+ sheet.FrozenRowCount = FrozenRowCount;
548
+
549
+
550
+
551
+
552
+
553
+ }
554
+
173
555
  ```
174
-
175
-
176
-
177
- こちらの環境へコピペしてみましたが
178
-
179
- Enumerableでエラーがでます。なにか足らない??
180
-
181
- ```C#
182
-
183
- using System;
184
-
185
- using System.Collections.Generic;
186
-
187
- using System.Linq;
188
-
189
- using System.Text;
190
-
191
- using System.Threading.Tasks;
192
-
193
-
194
-
195
- namespace WindowsFormsApplication1
196
-
197
- {
198
-
199
- public class Poco
200
-
201
- {
202
-
203
- public string Name;
204
-
205
- public string Id;
206
-
207
- public int Width;
208
-
209
- public bool IsValid;
210
-
211
- public int Valign;
212
-
213
- public int Halign;
214
-
215
- public string Label;
216
-
217
- public Poco(string name, string id, int width, bool isvalid, int valign, int halign, string label)
218
-
219
- {
220
-
221
- Name = name; Id = id; Width = width; IsValid = isvalid; Valign = valign; Halign = halign; Label = label;
222
-
223
- }
224
-
225
-
226
-
227
-
228
-
229
- public List<Poco> ToList(object[,] hatchpotch)
230
-
231
- {
232
-
233
- var innerLen = 7;
234
-
235
- var outerLen = hatchpotch.Length / innerLen;
236
-
237
- return Enumerable(0, outerLen).Select(i => new Poco((string)hatchpotch[i, 0], (string)hatchpotch[i, 1], (int)hatchpotch[i, 2], (bool)hatchpotch[i, 3], (int)hatchpotch[i, 4], (int)hatchpotch[i, 5], (string)hatchpotch[i, 6])).ToList();
238
-
239
- }
240
-
241
-
242
-
243
- public object[,] ToRect(List<Poco> data) //理解しやすくするためList<Poco>としてます。実用では副作用に注意しましょう
244
-
245
- {
246
-
247
- var ret = new object[data.Count(), 7];
248
-
249
- for (var i = 0; i < data.Count(); i++)
250
-
251
- {
252
-
253
- ret[i, 0] = (object)data[i].Name;
254
-
255
- ret[i, 1] = (object)data[i].Id;
256
-
257
- ret[i, 2] = (object)data[i].Width;
258
-
259
- ret[i, 3] = (object)data[i].IsValid;
260
-
261
- ret[i, 4] = (object)data[i].Valign;
262
-
263
- ret[i, 5] = (object)data[i].Halign;
264
-
265
- ret[i, 6] = (object)data[i].Label;
266
-
267
- }
268
-
269
- return ret;
270
-
271
- }
272
-
273
-
274
-
275
-
276
-
277
- }
278
-
279
-
280
-
281
-
282
-
283
-
284
-
285
-
286
-
287
- }
288
-
289
-
290
-
291
- ```
292
-
293
-
294
-
295
-
296
-
297
- 実装してみました。
298
-
299
- うまくいきました。
300
-
301
- ```C#
302
-
303
-
304
-
305
- using System;
306
-
307
- using System.Collections.Generic;
308
-
309
- using System.Linq;
310
-
311
- using System.Text;
312
-
313
- using System.Threading.Tasks;
314
-
315
-
316
-
317
- namespace WindowsFormsApplication1
318
-
319
- {
320
-
321
- public class Poco
322
-
323
- {
324
-
325
- public string Name;
326
-
327
- public string Id;
328
-
329
- public int Width;
330
-
331
- public bool IsValid;
332
-
333
- public int Valign;
334
-
335
- public int Halign;
336
-
337
- public string Label;
338
-
339
- public Poco(string name, string id, int width, bool isvalid, int valign, int halign, string label)
340
-
341
- {
342
-
343
- Name = name; Id = id; Width = width; IsValid = isvalid; Valign = valign; Halign = halign; Label = label;
344
-
345
- }
346
-
347
-
348
-
349
-
350
-
351
- public static IList<Poco> ToList(object[,] hatchpotch)
352
-
353
- {
354
-
355
- var innerLen = 7;
356
-
357
- var outerLen = hatchpotch.Length / innerLen;
358
-
359
- return Enumerable.Range(0, outerLen).Select(i => new Poco((string)hatchpotch[i, 0], (string)hatchpotch[i, 1], (int)hatchpotch[i, 2], (bool)hatchpotch[i, 3], (int)hatchpotch[i, 4], (int)hatchpotch[i, 5], (string)hatchpotch[i, 6])).ToList();
360
-
361
- }
362
-
363
-
364
-
365
- public static object[,] ToRect(IList<Poco> data) //理解しやすくするためList<Poco>としてます。実用では副作用に注意しましょう
366
-
367
- {
368
-
369
- var ret = new object[data.Count(), 7];
370
-
371
- for (var i = 0; i < data.Count(); i++)
372
-
373
- {
374
-
375
- ret[i, 0] = (object)data[i].Name;
376
-
377
- ret[i, 1] = (object)data[i].Id;
378
-
379
- ret[i, 2] = (object)data[i].Width;
380
-
381
- ret[i, 3] = (object)data[i].IsValid;
382
-
383
- ret[i, 4] = (object)data[i].Valign;
384
-
385
- ret[i, 5] = (object)data[i].Halign;
386
-
387
- ret[i, 6] = (object)data[i].Label;
388
-
389
- }
390
-
391
- return ret;
392
-
393
- }
394
-
395
-
396
-
397
-
398
-
399
- }
400
-
401
-
402
-
403
- }
404
-
405
-
406
-
407
-
408
-
409
-
410
-
411
- //実行部
412
-
413
- sub main()
414
-
415
- {
416
-
417
- Object[,] Obj = {
418
-
419
- { "UniqId", "UniqId", 70, false, 11111, 22222, "LABEL_CHAR" },
420
-
421
- { "職員名", "ShokuinName", 320, true, 11111, 22222, "LABEL_CHAR" },
422
-
423
- { "科目コード", "AAA", 80, true, 11111, 22222, "MONEY" },
424
-
425
- };
426
-
427
-
428
-
429
- IList<Poco> PocoList = Poco.ToList(Obj);
430
-
431
-
432
-
433
-
434
-
435
- for (var i = 0; i < 10; i++)
436
-
437
- {
438
-
439
- Poco _Poco = new Poco("ほげほげ" + i, "Hogehoge" + i, 80, true, 11111, 22222, "MONEY");
440
-
441
- PocoList.Add(_Poco);
442
-
443
- }
444
-
445
-
446
-
447
-
448
-
449
- Object[,] Obj2 = Poco.ToRect(PocoList);
450
-
451
- }
452
-
453
-
454
-
455
- ```

4

追記

2019/02/01 04:15

投稿

cutedog
cutedog

スコア177

test CHANGED
File without changes
test CHANGED
@@ -289,3 +289,167 @@
289
289
 
290
290
 
291
291
  ```
292
+
293
+
294
+
295
+
296
+
297
+ 実装してみました。
298
+
299
+ うまくいきました。
300
+
301
+ ```C#
302
+
303
+
304
+
305
+ using System;
306
+
307
+ using System.Collections.Generic;
308
+
309
+ using System.Linq;
310
+
311
+ using System.Text;
312
+
313
+ using System.Threading.Tasks;
314
+
315
+
316
+
317
+ namespace WindowsFormsApplication1
318
+
319
+ {
320
+
321
+ public class Poco
322
+
323
+ {
324
+
325
+ public string Name;
326
+
327
+ public string Id;
328
+
329
+ public int Width;
330
+
331
+ public bool IsValid;
332
+
333
+ public int Valign;
334
+
335
+ public int Halign;
336
+
337
+ public string Label;
338
+
339
+ public Poco(string name, string id, int width, bool isvalid, int valign, int halign, string label)
340
+
341
+ {
342
+
343
+ Name = name; Id = id; Width = width; IsValid = isvalid; Valign = valign; Halign = halign; Label = label;
344
+
345
+ }
346
+
347
+
348
+
349
+
350
+
351
+ public static IList<Poco> ToList(object[,] hatchpotch)
352
+
353
+ {
354
+
355
+ var innerLen = 7;
356
+
357
+ var outerLen = hatchpotch.Length / innerLen;
358
+
359
+ return Enumerable.Range(0, outerLen).Select(i => new Poco((string)hatchpotch[i, 0], (string)hatchpotch[i, 1], (int)hatchpotch[i, 2], (bool)hatchpotch[i, 3], (int)hatchpotch[i, 4], (int)hatchpotch[i, 5], (string)hatchpotch[i, 6])).ToList();
360
+
361
+ }
362
+
363
+
364
+
365
+ public static object[,] ToRect(IList<Poco> data) //理解しやすくするためList<Poco>としてます。実用では副作用に注意しましょう
366
+
367
+ {
368
+
369
+ var ret = new object[data.Count(), 7];
370
+
371
+ for (var i = 0; i < data.Count(); i++)
372
+
373
+ {
374
+
375
+ ret[i, 0] = (object)data[i].Name;
376
+
377
+ ret[i, 1] = (object)data[i].Id;
378
+
379
+ ret[i, 2] = (object)data[i].Width;
380
+
381
+ ret[i, 3] = (object)data[i].IsValid;
382
+
383
+ ret[i, 4] = (object)data[i].Valign;
384
+
385
+ ret[i, 5] = (object)data[i].Halign;
386
+
387
+ ret[i, 6] = (object)data[i].Label;
388
+
389
+ }
390
+
391
+ return ret;
392
+
393
+ }
394
+
395
+
396
+
397
+
398
+
399
+ }
400
+
401
+
402
+
403
+ }
404
+
405
+
406
+
407
+
408
+
409
+
410
+
411
+ //実行部
412
+
413
+ sub main()
414
+
415
+ {
416
+
417
+ Object[,] Obj = {
418
+
419
+ { "UniqId", "UniqId", 70, false, 11111, 22222, "LABEL_CHAR" },
420
+
421
+ { "職員名", "ShokuinName", 320, true, 11111, 22222, "LABEL_CHAR" },
422
+
423
+ { "科目コード", "AAA", 80, true, 11111, 22222, "MONEY" },
424
+
425
+ };
426
+
427
+
428
+
429
+ IList<Poco> PocoList = Poco.ToList(Obj);
430
+
431
+
432
+
433
+
434
+
435
+ for (var i = 0; i < 10; i++)
436
+
437
+ {
438
+
439
+ Poco _Poco = new Poco("ほげほげ" + i, "Hogehoge" + i, 80, true, 11111, 22222, "MONEY");
440
+
441
+ PocoList.Add(_Poco);
442
+
443
+ }
444
+
445
+
446
+
447
+
448
+
449
+ Object[,] Obj2 = Poco.ToRect(PocoList);
450
+
451
+ }
452
+
453
+
454
+
455
+ ```

3

追記

2019/02/01 03:49

投稿

cutedog
cutedog

スコア177

test CHANGED
File without changes
test CHANGED
@@ -171,3 +171,121 @@
171
171
  }
172
172
 
173
173
  ```
174
+
175
+
176
+
177
+ こちらの環境へコピペしてみましたが
178
+
179
+ Enumerableでエラーがでます。なにか足らない??
180
+
181
+ ```C#
182
+
183
+ using System;
184
+
185
+ using System.Collections.Generic;
186
+
187
+ using System.Linq;
188
+
189
+ using System.Text;
190
+
191
+ using System.Threading.Tasks;
192
+
193
+
194
+
195
+ namespace WindowsFormsApplication1
196
+
197
+ {
198
+
199
+ public class Poco
200
+
201
+ {
202
+
203
+ public string Name;
204
+
205
+ public string Id;
206
+
207
+ public int Width;
208
+
209
+ public bool IsValid;
210
+
211
+ public int Valign;
212
+
213
+ public int Halign;
214
+
215
+ public string Label;
216
+
217
+ public Poco(string name, string id, int width, bool isvalid, int valign, int halign, string label)
218
+
219
+ {
220
+
221
+ Name = name; Id = id; Width = width; IsValid = isvalid; Valign = valign; Halign = halign; Label = label;
222
+
223
+ }
224
+
225
+
226
+
227
+
228
+
229
+ public List<Poco> ToList(object[,] hatchpotch)
230
+
231
+ {
232
+
233
+ var innerLen = 7;
234
+
235
+ var outerLen = hatchpotch.Length / innerLen;
236
+
237
+ return Enumerable(0, outerLen).Select(i => new Poco((string)hatchpotch[i, 0], (string)hatchpotch[i, 1], (int)hatchpotch[i, 2], (bool)hatchpotch[i, 3], (int)hatchpotch[i, 4], (int)hatchpotch[i, 5], (string)hatchpotch[i, 6])).ToList();
238
+
239
+ }
240
+
241
+
242
+
243
+ public object[,] ToRect(List<Poco> data) //理解しやすくするためList<Poco>としてます。実用では副作用に注意しましょう
244
+
245
+ {
246
+
247
+ var ret = new object[data.Count(), 7];
248
+
249
+ for (var i = 0; i < data.Count(); i++)
250
+
251
+ {
252
+
253
+ ret[i, 0] = (object)data[i].Name;
254
+
255
+ ret[i, 1] = (object)data[i].Id;
256
+
257
+ ret[i, 2] = (object)data[i].Width;
258
+
259
+ ret[i, 3] = (object)data[i].IsValid;
260
+
261
+ ret[i, 4] = (object)data[i].Valign;
262
+
263
+ ret[i, 5] = (object)data[i].Halign;
264
+
265
+ ret[i, 6] = (object)data[i].Label;
266
+
267
+ }
268
+
269
+ return ret;
270
+
271
+ }
272
+
273
+
274
+
275
+
276
+
277
+ }
278
+
279
+
280
+
281
+
282
+
283
+
284
+
285
+
286
+
287
+ }
288
+
289
+
290
+
291
+ ```

2

追記

2019/02/01 03:15

投稿

cutedog
cutedog

スコア177

test CHANGED
File without changes
test CHANGED
@@ -99,3 +99,75 @@
99
99
  }
100
100
 
101
101
  ```
102
+
103
+
104
+
105
+ List形式からObject[,]への変換までを書いてみました。
106
+
107
+ なんとかできました。ありがとうございました。
108
+
109
+ ```C#
110
+
111
+ var objList = new List<List<object>>();
112
+
113
+ objList.Add(new List<object>() { "UniqId", "UniqId", 70, false, 11111, 22222, "LABEL_CHAR" });
114
+
115
+ objList.Add(new List<object>() { "職員名", "ShokuinName", 320, true, 11111, 22222, "LABEL_CHAR" });
116
+
117
+ objList.Add(new List<object>() { "科目コード", "AAA", 80, true, 11111, 22222, "MONEY" });
118
+
119
+
120
+
121
+ for (var i = 0; i < 10; i++)
122
+
123
+ {
124
+
125
+
126
+
127
+ objList.Add(new List<object>() { "ほげほげ" + i, "Hogehoge" + i, 80, true, 11111, 22222, "MONEY" });
128
+
129
+
130
+
131
+ }
132
+
133
+
134
+
135
+ //これだとObject[][]になってしまう
136
+
137
+ //var parsedList = objList
138
+
139
+ // .Select(val => val
140
+
141
+ // .Select(val2 => val2).ToArray()
142
+
143
+ // ).ToArray();
144
+
145
+
146
+
147
+ var rowCount = objList.Count;
148
+
149
+ var colCount = 7;
150
+
151
+
152
+
153
+ var r = new Object[objList.Count, 7];
154
+
155
+
156
+
157
+ for (int y = 0; y < rowCount; y++)
158
+
159
+ {
160
+
161
+ var src = objList[y];
162
+
163
+ for (int x = 0; x < colCount; x++)
164
+
165
+ {
166
+
167
+ r[y, x] = objList[x];
168
+
169
+ }
170
+
171
+ }
172
+
173
+ ```

1

追記

2019/02/01 02:53

投稿

cutedog
cutedog

スコア177

test CHANGED
File without changes
test CHANGED
@@ -67,3 +67,35 @@
67
67
 
68
68
 
69
69
  ```
70
+
71
+
72
+
73
+
74
+
75
+ LIST<T>を使うっていうのはこういことですか?
76
+
77
+ ```C#
78
+
79
+ IList<Object[]> objList = new List<Object[]>();
80
+
81
+ objList.Add(new object[] { "UniqId", "UniqId", 70, false, 11111, 22222, "LABEL_CHAR" });
82
+
83
+ objList.Add(new object[] { "職員名", "ShokuinName", 320, true, 11111, 22222, "LABEL_CHAR" });
84
+
85
+ objList.Add(new object[] { "科目コード", "AAA", 80, true, 11111, 22222, "MONEY" });
86
+
87
+
88
+
89
+ for (var i = 0; i < 10; i++)
90
+
91
+ {
92
+
93
+
94
+
95
+ objList.Add(new object[] { "ほげほげ" + i, "Hogehoge" + i, 80, true, 11111, 22222, "MONEY" });
96
+
97
+
98
+
99
+ }
100
+
101
+ ```