質問編集履歴
2
ソースコードをマークダウンで追記
test
CHANGED
File without changes
|
test
CHANGED
@@ -45,3 +45,219 @@
|
|
45
45
|
|
46
46
|
|
47
47
|
お力添えの程どうぞ宜しく御願い致します
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
### 補足情報(2019/08/20 追記)
|
52
|
+
|
53
|
+
```Java
|
54
|
+
|
55
|
+
/**
|
56
|
+
|
57
|
+
* 指定した範囲のセルをコピーする。
|
58
|
+
|
59
|
+
*
|
60
|
+
|
61
|
+
* @param copyRow0
|
62
|
+
|
63
|
+
* 開始行
|
64
|
+
|
65
|
+
* @param copyColumn0
|
66
|
+
|
67
|
+
* 開始列
|
68
|
+
|
69
|
+
* @param copyRow1
|
70
|
+
|
71
|
+
* 終了行
|
72
|
+
|
73
|
+
* @param copyColumn1
|
74
|
+
|
75
|
+
* 終了列
|
76
|
+
|
77
|
+
* @param startRow
|
78
|
+
|
79
|
+
* 貼り付け行
|
80
|
+
|
81
|
+
* @param startColumn
|
82
|
+
|
83
|
+
* 貼り付け列
|
84
|
+
|
85
|
+
*/
|
86
|
+
|
87
|
+
@SuppressWarnings("deprecation")
|
88
|
+
|
89
|
+
public void copyCellArea(String orgSheetName, int copyRow0, int copyColumn0, int copyRow1,
|
90
|
+
|
91
|
+
int copyColumn1, int startRow, int startColumn) {
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
// シートオブジェクト生成
|
96
|
+
|
97
|
+
HSSFSheet sheet = wb.getSheet(orgSheetName);
|
98
|
+
|
99
|
+
List<Region> appendRegionList = new ArrayList<Region>();
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
for (int i = 0; copyRow0 + i <= copyRow1; i++) {
|
104
|
+
|
105
|
+
for (int j = 0; copyColumn0 + j <= copyColumn1; j++) {
|
106
|
+
|
107
|
+
HSSFCell srcCell = getCell(copyRow0 + i, copyColumn0 + j, sheet);
|
108
|
+
|
109
|
+
HSSFCell destCell = getCell(startRow + i, startColumn + j, sheet);
|
110
|
+
|
111
|
+
// スタイルを取得
|
112
|
+
|
113
|
+
destCell.setCellStyle(srcCell.getCellStyle());
|
114
|
+
|
115
|
+
destCell.setCellType(srcCell.getCellType());
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
// 値の設定
|
120
|
+
|
121
|
+
switch (srcCell.getCellType()) {
|
122
|
+
|
123
|
+
case HSSFCell.CELL_TYPE_BOOLEAN:
|
124
|
+
|
125
|
+
destCell.setCellValue(srcCell.getBooleanCellValue());
|
126
|
+
|
127
|
+
break;
|
128
|
+
|
129
|
+
case HSSFCell.CELL_TYPE_ERROR:
|
130
|
+
|
131
|
+
destCell.setCellValue(srcCell.getErrorCellValue());
|
132
|
+
|
133
|
+
break;
|
134
|
+
|
135
|
+
case HSSFCell.CELL_TYPE_FORMULA:
|
136
|
+
|
137
|
+
destCell.setCellFormula(srcCell.getCellFormula());
|
138
|
+
|
139
|
+
break;
|
140
|
+
|
141
|
+
case HSSFCell.CELL_TYPE_NUMERIC:
|
142
|
+
|
143
|
+
destCell.setCellValue(srcCell.getNumericCellValue());
|
144
|
+
|
145
|
+
break;
|
146
|
+
|
147
|
+
case HSSFCell.CELL_TYPE_STRING:
|
148
|
+
|
149
|
+
destCell.setCellValue(srcCell.getStringCellValue());
|
150
|
+
|
151
|
+
break;
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
// 結合の設定
|
158
|
+
|
159
|
+
for (int k = 0; k < sheet.getNumMergedRegions(); k++) {
|
160
|
+
|
161
|
+
Region region = sheet.getMergedRegionAt(k);
|
162
|
+
|
163
|
+
// 処理中のコピー元セルが結合セルである場合
|
164
|
+
|
165
|
+
if (region.contains(i, (short) j)) {
|
166
|
+
|
167
|
+
int newRow0 = startRow + i;
|
168
|
+
|
169
|
+
short newCol0 = region.getColumnFrom();
|
170
|
+
|
171
|
+
int newRow1 = region.getRowTo() - region.getRowFrom() + startRow + i;
|
172
|
+
|
173
|
+
short newCol1 = region.getColumnTo();
|
174
|
+
|
175
|
+
Region newRegion = new Region();
|
176
|
+
|
177
|
+
newRegion.setRowFrom(newRow0);
|
178
|
+
|
179
|
+
newRegion.setColumnFrom((short) newCol0);
|
180
|
+
|
181
|
+
newRegion.setRowTo(newRow1);
|
182
|
+
|
183
|
+
newRegion.setColumnTo((short) newCol1);
|
184
|
+
|
185
|
+
boolean exist = false;
|
186
|
+
|
187
|
+
for (int n = 0; n < appendRegionList.size(); n++) {
|
188
|
+
|
189
|
+
Region exRegion = appendRegionList.get(n);
|
190
|
+
|
191
|
+
if (exRegion.contains(newRow0, newCol0)) {
|
192
|
+
|
193
|
+
// 既に存在する
|
194
|
+
|
195
|
+
exist = true;
|
196
|
+
|
197
|
+
break;
|
198
|
+
|
199
|
+
}
|
200
|
+
|
201
|
+
}
|
202
|
+
|
203
|
+
if (!exist) {
|
204
|
+
|
205
|
+
appendRegionList.add(newRegion);
|
206
|
+
|
207
|
+
break;
|
208
|
+
|
209
|
+
} else {
|
210
|
+
|
211
|
+
break;
|
212
|
+
|
213
|
+
}
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
}
|
218
|
+
|
219
|
+
// 幅サイズ調節
|
220
|
+
|
221
|
+
if (i == 0) {
|
222
|
+
|
223
|
+
sheet.setColumnWidth((short) (startColumn + j), sheet.getColumnWidth((short) (copyColumn0 + j)));
|
224
|
+
|
225
|
+
}
|
226
|
+
|
227
|
+
}
|
228
|
+
|
229
|
+
}
|
230
|
+
|
231
|
+
}
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
/**
|
236
|
+
|
237
|
+
* Cell を返す。
|
238
|
+
|
239
|
+
*
|
240
|
+
|
241
|
+
* @param row
|
242
|
+
|
243
|
+
* 行
|
244
|
+
|
245
|
+
* @param column
|
246
|
+
|
247
|
+
* 列
|
248
|
+
|
249
|
+
* @param sheet
|
250
|
+
|
251
|
+
* オブジェクト
|
252
|
+
|
253
|
+
* @return Cell
|
254
|
+
|
255
|
+
*/
|
256
|
+
|
257
|
+
protected HSSFCell getCell(int row, int column, HSSFSheet sheet) {
|
258
|
+
|
259
|
+
return HSSFCellUtil.getCell(HSSFCellUtil.getRow(row, sheet), column);
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
```
|
1
添付画像追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -14,7 +14,7 @@
|
|
14
14
|
|
15
15
|
具体的には添付のようなイメージで実現したいです。
|
16
16
|
|
17
|
-
|
17
|
+
![イメージ説明](11b40c9eda387a64ed1ce4af86d6168f.jpeg)
|
18
18
|
|
19
19
|
### 試したこと
|
20
20
|
|