Solved

Putting data into merged cells using POI

Posted on 2006-07-01
2
2,776 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java Filesystem manipulation of Word Docx file (find replace text) 3 66
Requested array size exceeds VM limit 3 85
maven example error 3 53
Java JRE greater than 1.6 5 51
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

867 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now