Click here to Skip to main content
15,886,362 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi coders,

I am generating an excel report and formatting it before showing to user.
I want to apply borders for all cells that have data.(except empty data cells)
I would like to know that is there any method to get collection of data cells to apply borders, instead of using conditional formatting?

Thanks in advance
Posted
Comments
Maciej Los 17-Jul-13 5:53am    
What have you done so far? Where are you stuck? What technology do you use: OpenXML, Interop, other?
nand99deep 19-Jul-13 9:55am    
i have created an excel application and written some data
then, i would like to add borders only for the data cells through vb.net code
currently i added conditional format like below, which is taking much time to add borders and later to release COM objects

dim xlRange as Excel.Range= worksheet.Range("B1:B1000", Type.Missing)
condition1 = xlRange.FormatConditions.Add(Excel.XlFormatConditionType.xlExpression, Formula1:="=NOT(ISBLANK(B1))")
condition1.Borders.LineStyle = Excel.XlLineStyle.xlContinuous
condition1.Borders.Weight = Excel.XlBorderWeight.xlThin

1 solution

1. Interop:
Cells, range which have data: UsedRange[^]. The simplest way to add borders is to use: Range.BorderAround Method[^]. Borders[^] can be formatted with many LineStyle[^].

More: Understanding the Excel Object Model from a .NET Developer's Perspective[^]

2. OpenXML
Borders[^] and Border[^] ;)
 
Share this answer
 
Comments
Espen Harlinn 17-Jul-13 8:40am    
5'ed!
Maciej Los 17-Jul-13 8:54am    
Thank you, Espen ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900