Solved

Putting data into merged cells using POI

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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

707 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

18 Experts available now in Live!

Get 1:1 Help Now