質問編集履歴

2

修正後

2018/06/14 03:13

投稿

kirin311
kirin311

スコア53

test CHANGED
File without changes
test CHANGED
@@ -116,7 +116,7 @@
116
116
 
117
117
  {
118
118
 
119
- if ($count % 2 == 0)
119
+ if ($cnt % 2 == 0)
120
120
 
121
121
  {
122
122
 
@@ -138,7 +138,7 @@
138
138
 
139
139
 
140
140
 
141
- $count++;
141
+ $cnt++;
142
142
 
143
143
  }
144
144
 
@@ -152,6 +152,8 @@
152
152
 
153
153
  $writer->save('php://output'); //出力開始
154
154
 
155
+ }
156
+
155
157
  ```
156
158
 
157
159
 
@@ -213,3 +215,91 @@
213
215
 
214
216
 
215
217
  以上です、ヒントだけでも何らかのアドバイスを頂ければとても助かりますので是非ともよろしくお願いします。
218
+
219
+
220
+
221
+
222
+
223
+ ###修正後
224
+
225
+ papinianus様の回答により、理想通りにできましたので以下に修正いたしました。
226
+
227
+
228
+
229
+ ```PHP
230
+
231
+ if ($is_dlbutton)
232
+
233
+ { //DLボタンを押したら実行
234
+
235
+
236
+
237
+ $obj = PHPExcel_IOFactory::createReader('Excel5');
238
+
239
+ $file = $obj->load("./excel.xls");
240
+
241
+ $file->setActiveSheetIndex(0);
242
+
243
+ $sheet = $file->getActiveSheet();
244
+
245
+ $cnt = 0;
246
+
247
+
248
+
249
+ // テンプレートの読込
250
+
251
+ $obj = PHPExcel_IOFactory::createReader('Excel5');
252
+
253
+ $file = $obj->load("./excel.xls");
254
+
255
+ $file->setActiveSheetIndex(0);
256
+
257
+ $sheet = $file->getActiveSheet();
258
+
259
+ $cnt = 0;
260
+
261
+
262
+
263
+ while ($row = $list[$cnt])
264
+
265
+ $param1 = floor($cnt/2);//2で割って小数点以下を切り捨てる
266
+
267
+ if($cnt % 2 == 0){
268
+
269
+ //0*7パターン
270
+
271
+ $sheet->setCellValue('A' . ($param1*8+1), $row["address"]); //住所
272
+
273
+ $sheet->setCellValue('A' . ($param1*8+2) , $row["name"]); //名前
274
+
275
+ }else{
276
+
277
+ //1*7パターン
278
+
279
+ $sheet->setCellValue('G' . ($param1*8+1), $row["address"]); //住所
280
+
281
+ $sheet->setCellValue('G' . ($param1*8+2) , $row["name"]); //名前
282
+
283
+ }
284
+
285
+ $cnt++;
286
+
287
+ }
288
+
289
+
290
+
291
+ header('Content-Type: application/force-download');
292
+
293
+ header('Content-Disposition: attachment; filename= mb_convert_encoding("excel.xls", "SJIS-win", "UTF-8")');
294
+
295
+ $writer = PHPExcel_IOFactory::createWriter($sheet, "Excel5");
296
+
297
+ $writer->save('php://output'); //出力開始
298
+
299
+ }
300
+
301
+
302
+
303
+ ```
304
+
305
+ ただ、非推奨とのことなのでPhpSpreadsheeでこちらの考え方をもとに作らせて頂きます。

1

エラーメッセージの削除

2018/06/14 03:13

投稿

kirin311
kirin311

スコア53

test CHANGED
File without changes
test CHANGED
@@ -44,122 +44,116 @@
44
44
 
45
45
 
46
46
 
47
+
48
+
49
+ ### 該当のソースコード
50
+
51
+ ■ $listの中身
52
+
53
+ array (size=10)
54
+
55
+ 0 =>
56
+
57
+ array (size=2)
58
+
59
+ 'name' => string '名前1'
60
+
61
+ 'address' => string 'ダミー1'
62
+
63
+ 1 =>
64
+
65
+ array (size=2)
66
+
67
+ 'name' => string '名前2'
68
+
69
+ 'address' => string 'ダミー2'
70
+
71
+ 2 =>
72
+
73
+ array (size=2)
74
+
75
+ 'name' => string '名前3'
76
+
77
+ 'address' => string 'ダミー3'
78
+
79
+ .
80
+
81
+ .
82
+
83
+ .
84
+
85
+ 以降繰り返し
86
+
87
+ .
88
+
89
+ .
90
+
91
+ .
92
+
93
+ ```php
94
+
95
+ if ($is_dlbutton)
96
+
97
+ { //DLボタンを押したら実行
98
+
99
+
100
+
101
+ // テンプレートの読込
102
+
103
+
104
+
105
+ $obj = PHPExcel_IOFactory::createReader('Excel5');
106
+
107
+ $file = $obj->load("./excel.xls");
108
+
109
+ $file->setActiveSheetIndex(0);
110
+
111
+ $sheet = $file->getActiveSheet();
112
+
113
+ $cnt = 0;
114
+
115
+ while ($row = $list[$cnt])
116
+
117
+ {
118
+
119
+ if ($count % 2 == 0)
120
+
121
+ {
122
+
123
+ $sheet->setCellValue('A' . (8 * $cnt + 2) , $row["address"]); //住所
124
+
125
+ $sheet->setCellValue('A' . (8 * $cnt + 5) , $row["name"]); //名前
126
+
127
+ }
128
+
129
+ else
130
+
131
+ {
132
+
133
+ $sheet->setCellValue('G' . (8 * $cnt + 2) , $row["address"]); //住所
134
+
135
+ $sheet->setCellValue('G' . (8 * $cnt + 5) , $row["name"]); //名前
136
+
137
+ }
138
+
139
+
140
+
141
+ $count++;
142
+
143
+ }
144
+
145
+
146
+
147
+ header('Content-Type: application/force-download');
148
+
149
+ header('Content-Disposition: attachment; filename= mb_convert_encoding("excel.xls", "SJIS-win", "UTF-8")');
150
+
151
+ $writer = PHPExcel_IOFactory::createWriter($sheet, "Excel5");
152
+
153
+ $writer->save('php://output'); //出力開始
154
+
47
155
  ```
48
156
 
49
- エラーメッセージ
50
-
51
- ```
52
-
53
-
54
-
55
- ### 該当のソースコード
56
-
57
- ■ $listの中身
58
-
59
- array (size=10)
60
-
61
- 0 =>
62
-
63
- array (size=2)
64
-
65
- 'name' => string '名前1'
66
-
67
- 'address' => string 'ダミー1'
68
-
69
- 1 =>
70
-
71
- array (size=2)
72
-
73
- 'name' => string '名前2'
74
-
75
- 'address' => string 'ダミー2'
76
-
77
- 2 =>
78
-
79
- array (size=2)
80
-
81
- 'name' => string '名前3'
82
-
83
- 'address' => string 'ダミー3'
84
-
85
- .
86
-
87
- .
88
-
89
- .
90
-
91
- 以降繰り返し
92
-
93
- .
94
-
95
- .
96
-
97
- .
98
-
99
- ```php
100
-
101
- if ($is_dlbutton)
102
-
103
- { //DLボタンを押したら実行
104
-
105
-
106
-
107
- // テンプレートの読込
108
-
109
-
110
-
111
- $obj = PHPExcel_IOFactory::createReader('Excel5');
112
-
113
- $file = $obj->load("./excel.xls");
114
-
115
- $file->setActiveSheetIndex(0);
116
-
117
- $sheet = $file->getActiveSheet();
118
-
119
- $cnt = 0;
120
-
121
- while ($row = $list[$cnt])
122
-
123
- {
124
-
125
- if ($count % 2 == 0)
126
-
127
- {
128
-
129
- $sheet->setCellValue('A' . (8 * $cnt + 2) , $row["address"]); //住所
130
-
131
- $sheet->setCellValue('A' . (8 * $cnt + 5) , $row["name"]); //名前
132
-
133
- }
134
-
135
- else
136
-
137
- {
138
-
139
- $sheet->setCellValue('G' . (8 * $cnt + 2) , $row["address"]); //住所
140
-
141
- $sheet->setCellValue('G' . (8 * $cnt + 5) , $row["name"]); //名前
142
-
143
- }
144
-
145
-
146
-
147
- $count++;
148
-
149
- }
150
-
151
-
152
-
153
- header('Content-Type: application/force-download');
154
-
155
- header('Content-Disposition: attachment; filename= mb_convert_encoding("excel.xls", "SJIS-win", "UTF-8")');
156
-
157
- $writer = PHPExcel_IOFactory::createWriter($sheet, "Excel5");
158
-
159
- $writer->save('php://output'); //出力開始
160
-
161
- ```
162
-
163
157
 
164
158
 
165
159
  ### 試したこと