How to get Merge cells data as it is to Word Document

Hi ,

This is madhu and my doubt is that How can I get Merge cells data ac it is into my word document.

My code is like

for (int rowIndex = 103; rowIndex <=111; rowIndex++)
{
ArrayList list=new ArrayList();
int x=0;
for(int colIndex=1;colIndex<=10;colIndex++)
{
if(worksheet.getCell(rowIndex,colIndex).getStringValue().equalsIgnoreCase("0"))
{
exceldata="";
}
else
{
exceldata=worksheet.getCells().getCell(rowIndex, colIndex).getStringValue();
}
list.add(x,exceldata);
x++;
}
lists.add(new com.crisil.Map(list));
a++;
}
com.crisil.MailMerge customersDataSource = new com.crisil.MailMerge(lists,a,tablename[data],columns[data]);
doc.getMailMerge().executeWithRegions(customersDataSource);

And I defined all the interface methods and it is working for other cases. But for the Merge cells it is not coming.

Only two lines are comig.

Here I am attaching my Excel file.

Thanks

Madhu

Hi Madhu,

I am not sure about your requirement, I have tested with your template file and code, without your customed Interface, I can only printed cell values out. The values got by Aspose.Cells's API were just same as they are in Excel file.

For merged cells, their values are stored in the top-left cell of the merged range, values of other cells in this merged area are empty. To check whether one cell is merged and to get the merged area, you can use Cells.getMergedCells() to get all merged areas in specific sheet and check whether one area of them cover the cell to be checked, also, you can get the height and width of merged area by accumulating the rows height and columns width of this CellArea.

To import it into words with proper format, I think you need to custom your Table/Grid using Aspose.Words's APIs with information such as height and width got by Aspose.Cells, and you can design what you want to create in MS Word and post it to Aspose.Words's forum, they will guide you to create it by Aspose.Words's APIs. Thank you.

By the way, it is recommend to define variables to hold the cell and cell's value for later using, because it will cause unnecessary effect for performance if you call Cells.getCell() and Cell.getStringValue() for many times.