2002-03-12 05:54:56 -05:00
|
|
|
/* ====================================================================
|
2006-12-22 14:18:16 -05:00
|
|
|
Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
contributor license agreements. See the NOTICE file distributed with
|
|
|
|
this work for additional information regarding copyright ownership.
|
|
|
|
The ASF licenses this file to You under the Apache License, Version 2.0
|
|
|
|
(the "License"); you may not use this file except in compliance with
|
|
|
|
the License. You may obtain a copy of the License at
|
2004-04-09 09:05:39 -04:00
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
==================================================================== */
|
2002-03-12 05:54:56 -05:00
|
|
|
|
2002-03-12 05:38:26 -05:00
|
|
|
package org.apache.poi.hssf.usermodel.examples;
|
|
|
|
|
|
|
|
import java.io.FileOutputStream;
|
2016-12-18 17:03:31 -05:00
|
|
|
import java.io.IOException;
|
|
|
|
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFCell;
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFRow;
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFSheet;
|
|
|
|
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
|
|
import org.apache.poi.ss.util.CellRangeAddress;
|
2002-03-12 05:38:26 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An example of how to merge regions of cells.
|
|
|
|
*/
|
2009-02-02 20:19:13 -05:00
|
|
|
public class MergedCells {
|
|
|
|
public static void main(String[] args) throws IOException {
|
2002-03-12 05:38:26 -05:00
|
|
|
HSSFWorkbook wb = new HSSFWorkbook();
|
|
|
|
HSSFSheet sheet = wb.createSheet("new sheet");
|
|
|
|
|
2009-02-02 20:19:13 -05:00
|
|
|
HSSFRow row = sheet.createRow(1);
|
|
|
|
HSSFCell cell = row.createCell(1);
|
2002-03-12 05:38:26 -05:00
|
|
|
cell.setCellValue("This is a test of merging");
|
|
|
|
|
2009-02-02 20:19:13 -05:00
|
|
|
sheet.addMergedRegion(new CellRangeAddress(1, 1, 1, 2));
|
2002-03-12 05:38:26 -05:00
|
|
|
|
|
|
|
// Write the output to a file
|
|
|
|
FileOutputStream fileOut = new FileOutputStream("workbook.xls");
|
|
|
|
wb.write(fileOut);
|
|
|
|
fileOut.close();
|
2016-12-18 17:03:31 -05:00
|
|
|
wb.close();
|
2002-03-12 05:38:26 -05:00
|
|
|
}
|
|
|
|
}
|