Free Support Forum - aspose.com

Autofit columu and row not working with merge cell


#1

Hi Team,

I am generating excel in my application using latest version of Aspose.Cells. I want to dynamically set height and width of cell as per content of cell. For that i have set autofit row and column but height of cell is not change according to cell content. Due to that user is unable to show whole text of cell.
I have attached working application. To run it you required to add latest version DLL file of Aspose.Cells.
Please suggest me solution.
ConsoleAspose.zip (54.0 KB)


#2

@siriussynoptek,

I have tried to perform all these tasks in Excel and observed that Excel also does not autofit the row height when cells are merged. As Aspose.Cells mimics the Excel features, that is why this feature is not working. For testing purpose perform these steps in Excel and if it works, share the steps to perform it. We will check the scenario and try to provide similar functionality using Aspose.Cells.


#3

@siriussynoptek,

You may auto-fit rows height having merged cells via Aspose.Cells (although this may not be supported in MS Excel manually). See the updated sample code which works fine for your needs:
e.g
Sample code:

            Workbook workbook = new Workbook();
            //Get the first (default) worksheet.
            Worksheet sheet = workbook.Worksheets[0];
            //Get the cells in the sheet.
            Cells cells = sheet.Cells;
            //Merging two cells (B5:C5)into a single cell(B5).
            cells.Merge(4, 0, 1, 5);


            Cell cell = sheet.Cells[4, 0];
            Style style = sheet.Cells[4, 0].GetStyle();
            style.IsTextWrapped = true;
            cell.SetStyle(style);
            //Put some value into the merged cell.
            cells["A5"].PutValue("Please select the conversion rate and velocity between each stage for the waterfall type you selected in the prior question. For reference, we have included definitions of each stage.Marketing through tele – Marketing sources an inquiry that passes through a telequalification function before acceptance/rejection by a field sales force.  Inquiry: The total number of raw responses or hand-raisers to an outbound or inbound marketing activity. Relatively little is known about the prospect at this point. Automation qualified lead (AQL): A lead that has been qualified via an automated system or tool and is deemed ready for a receiving function to work. Teleprospecting accepted lead (TAL): A lead that has been formally accepted by the teleprospecting function, which is then compelled to work the lead in a given timeframe to promote or disqualify it. Teleprospecting qualified lead (TQL): A lead that has been qualified via teleprospecting and is deemed ready for a receiving function (e.g. field rep, channel partner) to work. Sales accepted lead (SAL): A lead that has been formally accepted by the sales function, which is then compelled to work the lead in a given timeframe to promote or disqualify it. Sales qualified lead (SQL): A lead that has evolved into opportunities – complete with estimated revenue and timeframe to close. Won business: An opportunity that has converted to a closed/won deal.");

            AutoFitterOptions options = new AutoFitterOptions();
            options.AutoFitMergedCellsType = AutoFitMergedCellsType.EachLine;
            sheet.AutoFitRows(options);
            sheet.AutoFitColumns();
            //Save the file.
            workbook.Save("e:\\test2\\out1.xls"); 

Hope, this helps a bit.