Smart Marker in Alternating Background Color

Last post 02-24-2009, 12:16 AM by Amjad Sahi. 3 replies.
Sort Posts: Previous Next
  •  02-20-2009, 5:15 PM 166283

    Smart Marker in Alternating Background Color

    Is there a easy way to make the rows generated by the "Smart Markers" feature to come out in alternating background color?  Is there a parameter I can set and have it automatically come out in alternating background color?

    Someone posted an answer but it is not very clear to me.  I tried this and it did not work for me.
    http://www.aspose.com/community/forums/thread/15536/alternating-background.aspx
     
  •  02-21-2009, 1:32 AM 166307 in reply to 166283

    Re: Smart Marker in Alternating Background Color

    Attachment: Present (inaccessible)

    Hi,

    Thanks for your inquiry.

    Well, you have to use your own code to set the alternative filling color for the rows using Aspose.Cells APIs. In the latest versions of Aspose.Cells for .NET, you may set the the colors in the following way.

    I have created a sample code for your need, kindly consult it.

    Sample code:

                      Dim dt As New DataTable("MyData")
                      dt.Columns.Add(New DataColumn("MyField", GetType(String)))
                      dt.Columns.Add(New DataColumn("MyField2", GetType(String)))

                      Dim dr As DataRow = dt.NewRow()
                      dr("MyField") = "1"
                      dr("MyField2") = "ABC"
                      dt.Rows.Add(dr)
                      dr = dt.NewRow()
                      dr("MyField") = "2"
                      dr("MyField2") = "DEF"
                      dt.Rows.Add(dr)
                      dr = dt.NewRow()
                      dr("MyField") = "3"
                      dr("MyField2") = "MCF"
                      dt.Rows.Add(dr)
                      dr = dt.NewRow()
                      dr("MyField") = "4"
                      dr("MyField2") = "MCF"
                      dt.Rows.Add(dr)
                      dr = dt.NewRow()
                      dr("MyField") = "5"
                      dr("MyField2") = "JKG"
                      dt.Rows.Add(dr)

                      Dim designer As New WorkbookDesigner()
                      designer.Workbook.Worksheets("Sheet1").Cells("A1").PutValue("&=MyData.MyField(noadd)")
                      designer.Workbook.Worksheets("Sheet1").Cells("B1").PutValue("&=MyData.MyField2(noadd)")
                      designer.SetDataSource(dt)
                      designer.Process(False)
                      designer.Workbook.ConvertNumericData = True

                      Dim style1 As Style = designer.Workbook.Styles(designer.Workbook.Styles.Add())
                      style1.ForegroundColor = Color.Yellow
                      style1.Pattern = BackgroundType.Solid

                      Dim style2 As Style = designer.Workbook.Styles(designer.Workbook.Styles.Add())
                      style2.ForegroundColor = Color.Gray
                      style2.Pattern = BackgroundType.Solid

                      For i As Integer = 0 To designer.Workbook.Worksheets(0).Cells.MaxDataRow
                            For j As Integer = 0 To designer.Workbook.Worksheets(0).Cells.MaxDataColumn
                                  If i Mod 2 = 0 Then
                                        designer.Workbook.Worksheets(0).Cells(i, j).SetStyle(style1)
                                  Else
                                        designer.Workbook.Worksheets(0).Cells(i, j).SetStyle(style2)
                                  End If
                            Next j

                      Next i

                      designer.Save("f:\test\out_msm2.xls", FileFormatType.Default)
     
     
    I have also attached the output file here.
     
    Thank you.

    Amjad Sahi
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
  •  02-23-2009, 2:16 PM 166513 in reply to 166307

    Re: Smart Marker in Alternating Background Color

    Thank you for the clear and concise example!  This will allow me to get what I need.

    It would be great if in a later version, Aspose can provide a feature for the user to specify alternating colors without having to write his/her own code. 
     
  •  02-24-2009, 12:16 AM 166572 in reply to 166513

    Re: Smart Marker in Alternating Background Color

    Hi,

    Well, I think, alternatively, you may also use Conditional formattings to apply your desired formattings upon data. For reference, please check the following documentation topic:

    http://www.aspose.com/documentation/file-format-components/aspose.cells-for-.net-and-java/conditional-formatting.html

    Thank you.


    Amjad Sahi
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
View as RSS news feed in XML