LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Automatically Setting Row Height with Merged Cells

Hi All,
I am working on a C# application that requires me to enter multi-line
data into an Excel 2003 spreadsheet. I am wondering how to
automatically resize the row height of merged cells to accomodate all
of this text. I attempted to use a dummy cell with the same column
width as the merged cells to discern the row height, but this is not
working.

Below is a snippet of the code that I am using...

// dummy cell location
string cell = "AA19";
string tempRowHeight = ""; // object for storing original
dummy cell height
// Create a non-merged dummy cell so we can determine the
necessary height of the row
Excel.Range dummyCell =
(Excel.Range)worksheet.get_Range(cell, cell);
// Get the original row height so that we can reset the
dummy cell when we are finished
tempRowHeight = dummyCell.RowHeight.ToString();
// Set the dummyCell column width to the width of the
merged range
dummyCell.ColumnWidth = columnWidth;

dummyCell.WrapText = true; // force the cell to resize

dummyCell.Value2 = locText;

// get the rowHeight of the resized cell
string rowHeight = dummyCell.RowHeight.ToString();

// remove the text from the dummy cell before continuing
dummyCell.Value2 = "";
dummyCell.RowHeight = tempRowHeight;
// release the com objects

System.Runtime.InteropServices.Marshal.FinalReleas eComObject(dummyCell);
dummyCell = null;

return rowHeight

I then use the calculated rowHeight to set the rowHeight of the merged
area. Has anyone else attempted a solution like this with any success?


Any help would be much appreciated!

Katherine

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merged cells won't Autofit row height Hpyifur Excel Discussion (Misc queries) 27 May 20th 23 07:45 PM
Automatically Adjusting Row Height in Merged Cells MGC Excel Discussion (Misc queries) 12 October 1st 07 08:19 PM
row height increase automatically to fit contents of merged cells JB Excel Discussion (Misc queries) 1 May 22nd 07 07:37 PM
Row height and Merged Cells Darin Kramer[_3_] Excel Programming 3 February 28th 05 04:23 PM
Row Height for merged cells Kaval Excel Programming 1 July 12th 04 04:26 AM


All times are GMT +1. The time now is 02:02 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"