Spire.Spreadsheet is a powerful component to view spreadsheet. As a standalone spreadsheet class library, Spire.Spreadsheet is a companion component to Spire.XLS, which mainly focus on how to display spreadsheet.

Mon May 20, 2019 12:34 pm

Hey

I want to change the backgroundcolor and the border of each cell in a range?

Thank you for help.

GH

GHWels
 
Posts: 90
Joined: Sun Nov 23, 2014 7:22 pm

Tue May 21, 2019 7:57 am

Hello,

Thanks for your inquiry.
According to your previous letters, I did notice that you used the VB. Please kindly refer to the following sample code to achieve your requirement, if there is any question, just feel free to write back.
Code: Select all
 Public Sub New()
     InitializeComponent()
     spreadsheet1.LoadFromFile("Test.xlsx")
     spreadsheet1.ActiveWorksheet.SetActiveCell(1, 1)
 End Sub
 Private Sub Format_Click(ByVal sender As Object, ByVal e As EventArgs) Handles button1.Click
     Dim sheet As IWorksheet = spreadsheet1.ActiveWorksheet
     Dim CellRange As List(Of CellRangeInfo) = spreadsheet1.ActiveWorksheet.GetAllSelectedRanges()
     For m As Integer = 0 To CellRange.Count - 1
         Dim topRow As Integer = CellRange(m).Top
         Dim leftCol As Integer = CellRange(m).Left
         Dim bottomRow As Integer = CellRange(m).Bottom
         Dim rightCol As Integer = CellRange(m).Right
         For i As Integer = topRow To bottomRow
             For j As Integer = leftCol To rightCol
                 'set the backgroundcolor
                 sheet.Item(i, j).Style.ForegroundColor = System.Drawing.Color.Green
                  'set the border style and color
                 sheet.Item(i, j).Style.Borders.All = Utility.BorderLineType.Thick
                 sheet.Item(i, j).Style.Borders.AllColor = Color.Bisque
             Next j
         Next i
     Next m
 End Sub

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Thu May 23, 2019 4:44 am

hey,

Although not exactly what I was looking for, but thanks.

GH

GHWels
 
Posts: 90
Joined: Sun Nov 23, 2014 7:22 pm

Thu May 23, 2019 5:44 am

Hello,

Thanks for your feedback.
Could you please share us with more details about your requirement? Or sharing some screenshots that show your desired effect will be helpful. Then, we will look into it and guide accordingly.
Thanks in advance.

Sincerely,
Lisa
E-iceblue support team
User avatar

Lisa.Li
 
Posts: 1261
Joined: Wed Apr 25, 2018 3:20 am

Return to Spire.Spreadsheet