excel borders drawing problem

Posted on 2003-02-19
Medium Priority
Last Modified: 2007-12-19
i wrote a c# code that create an excel sheet and transfer data from a DataView object into it,
my problem is how can draw borders (all borders) around a range on the sheet?
i use the follow code:
m_objRange.Borders(xlDiagonalDown).LineStyle = xlNone
m_objRange.Borders(xlDiagonalUp).LineStyle = xlNone
m_objRange.Borders.LineStyle = xlContinuous
m_objRange.Borders.Weight = xlThin
m_objRange.Borders.ColorIndex = xlAutomatic
(m_objRange is a Excel.Range object pointing on the relevant range)
but i got a compilation error said:
'Excel.Range.Borders' denotes a 'property' where a 'method' was expected.
what do u think about it???

another problem is how can i hide the existing borders that apears on the rest of the sheet?

if u can send me a samle code it will be great (a c# code)

Question by:stanley_123
1 Comment

Accepted Solution

Nebulus_ earned 400 total points
ID: 8040223
I hope this will help you:
(comments represents VBA code)

Excel.Range sel =  exSheet.get_Range(exSheet.Cells[7,7], exSheet.Cells[10,10]);
//Selection.Borders(xlDiagonalDown).LineStyle = xlNone
sel.Borders[Excel.XlBordersIndex.xlDiagonalDown].LineStyle = Excel.Constants.xlNone;
//Selection.Borders(xlDiagonalUp).LineStyle = xlNone
sel.Borders[Excel.XlBordersIndex.xlDiagonalUp].LineStyle = Excel.Constants.xlNone;
//With Selection.Borders(xlEdgeLeft)
//          .LineStyle = xlContinuous
//          .Weight = xlMedium
//          .ColorIndex = xlAutomatic
//End With
sel.Borders[Excel.XlBordersIndex.xlEdgeLeft].LineStyle = Excel.XlLineStyle.xlContinuous;
sel.Borders[Excel.XlBordersIndex.xlEdgeLeft].Weight = Excel.XlBorderWeight.xlMedium;
sel.Borders[Excel.XlBordersIndex.xlEdgeLeft].ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic;
//With Selection.Borders(xlEdgeTop)
//          .LineStyle = xlContinuous
//          .Weight = xlMedium
//          .ColorIndex = xlAutomatic
//End With
sel.Borders[Excel.XlBordersIndex.xlEdgeTop].LineStyle = Excel.XlLineStyle.xlContinuous;
sel.Borders[Excel.XlBordersIndex.xlEdgeTop].Weight = Excel.XlBorderWeight.xlMedium;
sel.Borders[Excel.XlBordersIndex.xlEdgeTop].ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic;
//With Selection.Borders(xlEdgeBottom)
//          .LineStyle = xlContinuous
//          .Weight = xlMedium
//          .ColorIndex = xlAutomatic
//End With
sel.Borders[Excel.XlBordersIndex.xlEdgeBottom].LineStyle = Excel.XlLineStyle.xlContinuous;
sel.Borders[Excel.XlBordersIndex.xlEdgeBottom].Weight = Excel.XlBorderWeight.xlMedium;
sel.Borders[Excel.XlBordersIndex.xlEdgeBottom].ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic;
//With Selection.Borders(xlEdgeRight)
//          .LineStyle = xlContinuous
//          .Weight = xlMedium
//          .ColorIndex = xlAutomatic
//End With
sel.Borders[Excel.XlBordersIndex.xlEdgeRight].LineStyle = Excel.XlLineStyle.xlContinuous;
sel.Borders[Excel.XlBordersIndex.xlEdgeRight].Weight = Excel.XlBorderWeight.xlMedium;
sel.Borders[Excel.XlBordersIndex.xlEdgeRight].ColorIndex = Excel.XlColorIndex.xlColorIndexAutomatic;
//Selection.Borders(xlInsideVertical).LineStyle = xlNone
sel.Borders[Excel.XlBordersIndex.xlInsideVertical].LineStyle = Excel.Constants.xlNone;
//Selection.Borders(xlInsideHorizontal).LineStyle = xlNone
sel.Borders[Excel.XlBordersIndex.xlInsideHorizontal].LineStyle = Excel.Constants.xlNone;

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Suggested Courses

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question