C# Excel cells formating

G

Guest

Hi,

I have an application that creates Excel files and I ma having trouble
formatting cells.

I fill all cells required, sewt fonts and everything, but have a cell that
contains multiple text rows.
ie.
Company one
Address abc
Phone: 223-323-4244

I put above text in a cell, set wraptext=true. It resize the row height to
show all info, but keeps same column width showing the info incorrectly as it
is to narrow to show a line by line.
ie. It is shown in a 7 characters width x 7 rows:
company
one
address
abc
phone:
223-
323-4244

I merged 3 cells to accomodate all the text, but it does not reset the row
height as I was expecting and it left a blank space at the bottom of the cell.

Any suggestion?


Here is the related code:

oSheet1 = (Excel.Worksheet) oNewBook.ActiveSheet;
sAddress = cFiles.ReadINIFile(conForm.sPath
+ "\\Checkmatic.INI","ProviderAddress");
sAddress = sAddress.Replace("<cr>","\n"); // multirow address
// Call Excel class to set cell value
dExcel.setCellValue((Excel.Range) oSheet1.Cells[nRow1,1],sAddress.Trim());
// Get cell range
oRange = oSheet1.get_Range("A" + nRow1.ToString(),"A" + nRow1.ToString());
// Wrap text
oRange.WrapText = true;
// Get cells range for merging
oRange = oSheet1.get_Range("A" + nRow1.ToString(),"C" + nRow1.ToString());
oRange.Select();
oRange.Merge(false);
// Align cell
oRange.VerticalAlignment = Excel.XlVAlign.xlVAlignTop;
oRange.HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top