We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

UnMerge doesn't work!

Hi there,


I have this simple code and a very simple Excel file (attached). UnMerge doesn’t work! The cells are still merged. What do you think is wrong? I am using the latest version of Aspose Cells (downloaded today)

Aspose.Cells.License lic = new Aspose.Cells.License();
lic.SetLicense(“Aspose.Total.lic”);
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();
wb.Open(f);
foreach (Aspose.Cells.Worksheet sheet in wb.Worksheets)
{
if (sheet.Name == “Tickmarks”)
{
foreach (CellArea cellArea in sheet.Cells.MergedCells)
{
sheet.Cells.UnMerge(cellArea.StartRow, cellArea.StartColumn, cellArea.EndRow, cellArea.EndColumn);
}
}
}
wb.Save(f);

Hi Basar,

We are able to reproduce the issue using the file provided by you. The issue has been logged wih ID CELLSNET-20719. We will further working on it and will udpate you soon about the findings.

Thanks,

Hi,

Please ignore Salman Shakeel’s post, he might have missed this in his initial test. After looking your code, it is not an issue with the component, rather there is a flaw/error in your code. Please change your code to (see the bold line):

Aspose.Cells.License lic = new Aspose.Cells.License();
lic.SetLicense(“Aspose.Total.lic”);
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook();
wb.Open(f);
foreach (Aspose.Cells.Worksheet sheet in wb.Worksheets)
{
if (sheet.Name == “Tickmarks”)
{
foreach (CellArea cellArea in sheet.Cells.MergedCells)
{
sheet.Cells.UnMerge(cellArea.StartRow, cellArea.StartColumn, cellArea.EndRow - cellArea.StartRow + 1, cellArea.EndColumn - cellArea.StartColumn + 1);
}
}
}
wb.Save(f);

The third and fourth parameter for UnMerge() methods are total_number_of_rows and total_number_of_columns for the range to be merged. So, you got to be careful specifying values for the parameters.

Thank you.

Hi Basar,

Please accept my apologies. Yes, my college Amjad is quite right. I have also tried using the following lines of code and it is working fine.

Cells objcells = objsheet.Cells;
objcells.UnMerge(1, 1, 1, 3);
objcells.UnMerge(3, 0, 1, 2);

Thanks,

Salman & Amjad:


Thank you for suggestions - it worked.

Basar

Hi,
I’m trying to unmerge the cells using the code mentioned above and it just doesn’t work.
I’ve tried:
1)

Cells cells = worksheet.Cells;
cells.UnMerge(12, 1, 10, 1);
2)
 foreach (CellArea cellArea in worksheet.Cells.MergedCells)
{
worksheet.Cells.UnMerge(cellArea.StartRow, cellArea.StartColumn, cellArea.EndRow - cellArea.StartRow + 1, cellArea.EndColumn - cellArea.StartColumn + 1);
}
Nothing has happened. What am I missing?

10x in advance.

Hi,
<!–[if gte mso 9]>
<w:WordDocument>
<w:View>Normal</w:View>
<w:Zoom>0</w:Zoom>
<w:TrackMoves/>
<w:TrackFormatting/>
<w:PunctuationKerning/>
<w:ValidateAgainstSchemas/>
<w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid>
<w:IgnoreMixedContent>false</w:IgnoreMixedContent>
<w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText>
<w:DoNotPromoteQF/>
<w:LidThemeOther>EN-US</w:LidThemeOther>
<w:LidThemeAsian>X-NONE</w:LidThemeAsian>
<w:LidThemeComplexScript>HE</w:LidThemeComplexScript>
<w:Compatibility>
<w:BreakWrappedTables/>
<w:SnapToGridInCell/>
<w:WrapTextWithPunct/>
<w:UseAsianBreakRules/>
<w:DontGrowAutofit/>
<w:SplitPgBreakAndParaMark/>
<w:EnableOpenTypeKerning/>
<w:DontFlipMirrorIndents/>
<w:OverrideTableStyleHps/>
</w:Compatibility>
<m:mathPr>
<m:mathFont m:val=“Cambria Math”/>
<m:brkBin m:val=“before”/>
<m:brkBinSub m:val="–"/>
<m:smallFrac m:val=“off”/>
<m:dispDef/>
<m:lMargin m:val=“0”/>
<m:rMargin m:val=“0”/>
<m:defJc m:val=“centerGroup”/>
<m:wrapIndent m:val=“1440”/>
<m:intLim m:val=“subSup”/>
<m:naryLim m:val=“undOvr”/>
</m:mathPr></w:WordDocument>
<![endif]–><!–[if gte mso 10]>

/* Style Definitions */ table.MsoNormalTable {mso-style-name:"Table Normal"; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0in 5.4pt 0in 5.4pt; mso-para-margin-top:0in; mso-para-margin-right:0in; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0in; line-height:115%; mso-pagination:widow-orphan; font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:Arial; mso-bidi-theme-font:minor-bidi;}

<![endif]–>

Actually it worked, but I also expected that it fills unmerged cells with original values (which is not happened and it’s probably okay), so that’s why I thought that it is a bug.


Hi,


It works fine as I also tested:
Sample code:
Aspose.Cells.Workbook wb = new Aspose.Cells.Workbook(“e:\test2\C1.xlsx”);
Worksheet sheet = wb.Worksheets[0];
foreach (CellArea cellArea in sheet.Cells.MergedCells)
{
sheet.Cells.UnMerge(cellArea.StartRow, cellArea.StartColumn, cellArea.EndRow - cellArea.StartRow + 1, cellArea.EndColumn - cellArea.StartColumn + 1);
}
wb.Save(“e:\test2\outC1.xlsx”);