Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Putting data into merged cells using POI

Posted on 2006-07-01
2
Medium Priority
?
3,288 Views
Last Modified: 2008-03-03
Hi experts, I have a question about using the POI framework to push data out to a spreadsheet having merged cell regions. I've read the poi documentation and I am fine as long as I am trying to push data out to a single cell. For example

HSSFSheet sheet = wb.getSheet("TDP");
HSSFRow row = sheet.getRow(3);
HSSFCell cell = row.createCell(column);            
cell.setCellValue("data");

works just fine.

but putting data into a merged region is quite different entirely and not working for me. I have an Excel template that
has merged cells that cover (A4..H4) and (I4..P4) respectively. I want to data into each to prefill a template according to the users desired layout. I looked at the Region object and that looked promising, but it's MergedRegionAt method takes only a single argument, seemingly a row. So how can you programmatically specify a range and then put data in that range?
0
Comment
Question by:OMyStuckAgin
2 Comments
 
LVL 16

Accepted Solution

by:
Peter Kwan earned 2000 total points
ID: 17027027
You can use the following example (e.g. A4..H4):

HSSFSheet sheet = wb.getSheet("TDP");
HSSFRow row = sheet.getRow(3);
HSSFCell cell = row.createCell(0);          
cell.setCellValue("data");
sheet.addMergeRegion(new Region(3,0,3,7));

The getMergedRegionAt is the index of the merge regions. If you have more than one merge regions, you can use getMergedRegionAt to locate the region by index starting with zero.

0
 

Author Comment

by:OMyStuckAgin
ID: 17030615
Thanks for the explanation. The POI documentation is a little subpar, and does not carry nearly enough examples.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
In this post we will learn different types of Android Layout and some basics of an Android App.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

877 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question