質問編集履歴

16

ソースコード修正

2019/01/18 08:40

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -26,602 +26,162 @@
26
26
 
27
27
  ```ここに言語名を入力
28
28
 
29
- void CEMain::PageComvert(CExcelCtrl *exl,int Max,int PageRowMax)
30
-
31
- {
32
-
33
- CString wks;
34
-
35
- int rp;
36
-
37
-
38
-
39
- CStringArray sa;
40
-
41
-
42
-
43
- for(int page = 1;page <= Max;page++){ // ページのループ
44
-
45
- m_Page++;
46
-
47
- for(int row = 1;row <= PageRowMax;row++){ // ページ内の行ループ
48
-
49
- rp = ((page - 1) * PageRowMax) + row;
50
-
51
- exl->GetCellData(1,rp,255,rp,sa,true);
52
-
53
- for(int col = 0;col < sa.GetSize();col++){ // 項目のループ
54
-
55
- wks = sa[col];
56
-
57
- if(sa[col].GetLength() <= 3) continue;
58
-
59
- if(sa[col][0] != '&') continue;
60
-
61
- wks = ChangeData(sa[col],page,Max);
62
-
63
- exl->SetCellData(col + 1,rp,wks);
29
+
30
+
31
+ void CExcelCtrl::SetCellData(short col, short row,LPCSTR str)
32
+
33
+ {
34
+
35
+ try{
36
+
37
+ Range range = m_excel.GetCells();
38
+
39
+ range.SetItem(COleVariant(row),COleVariant(col),COleVariant(str));
40
+
41
+ }catch(COleDispatchException *e){
42
+
43
+ AfxMessageBox(e->m_strDescription,MB_ICONEXCLAMATION);
44
+
45
+ }
46
+
47
+ }
48
+
49
+
50
+
51
+ void CExcelCtrl::GetCellData(int cols,int rows,int cole,int rowe,CStringArray &dt,bool formula)
52
+
53
+ {
54
+
55
+ CString sc,ec;
56
+
57
+ sc.Format("%s%d",Num2Col(cols),rows);
58
+
59
+ ec.Format("%s%d",Num2Col(cole),rowe);
60
+
61
+ GetCellData(sc,ec,dt,formula);
62
+
63
+ }
64
+
65
+
66
+
67
+ void CExcelCtrl::GetCellData(LPCSTR sc,LPCSTR ec,CStringArray &dt,bool formula)
68
+
69
+ {
70
+
71
+ try{
72
+
73
+ _Worksheet ws = m_excel.GetActiveSheet();
74
+
75
+ Range range = ws.GetRange(COleVariant(sc),COleVariant(ec));
76
+
77
+
78
+
79
+ COleVariant data;
80
+
81
+ if(formula) data = range.GetFormula();
82
+
83
+ else data = range.GetValue(vtMissing);
84
+
85
+
86
+
87
+ COleSafeArray sa;
88
+
89
+ sa.Attach(data);
90
+
91
+
92
+
93
+ long rowmax,colmax;
94
+
95
+ sa.GetUBound(1,&rowmax);
96
+
97
+ sa.GetUBound(2,&colmax);
98
+
99
+
100
+
101
+ CString str;
102
+
103
+ long idx[2];
104
+
105
+
106
+
107
+ dt.RemoveAll();
108
+
109
+ for(long row = 1;row <= rowmax;row++){
110
+
111
+ idx[0] = row;
112
+
113
+ for(long col = 1;col <= colmax;col++){
114
+
115
+ idx[1] = col;
116
+
117
+ COleVariant val;
118
+
119
+ sa.GetElement(idx,&val);
120
+
121
+ switch(val.vt){
122
+
123
+ case VT_R8:
124
+
125
+ str.Format("%1.2f", val.dblVal);
126
+
127
+ break;
128
+
129
+ case VT_BSTR:
130
+
131
+ str.Format("%s",(CString)val.bstrVal);
132
+
133
+ break;
134
+
135
+ case VT_EMPTY:
136
+
137
+ str.Empty();
138
+
139
+ break;
140
+
141
+ }
142
+
143
+ dt.Add(str);
64
144
 
65
145
  }
66
146
 
67
147
  }
68
148
 
149
+ }catch(COleDispatchException *e){
150
+
151
+ AfxMessageBox(e->m_strDescription,MB_ICONEXCLAMATION);
152
+
153
+ dt.RemoveAll();
154
+
69
155
  }
70
156
 
71
157
  }
72
158
 
73
159
 
74
160
 
75
- CString CEMain::ChangeData(LPCSTR id,int page,int pageMax)
76
-
77
- {
78
-
79
- CString ret = id;
80
-
81
- switch(ret[1]){
82
-
83
- case 'R': ret = CellSetRentalList(id); break;
84
-
85
- case 'N': ret = CellSetNameList(id); break;
86
-
87
- case 'M': ret = CellSetMemo(id); break;
88
-
89
- case 'B': ret = CellSetBusinessData(id,page,pageMax); break;
90
-
91
- case 'P': ret = CellSetPageData(id,page); break;
92
-
93
- }
94
-
95
- return ret;
96
-
97
- }
98
-
99
-
100
-
101
- void CExcelCtrl::SetCellData(short col, short row,LPCSTR str)
102
-
103
- {
104
-
105
- try{
106
-
107
- Range range = m_excel.GetCells();
108
-
109
- range.SetItem(COleVariant(row),COleVariant(col),COleVariant(str));
110
-
111
- }catch(COleDispatchException *e){
112
-
113
- AfxMessageBox(e->m_strDescription,MB_ICONEXCLAMATION);
114
-
115
- }
116
-
117
- }
118
-
119
-
120
-
121
- void CExcelCtrl::GetCellData(int cols,int rows,int cole,int rowe,CStringArray &dt,bool formula)
122
-
123
- {
124
-
125
- CString sc,ec;
126
-
127
- sc.Format("%s%d",Num2Col(cols),rows);
128
-
129
- ec.Format("%s%d",Num2Col(cole),rowe);
130
-
131
- GetCellData(sc,ec,dt,formula);
132
-
133
- }
134
-
135
-
136
-
137
- void CExcelCtrl::GetCellData(LPCSTR sc,LPCSTR ec,CStringArray &dt,bool formula)
138
-
139
- {
140
-
141
- try{
142
-
143
- _Worksheet ws = m_excel.GetActiveSheet();
144
-
145
- Range range = ws.GetRange(COleVariant(sc),COleVariant(ec));
146
-
147
-
148
-
149
- COleVariant data;
150
-
151
- if(formula) data = range.GetFormula();
152
-
153
- else data = range.GetValue(vtMissing);
154
-
155
-
156
-
157
- COleSafeArray sa;
158
-
159
- sa.Attach(data);
160
-
161
-
162
-
163
- long rowmax,colmax;
164
-
165
- sa.GetUBound(1,&rowmax);
166
-
167
- sa.GetUBound(2,&colmax);
168
-
169
-
170
-
171
- CString str;
172
-
173
- long idx[2];
174
-
175
-
176
-
177
- dt.RemoveAll();
178
-
179
- for(long row = 1;row <= rowmax;row++){
180
-
181
- idx[0] = row;
182
-
183
- for(long col = 1;col <= colmax;col++){
184
-
185
- idx[1] = col;
186
-
187
- COleVariant val;
188
-
189
- sa.GetElement(idx,&val);
190
-
191
- switch(val.vt){
192
-
193
- case VT_R8:
194
-
195
- str.Format("%1.2f", val.dblVal);
196
-
197
- break;
198
-
199
- case VT_BSTR:
200
-
201
- str.Format("%s",(CString)val.bstrVal);
202
-
203
- break;
204
-
205
- case VT_EMPTY:
206
-
207
- str.Empty();
208
-
209
- break;
210
-
211
- }
212
-
213
- dt.Add(str);
214
-
215
- }
216
-
217
- }
218
-
219
- }catch(COleDispatchException *e){
220
-
221
- AfxMessageBox(e->m_strDescription,MB_ICONEXCLAMATION);
222
-
223
- dt.RemoveAll();
224
-
225
- }
226
-
227
- }
228
-
229
-
230
-
231
- CString CExcelCtrl::Num2Col(int num)
232
-
233
- {
234
-
235
- CString ret = "";
236
-
237
- int a = (num - 1) / 26;
238
-
239
- int b = (num - 1) % 26;
240
-
241
-
242
-
243
- if(a > 0) ret.Format("%c%c",('A' + (a - 1)),('A' + b));
244
-
245
- else ret.Format("%c",('A' + b));
246
-
247
- return ret;
248
-
249
- }
250
-
251
161
  ```
252
162
 
163
+
164
+
253
- ChangeDataで使用している関数
165
+ RangeのGetCells関数
166
+
167
+
254
168
 
255
169
  ```ここに言語名を入力
256
170
 
257
- CString CExcelOutMain::CellSetPageData(LPCSTR str,int page)
258
-
259
- {
260
-
261
- CString ret = "";
262
-
263
-
264
-
265
- CString id,sub;
266
-
267
- int len,start;
268
-
269
- bool zero;
270
-
271
- DivId(str,id,sub,&len,&start,&zero);
272
-
273
- for(int idx = 0;idx < m_PageData.GetSize();idx++){
274
-
275
- if(m_PageData[idx].page != page) continue;
276
-
277
- if(m_PageData[idx].id != id) continue;
278
-
279
- switch(m_PageData[idx].type){
280
-
281
- case EOTP_STRING: ret = m_PageData[idx].stData; break;
282
-
283
- case EOTP_CHAR: ret.Format("%c",m_PageData[idx].cData); break;
284
-
285
- case EOTP_INTEGER:
286
-
287
- ret.Format("%d",m_PageData[idx].nData);
288
-
289
- if(zero){
290
-
291
- if(m_PageData[idx].nData == 0) ret = "";
292
-
293
- }
294
-
295
- break;
296
-
297
- case EOTP_FLOAT:
298
-
299
- ret.Format("%f",m_PageData[idx].dData);
300
-
301
- if(zero){
302
-
303
- if(m_PageData[idx].dData == 0.0) ret = "";
304
-
305
- }
306
-
307
- break;
308
-
309
- }
310
-
311
- break;
312
-
313
- }
314
-
315
- if(len > 0) ret = ret.Mid(start,len);
316
-
317
-
318
-
319
- return ret;
320
-
321
- }
322
-
323
-
324
-
325
- CString CExcelOutMain::CellSetBusinessData(LPCSTR str,int page,int pageMax)
326
-
327
- {
328
-
329
- CString ret = "";
330
-
331
-
332
-
333
- CString id,sub;
334
-
335
- int len,start;
336
-
337
- bool zero;
338
-
339
- DivId(str,id,sub,&len,&start,&zero);
340
-
341
-
342
-
343
- CTime tm;
344
-
345
- tm = CTime::GetCurrentTime();
346
-
347
- if(id == EOII_PAGE){ // ページ番号
348
-
349
- if(m_MitOption != NULL){
350
-
351
- switch(m_MitOption->nPageFunc){
352
-
353
- case 0: ret = ""; break;
354
-
355
- case 1: ret.Format("%d",page); break;
356
-
357
- case 2: ret.Format("%d",page + (m_MitOption->nPage - 1)); break;
358
-
359
- }
360
-
361
- }else ret.Format("%d",page);
362
-
363
- }else if(id == EOII_PAGEC){ // ページ連番
364
-
365
- if(m_MitOption != NULL){
366
-
367
- switch(m_MitOption->nPageFunc){
368
-
369
- case 0: ret = ""; break;
370
-
371
- case 1: ret.Format("%d",m_Page); break;
372
-
373
- case 2: ret.Format("%d",m_Page + (m_MitOption->nPage - 1)); break;
374
-
375
- }
376
-
377
- }else ret.Format("%d",m_Page);
378
-
379
- }else if(id == EOII_PAGEALL){ // 全ページ
380
-
381
- if(m_MitOption != NULL){
382
-
383
- switch(m_MitOption->nPageFunc){
384
-
385
- case 0: ret = ""; break;
386
-
387
- default: ret.Format("%d",pageMax);
388
-
389
- }
390
-
391
- }else ret.Format("%d",pageMax);
392
-
393
- }else if(id == EOII_SYSDATEY) ret = tm.Format("%Y");
394
-
395
- else if(id == EOII_SYSDATEWY) ret = "";
396
-
397
- else if(id == EOII_SYSDATEM) ret = tm.Format("%m");
398
-
399
- else if(id == EOII_SYSDATED) ret = tm.Format("%d");
400
-
401
-
402
-
403
- if(len > 0) ret = ret.Mid(start,len);
404
-
405
- return ret;
406
-
407
- }
408
-
409
-
410
-
411
- CString CExcelOutMain::CellSetRentalList(LPCSTR str)
412
-
413
- {
414
-
415
- CString ret = "";
416
-
417
-
418
-
419
- CArray<EXDATA,EXDATA> *rec = (CArray<EXDATA,EXDATA> *)m_BData[0];
420
-
421
-
422
-
423
- CString id,sub;
424
-
425
- int len,start;
426
-
427
- bool zero;
428
-
429
- DivId(str,id,sub,&len,&start,&zero);
430
-
431
- int pos = GetBPos2(id);
432
-
433
- if(pos != -1){
434
-
435
- switch(rec->GetAt(pos).cType){
436
-
437
- case EOTP_STRING: ret = rec->GetAt(pos).stData; break;
438
-
439
- case EOTP_CHAR: ret.Format("%c",rec->GetAt(pos).cData); break;
440
-
441
- case EOTP_INTEGER:
442
-
443
- ret.Format("%d",rec->GetAt(pos).nData);
444
-
445
- if(zero){
446
-
447
- if(rec->GetAt(pos).nData == 0) ret = "";
448
-
449
- }
450
-
451
- break;
452
-
453
- case EOTP_FLOAT:
454
-
455
- ret.Format("%f",rec->GetAt(pos).dData);
456
-
457
- if(zero){
458
-
459
- if(rec->GetAt(pos).dData == 0.0) ret = "";
460
-
461
- }
462
-
463
- break;
464
-
465
- }
466
-
467
- }
468
-
469
-
470
-
471
- if(len > 0) ret = ret.Mid(start,len);
472
-
473
- return ret;
474
-
475
- }
476
-
477
-
478
-
479
- CString CExcelOutMain::CellSetMemo(LPCSTR str)
480
-
481
- {
482
-
483
- CString ret = "";
484
-
485
- CString id,sub;
486
-
487
- int len,start;
488
-
489
- bool zero;
490
-
491
- DivId(str,id,sub,&len,&start,&zero);
492
-
493
- if(id == "&M"){
494
-
495
- for(int idx = 0;idx < m_MTitle.GetSize();idx++){
496
-
497
- if(sub == m_MTitle[idx]){
498
-
499
- ret = m_MData[idx];
500
-
501
- break;
502
-
503
- }
504
-
505
- }
506
-
507
- }else{
508
-
509
- int idx = atoi(sub) - 1;
510
-
511
- if(idx >= 0){
512
-
513
- if(id == EOIM_TITLE){
514
-
515
- if(idx < m_MTitle.GetSize()) ret = m_MTitle[idx];
516
-
517
- }else if(id == EOIM_MEMO){
518
-
519
- if(idx < m_MData.GetSize()) ret = m_MData[idx];
520
-
521
- }
522
-
523
- }
524
-
525
- }
526
-
527
- if(len > 0) ret = ret.Mid(start,len);
528
-
529
- return ret;
530
-
531
- }
532
-
533
-
534
-
535
- CString CExcelOutMain::CellSetNameList(LPCSTR str)
536
-
537
- {
538
-
539
- CString ret = "";
540
-
541
-
542
-
543
- CArray<EXDATA,EXDATA> *rec = (CArray<EXDATA,EXDATA> *)m_CData[0];
544
-
545
-
546
-
547
- CString id,sub;
548
-
549
- int len,start;
550
-
551
- bool zero;
552
-
553
- DivId(str,id,sub,&len,&start,&zero);
554
-
555
-
556
-
557
- int pos = GetCPos2(id);
558
-
559
- if(pos != -1){
560
-
561
- switch(rec->GetAt(pos).cType){
562
-
563
- case EOTP_STRING: ret = rec->GetAt(pos).stData; break;
564
-
565
- case EOTP_CHAR: ret.Format("%c",rec->GetAt(pos).cData); break;
566
-
567
- case EOTP_INTEGER:
568
-
569
- ret.Format("%d",rec->GetAt(pos).nData);
570
-
571
- if(zero){
572
-
573
- if(rec->GetAt(pos).nData == 0) ret = "";
574
-
575
- }
576
-
577
- break;
578
-
579
- case EOTP_FLOAT:
580
-
581
- ret.Format("%f",rec->GetAt(pos).dData);
582
-
583
- if(zero){
584
-
585
- if(rec->GetAt(pos).dData == 0.0) ret = "";
586
-
587
- }
588
-
589
- break;
590
-
591
- }
592
-
593
- }
594
-
595
-
596
-
597
- if(len > 0) ret = ret.Mid(start,len);
598
-
599
- return ret;
171
+ LPDISPATCH Range::GetCells()
172
+
173
+ {
174
+
175
+ LPDISPATCH result;
176
+
177
+ InvokeHelper(0xee, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
178
+
179
+ return result;
600
180
 
601
181
  }
602
182
 
603
183
  ```
604
184
 
605
- RangeのGetCells関数
606
-
607
-
608
-
609
- ```ここに言語名を入力
610
-
611
- LPDISPATCH Range::GetCells()
612
-
613
- {
614
-
615
- LPDISPATCH result;
616
-
617
- InvokeHelper(0xee, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
618
-
619
- return result;
620
-
621
- }
622
-
623
- ```
624
-
625
185
 
626
186
 
627
187
  ### 試したこと

15

説明修正

2019/01/18 08:40

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -14,7 +14,7 @@
14
14
 
15
15
  else data = range.GetValue(vtMissing);
16
16
 
17
- メモリの使用量が大きく上がるのが分かりました。
17
+ で、メモリの使用量が大きく上がるのが分かりました。
18
18
 
19
19
  しかし、どこに問題があるのかがまだ分からないので、教えてもらえないでしょうか。
20
20
 

14

説明追加

2019/01/09 23:53

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -8,7 +8,11 @@
8
8
 
9
9
  どこで発生しているのかを調査したところ、
10
10
 
11
+ GetCellData関数の
12
+
11
- ページ情報のコンバートを行う処理のソースコードの部分で、
13
+ if(formula) data = range.GetFormula();
14
+
15
+ else data = range.GetValue(vtMissing);
12
16
 
13
17
  メモリの使用量が大きく上がるのが分かりました。
14
18
 
@@ -16,16 +20,6 @@
16
20
 
17
21
 
18
22
 
19
- ※追記
20
-
21
- GetCellData関数でメモリが増加していました。
22
-
23
- 修正方法がありましたら、私にご指導いただけないでしょうか。
24
-
25
- よろしくお願い致します。
26
-
27
-
28
-
29
23
  ### 該当のソースコード
30
24
 
31
25
 

13

ソースコード修正

2019/01/09 23:53

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -176,8 +176,6 @@
176
176
 
177
177
  CString str;
178
178
 
179
- VARIANT val;
180
-
181
179
  long idx[2];
182
180
 
183
181
 

12

ソースコード追加

2019/01/09 01:44

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -192,7 +192,9 @@
192
192
 
193
193
  idx[1] = col;
194
194
 
195
+ COleVariant val;
196
+
195
- sa.GetElement(idx,&val);
197
+ sa.GetElement(idx,&val);
196
198
 
197
199
  switch(val.vt){
198
200
 
@@ -206,8 +208,6 @@
206
208
 
207
209
  str.Format("%s",(CString)val.bstrVal);
208
210
 
209
- ::SysFreeString(val.bstrVal);
210
-
211
211
  break;
212
212
 
213
213
  case VT_EMPTY:

11

説明追加

2019/01/09 01:44

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -638,6 +638,8 @@
638
638
 
639
639
  PageComvert関数のみ除外して、Excel出力を実行
640
640
 
641
+ PageComvert関数内のGetCellDataのみ除外して、Excel出力を実行
642
+
641
643
 
642
644
 
643
645
  ### 補足情報(FW/ツールのバージョンなど)

10

説明修正

2019/01/09 01:41

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -18,7 +18,7 @@
18
18
 
19
19
  ※追記
20
20
 
21
- GetCellData、SetCellData関数でメモリが増加していました。
21
+ GetCellData関数でメモリが増加していました。
22
22
 
23
23
  修正方法がありましたら、私にご指導いただけないでしょうか。
24
24
 

9

説明追加

2019/01/07 07:17

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -20,7 +20,9 @@
20
20
 
21
21
  GetCellData、SetCellData関数でメモリが増加していました。
22
22
 
23
- 修正方法がありましたらご提示をお願ます
23
+ 修正方法がありましたら、私に指導ただけないでょうか
24
+
25
+ よろしくお願い致します。
24
26
 
25
27
 
26
28
 

8

説明追加

2019/01/07 06:56

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -16,6 +16,14 @@
16
16
 
17
17
 
18
18
 
19
+ ※追記
20
+
21
+ GetCellData、SetCellData関数でメモリが増加していました。
22
+
23
+ 修正方法がありましたらご提示をお願い致します。
24
+
25
+
26
+
19
27
  ### 該当のソースコード
20
28
 
21
29
 

7

ソースコード追加

2019/01/07 06:55

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -130,6 +130,102 @@
130
130
 
131
131
 
132
132
 
133
+ void CExcelCtrl::GetCellData(LPCSTR sc,LPCSTR ec,CStringArray &dt,bool formula)
134
+
135
+ {
136
+
137
+ try{
138
+
139
+ _Worksheet ws = m_excel.GetActiveSheet();
140
+
141
+ Range range = ws.GetRange(COleVariant(sc),COleVariant(ec));
142
+
143
+
144
+
145
+ COleVariant data;
146
+
147
+ if(formula) data = range.GetFormula();
148
+
149
+ else data = range.GetValue(vtMissing);
150
+
151
+
152
+
153
+ COleSafeArray sa;
154
+
155
+ sa.Attach(data);
156
+
157
+
158
+
159
+ long rowmax,colmax;
160
+
161
+ sa.GetUBound(1,&rowmax);
162
+
163
+ sa.GetUBound(2,&colmax);
164
+
165
+
166
+
167
+ CString str;
168
+
169
+ VARIANT val;
170
+
171
+ long idx[2];
172
+
173
+
174
+
175
+ dt.RemoveAll();
176
+
177
+ for(long row = 1;row <= rowmax;row++){
178
+
179
+ idx[0] = row;
180
+
181
+ for(long col = 1;col <= colmax;col++){
182
+
183
+ idx[1] = col;
184
+
185
+ sa.GetElement(idx,&val);
186
+
187
+ switch(val.vt){
188
+
189
+ case VT_R8:
190
+
191
+ str.Format("%1.2f", val.dblVal);
192
+
193
+ break;
194
+
195
+ case VT_BSTR:
196
+
197
+ str.Format("%s",(CString)val.bstrVal);
198
+
199
+ ::SysFreeString(val.bstrVal);
200
+
201
+ break;
202
+
203
+ case VT_EMPTY:
204
+
205
+ str.Empty();
206
+
207
+ break;
208
+
209
+ }
210
+
211
+ dt.Add(str);
212
+
213
+ }
214
+
215
+ }
216
+
217
+ }catch(COleDispatchException *e){
218
+
219
+ AfxMessageBox(e->m_strDescription,MB_ICONEXCLAMATION);
220
+
221
+ dt.RemoveAll();
222
+
223
+ }
224
+
225
+ }
226
+
227
+
228
+
133
229
  CString CExcelCtrl::Num2Col(int num)
134
230
 
135
231
  {
@@ -504,6 +600,28 @@
504
600
 
505
601
  ```
506
602
 
603
+ RangeのGetCells関数
604
+
605
+
606
+
607
+ ```ここに言語名を入力
608
+
609
+ LPDISPATCH Range::GetCells()
610
+
611
+ {
612
+
613
+ LPDISPATCH result;
614
+
615
+ InvokeHelper(0xee, DISPATCH_PROPERTYGET, VT_DISPATCH, (void*)&result, NULL);
616
+
617
+ return result;
618
+
619
+ }
620
+
621
+ ```
622
+
623
+
624
+
507
625
  ### 試したこと
508
626
 
509
627
 

6

ソースコード追加

2019/01/07 02:14

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -152,7 +152,357 @@
152
152
 
153
153
  ```
154
154
 
155
-
155
+ ChangeDataで使用している関数
156
+
157
+ ```ここに言語名を入力
158
+
159
+ CString CExcelOutMain::CellSetPageData(LPCSTR str,int page)
160
+
161
+ {
162
+
163
+ CString ret = "";
164
+
165
+
166
+
167
+ CString id,sub;
168
+
169
+ int len,start;
170
+
171
+ bool zero;
172
+
173
+ DivId(str,id,sub,&len,&start,&zero);
174
+
175
+ for(int idx = 0;idx < m_PageData.GetSize();idx++){
176
+
177
+ if(m_PageData[idx].page != page) continue;
178
+
179
+ if(m_PageData[idx].id != id) continue;
180
+
181
+ switch(m_PageData[idx].type){
182
+
183
+ case EOTP_STRING: ret = m_PageData[idx].stData; break;
184
+
185
+ case EOTP_CHAR: ret.Format("%c",m_PageData[idx].cData); break;
186
+
187
+ case EOTP_INTEGER:
188
+
189
+ ret.Format("%d",m_PageData[idx].nData);
190
+
191
+ if(zero){
192
+
193
+ if(m_PageData[idx].nData == 0) ret = "";
194
+
195
+ }
196
+
197
+ break;
198
+
199
+ case EOTP_FLOAT:
200
+
201
+ ret.Format("%f",m_PageData[idx].dData);
202
+
203
+ if(zero){
204
+
205
+ if(m_PageData[idx].dData == 0.0) ret = "";
206
+
207
+ }
208
+
209
+ break;
210
+
211
+ }
212
+
213
+ break;
214
+
215
+ }
216
+
217
+ if(len > 0) ret = ret.Mid(start,len);
218
+
219
+
220
+
221
+ return ret;
222
+
223
+ }
224
+
225
+
226
+
227
+ CString CExcelOutMain::CellSetBusinessData(LPCSTR str,int page,int pageMax)
228
+
229
+ {
230
+
231
+ CString ret = "";
232
+
233
+
234
+
235
+ CString id,sub;
236
+
237
+ int len,start;
238
+
239
+ bool zero;
240
+
241
+ DivId(str,id,sub,&len,&start,&zero);
242
+
243
+
244
+
245
+ CTime tm;
246
+
247
+ tm = CTime::GetCurrentTime();
248
+
249
+ if(id == EOII_PAGE){ // ページ番号
250
+
251
+ if(m_MitOption != NULL){
252
+
253
+ switch(m_MitOption->nPageFunc){
254
+
255
+ case 0: ret = ""; break;
256
+
257
+ case 1: ret.Format("%d",page); break;
258
+
259
+ case 2: ret.Format("%d",page + (m_MitOption->nPage - 1)); break;
260
+
261
+ }
262
+
263
+ }else ret.Format("%d",page);
264
+
265
+ }else if(id == EOII_PAGEC){ // ページ連番
266
+
267
+ if(m_MitOption != NULL){
268
+
269
+ switch(m_MitOption->nPageFunc){
270
+
271
+ case 0: ret = ""; break;
272
+
273
+ case 1: ret.Format("%d",m_Page); break;
274
+
275
+ case 2: ret.Format("%d",m_Page + (m_MitOption->nPage - 1)); break;
276
+
277
+ }
278
+
279
+ }else ret.Format("%d",m_Page);
280
+
281
+ }else if(id == EOII_PAGEALL){ // 全ページ
282
+
283
+ if(m_MitOption != NULL){
284
+
285
+ switch(m_MitOption->nPageFunc){
286
+
287
+ case 0: ret = ""; break;
288
+
289
+ default: ret.Format("%d",pageMax);
290
+
291
+ }
292
+
293
+ }else ret.Format("%d",pageMax);
294
+
295
+ }else if(id == EOII_SYSDATEY) ret = tm.Format("%Y");
296
+
297
+ else if(id == EOII_SYSDATEWY) ret = "";
298
+
299
+ else if(id == EOII_SYSDATEM) ret = tm.Format("%m");
300
+
301
+ else if(id == EOII_SYSDATED) ret = tm.Format("%d");
302
+
303
+
304
+
305
+ if(len > 0) ret = ret.Mid(start,len);
306
+
307
+ return ret;
308
+
309
+ }
310
+
311
+
312
+
313
+ CString CExcelOutMain::CellSetRentalList(LPCSTR str)
314
+
315
+ {
316
+
317
+ CString ret = "";
318
+
319
+
320
+
321
+ CArray<EXDATA,EXDATA> *rec = (CArray<EXDATA,EXDATA> *)m_BData[0];
322
+
323
+
324
+
325
+ CString id,sub;
326
+
327
+ int len,start;
328
+
329
+ bool zero;
330
+
331
+ DivId(str,id,sub,&len,&start,&zero);
332
+
333
+ int pos = GetBPos2(id);
334
+
335
+ if(pos != -1){
336
+
337
+ switch(rec->GetAt(pos).cType){
338
+
339
+ case EOTP_STRING: ret = rec->GetAt(pos).stData; break;
340
+
341
+ case EOTP_CHAR: ret.Format("%c",rec->GetAt(pos).cData); break;
342
+
343
+ case EOTP_INTEGER:
344
+
345
+ ret.Format("%d",rec->GetAt(pos).nData);
346
+
347
+ if(zero){
348
+
349
+ if(rec->GetAt(pos).nData == 0) ret = "";
350
+
351
+ }
352
+
353
+ break;
354
+
355
+ case EOTP_FLOAT:
356
+
357
+ ret.Format("%f",rec->GetAt(pos).dData);
358
+
359
+ if(zero){
360
+
361
+ if(rec->GetAt(pos).dData == 0.0) ret = "";
362
+
363
+ }
364
+
365
+ break;
366
+
367
+ }
368
+
369
+ }
370
+
371
+
372
+
373
+ if(len > 0) ret = ret.Mid(start,len);
374
+
375
+ return ret;
376
+
377
+ }
378
+
379
+
380
+
381
+ CString CExcelOutMain::CellSetMemo(LPCSTR str)
382
+
383
+ {
384
+
385
+ CString ret = "";
386
+
387
+ CString id,sub;
388
+
389
+ int len,start;
390
+
391
+ bool zero;
392
+
393
+ DivId(str,id,sub,&len,&start,&zero);
394
+
395
+ if(id == "&M"){
396
+
397
+ for(int idx = 0;idx < m_MTitle.GetSize();idx++){
398
+
399
+ if(sub == m_MTitle[idx]){
400
+
401
+ ret = m_MData[idx];
402
+
403
+ break;
404
+
405
+ }
406
+
407
+ }
408
+
409
+ }else{
410
+
411
+ int idx = atoi(sub) - 1;
412
+
413
+ if(idx >= 0){
414
+
415
+ if(id == EOIM_TITLE){
416
+
417
+ if(idx < m_MTitle.GetSize()) ret = m_MTitle[idx];
418
+
419
+ }else if(id == EOIM_MEMO){
420
+
421
+ if(idx < m_MData.GetSize()) ret = m_MData[idx];
422
+
423
+ }
424
+
425
+ }
426
+
427
+ }
428
+
429
+ if(len > 0) ret = ret.Mid(start,len);
430
+
431
+ return ret;
432
+
433
+ }
434
+
435
+
436
+
437
+ CString CExcelOutMain::CellSetNameList(LPCSTR str)
438
+
439
+ {
440
+
441
+ CString ret = "";
442
+
443
+
444
+
445
+ CArray<EXDATA,EXDATA> *rec = (CArray<EXDATA,EXDATA> *)m_CData[0];
446
+
447
+
448
+
449
+ CString id,sub;
450
+
451
+ int len,start;
452
+
453
+ bool zero;
454
+
455
+ DivId(str,id,sub,&len,&start,&zero);
456
+
457
+
458
+
459
+ int pos = GetCPos2(id);
460
+
461
+ if(pos != -1){
462
+
463
+ switch(rec->GetAt(pos).cType){
464
+
465
+ case EOTP_STRING: ret = rec->GetAt(pos).stData; break;
466
+
467
+ case EOTP_CHAR: ret.Format("%c",rec->GetAt(pos).cData); break;
468
+
469
+ case EOTP_INTEGER:
470
+
471
+ ret.Format("%d",rec->GetAt(pos).nData);
472
+
473
+ if(zero){
474
+
475
+ if(rec->GetAt(pos).nData == 0) ret = "";
476
+
477
+ }
478
+
479
+ break;
480
+
481
+ case EOTP_FLOAT:
482
+
483
+ ret.Format("%f",rec->GetAt(pos).dData);
484
+
485
+ if(zero){
486
+
487
+ if(rec->GetAt(pos).dData == 0.0) ret = "";
488
+
489
+ }
490
+
491
+ break;
492
+
493
+ }
494
+
495
+ }
496
+
497
+
498
+
499
+ if(len > 0) ret = ret.Mid(start,len);
500
+
501
+ return ret;
502
+
503
+ }
504
+
505
+ ```
156
506
 
157
507
  ### 試したこと
158
508
 

5

説明追加

2019/01/07 01:01

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -158,7 +158,7 @@
158
158
 
159
159
 
160
160
 
161
- ここに問題に対して試したこと記載してください。
161
+ PageComvert関数のみ除外して、Excel出力実行
162
162
 
163
163
 
164
164
 

4

誤字修正

2019/01/04 08:02

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  初心者です。
6
6
 
7
- プログラムのExcel出力を行う際の処理で、メモリ使用量が大きいので調べてほしいと頼まれ、
7
+ Excel出力を行う際のメモリ使用量が大きいので調べてほしいと頼まれ、
8
8
 
9
9
  どこで発生しているのかを調査したところ、
10
10
 

3

説明追加

2019/01/04 06:53

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -4,11 +4,13 @@
4
4
 
5
5
  初心者です。
6
6
 
7
- プログラムのメモリ使用量が大きいので調べてほしいと頼まれ、
7
+ プログラムのExcel出力を行う際の処理で、メモリ使用量が大きいので調べてほしいと頼まれ、
8
8
 
9
9
  どこで発生しているのかを調査したところ、
10
10
 
11
+ ページ情報のコンバートを行う処理のソースコードの部分で、
12
+
11
- とあるソースコードの部分で、メモリの使用量が大きく上がるのが分かりました。
13
+ メモリの使用量が大きく上がるのが分かりました。
12
14
 
13
15
  しかし、どこに問題があるのかがまだ分からないので、教えてもらえないでしょうか。
14
16
 

2

誤字修正

2019/01/04 06:49

投稿

beginner101
beginner101

スコア18

test CHANGED
File without changes
test CHANGED
@@ -110,6 +110,44 @@
110
110
 
111
111
  }
112
112
 
113
+
114
+
115
+ void CExcelCtrl::GetCellData(int cols,int rows,int cole,int rowe,CStringArray &dt,bool formula)
116
+
117
+ {
118
+
119
+ CString sc,ec;
120
+
121
+ sc.Format("%s%d",Num2Col(cols),rows);
122
+
123
+ ec.Format("%s%d",Num2Col(cole),rowe);
124
+
125
+ GetCellData(sc,ec,dt,formula);
126
+
127
+ }
128
+
129
+
130
+
131
+ CString CExcelCtrl::Num2Col(int num)
132
+
133
+ {
134
+
135
+ CString ret = "";
136
+
137
+ int a = (num - 1) / 26;
138
+
139
+ int b = (num - 1) % 26;
140
+
141
+
142
+
143
+ if(a > 0) ret.Format("%c%c",('A' + (a - 1)),('A' + b));
144
+
145
+ else ret.Format("%c",('A' + b));
146
+
147
+ return ret;
148
+
149
+ }
150
+
113
151
  ```
114
152
 
115
153
 

1

誤字修正

2019/01/04 06:29

投稿

beginner101
beginner101

スコア18

test CHANGED
@@ -1 +1 @@
1
- メモリ使用量が増する
1
+ C++ 出力を行うとメモリ使用量が増する
test CHANGED
File without changes