how to apply style on cells

Last post 09-23-2011, 7:15 AM by Amjad Sahi. 3 replies.
Sort Posts: Previous Next
  •  09-23-2011, 5:40 AM 331496

    how to apply style on cells

    Hello Amjad,
    I have a small trouble with the code im working on -

    <cfobject type="JAVA" action="CREATE" class="xlsgen.XlsStyle" name="styleTechnicalOrientation">
    <cfset styleTechnicalOrientation = wksht.NewStyle()>
    <cfobject type="JAVA" action="CREATE" class="xlsgen.XlsAlignment" name="alignmentTechnical">
    <cfset alignmentTechnical = styleTechnicalOrientation.getAlignment()>
    <cfset alignmentTechnical.putHorizontal(2)>
    <cfset alignmentTechnical.putOrientation(-90)>
    <cfobject type="JAVA" action="CREATE" class="xlsgen.XlsPattern" name="patternTechOrient">
    <cfset patternTechOrient = styleTechnicalOrientation.getPattern()>
    <cfset patternTechOrient.putPattern( 1 )>
    <cfset patternTechOrient.putBackgroundColor("13434879")>

    <cfobject type="JAVA" action="CREATE" class="xlsgen.XlsBorders" name="borders">
    <cfset borders = styleTechnicalOrientation.getBorders()>
    <cfobject type="JAVA" action="CREATE" class="xlsgen.XlsBorder" name="Top">
    <cfset Top = borders.getTop()>
    <cfset Top.putStyle( 1 )>
    <cfobject type="JAVA" action="CREATE" class="xlsgen.XlsBorder" name="Left">
    <cfset Left = borders.getLeft()>
    <cfset Left.putStyle( 1 )>
    <cfobject type="JAVA" action="CREATE" class="xlsgen.XlsBorder" name="Right">
    <cfset Right = borders.getRight()>
    <cfset Right.putStyle( 1 )>
    <cfobject type="JAVA" action="CREATE" class="xlsgen.XlsBorder" name="Bottom">
    <cfset Bottom = borders.getBottom()>
    <cfset Bottom.putStyle( 1 )>

    I need to apply the following code on the style above -

    <cfset styleTechnical1.Apply()>
            <cfset wksht.putLabel(7,7,"Technical")>
            <cfset wksht.putLabel(9,13,"WAvg")>
        <cfset styleTechnicalPercent.Apply()>
            <cfset wksht.putFloat(8,7,"0.40")>
            <cfset wksht.putFloat(10,13,"1.0")>
        <cfset styleContextual1.Apply()>
            <cfset wksht.putLabel(7,14,"Contextual")>
            <cfset wksht.putLabel(9,20,"WAvg")>
        <cfset styleContextualPercent.Apply()>
            <cfset wksht.putFloat(8,14,"0.30")>
            <cfset wksht.putFloat(10,20,"1.0")>
        <cfset stylePersonal1.Apply()>
            <cfset wksht.putLabel(7,21,"Personal")>
            <cfset wksht.putLabel(9,27,"WAvg")>
        <cfset stylePersonalPercent.Apply()>
            <cfset wksht.putFloat(8,21,"0.10")>
            <cfset wksht.putFloat(10,27,"1.0")>
        <cfset styleLeadership1.Apply()>
            <cfset wksht.putLabel(7,28,"Leadership")>
            <cfset wksht.putLabel(9,34,"WAvg")>
        <cfset styleLeadershipPercent.Apply()>
            <cfset wksht.putFloat(8,28,"0.20")>
            <cfset wksht.putFloat(10,34,"1.0")>
        <cfset style1.Apply()>

    i am able to work with aspose using this method which is -

    <cfset style1 = CreateObject("java", "com.aspose.cells.Style")>
    <cfset cells = wksht.getCells()>
    <cfset wksht.getCells().hideColumn(16)>
    <cfset cell = cells.get(9,16)>
    <cfset cell.putValue("Rev")>
    <cfset style1 = cell.getStyle()>
    <cfset style1.getFont().setName("Arial")>
    <cfset style1.getFont().setSize("10")>
    <cfset style1.setPattern(BackgroundType.NONE)>
    <cfset border = style1.getBorders().getByBorderType(BorderType.TOP_BORDER)>
    <cfset border = style1.getBorders().getByBorderType(BorderType.LEFT_BORDER)>
    <cfset border = style1.getBorders().getByBorderType(BorderType.RIGHT_BORDER)>   
    <cfset border = style1.getBorders().getByBorderType(BorderType.BOTTOM_BORDER)>
    <cfset cell.setStyle(style1)>

    but its a long method.

    can you tell me a short method using aspose.
    Filed under: Aspose.Cells bug
     
  •  09-23-2011, 6:02 AM 331501 in reply to 331496

    Re: how to apply style on cells

    rachit:
    ...............

    i am able to work with aspose using this method which is -

    <cfset style1 = CreateObject("java", "com.aspose.cells.Style")>
    <cfset cells = wksht.getCells()>
    <cfset wksht.getCells().hideColumn(16)>
    <cfset cell = cells.get(9,16)>
    <cfset cell.putValue("Rev")>
    <cfset style1 = cell.getStyle()>
    <cfset style1.getFont().setName("Arial")>
    <cfset style1.getFont().setSize("10")>
    <cfset style1.setPattern(BackgroundType.NONE)>
    <cfset border = style1.getBorders().getByBorderType(BorderType.TOP_BORDER)>
    <cfset border = style1.getBorders().getByBorderType(BorderType.LEFT_BORDER)>
    <cfset border = style1.getBorders().getByBorderType(BorderType.RIGHT_BORDER)>   
    <cfset border = style1.getBorders().getByBorderType(BorderType.BOTTOM_BORDER)>
    <cfset cell.setStyle(style1)>

    but its a long method.

    can you tell me a short method using aspose.

    I am afraid there is no other short method to apply borders around cells or setting font attributes. You have to specify top, left, right, bottom borders separately.

    For reference see the document:

    Thank you.

    Amjad Sahi
    Support Developer,
    Aspose Sialkot Team
    Contact Us
     
  •  09-23-2011, 6:35 AM 331508 in reply to 331501

    Re: how to apply style on cells

    Thanks for the reply Amjad, I think i must be more clear on my question.


    My question is that can we define a style earlier just like the example i have given & then apply only cell number & cell value.

    i gave you the example which contains the following code -

    <cfobject type="JAVA" action="CREATE" class="xlsgen.XlsStyle" name="styleTechnicalOrientation">
    <cfset styleTechnicalOrientation = wksht.NewStyle()>
    <cfobject type="JAVA" action="CREATE" class="xlsgen.XlsAlignment" name="alignmentTechnical">
    <cfset alignmentTechnical = styleTechnicalOrientation.getAlignment()>

    here every thing was defined earlier like - border, pattern, alignment, background color, with style named as - "styleTechnicalOrientation".


    then i only have to give the cell number & cell value & apply this to Style - (styleTechnicalOrientation).

    like this one -

            <cfset styleTechnicalOrientation.Apply()>
            <cfset wksht.putLabel(7,7,"Technical")>
            <cfset wksht.putLabel(9,13,"WAvg")>
            <cfset styleTechnicalOrientation.Apply()>
            <cfset wksht.putFloat(8,7,"0.40")>
            <cfset wksht.putFloat(10,13,"1.0")>

    here i only need to write - these lines & automatically is will be set to the style i have mentioned.
     
  •  09-23-2011, 7:15 AM 331518 in reply to 331508

    Re: how to apply style on cells

    Hi,

    I am not completely sure about Xls Gen code segments but, yes, you can create the style object once and set its attributes or options accordingly then you only have to specify the style to your desired cells. e.g

    you may add lines to set style for your desired cells, i.e. (although i am not an expert in cold fusion, so you may modify/fix it accordingly)

    ........................
    <cfset cell = cells.get(10,17)>
    <cfset cell.putValue("Val1")>
    <cfset cell.setStyle(style1)>
    <cfset cell = cells.get(11,18)>
    <cfset cell.putValue("Val2")>
    <cfset cell.setStyle(style1)>
    <cfset cell = cells.get(12,19)>
    <cfset cell.putValue("Val3")>
    <cfset cell.setStyle(style1)>
    ..................

    Also, Aspose.Cells for Java does provide other ways to create style object e.g
    C# code:
    Workbook workbook = new Workbook();
    //...............

    Style style = workbook.createStyle();

    also other way:

    int styleIndex = workbook.getStyles().add();
    Style style = workbook.getStyles().get(styleIndex);


    Hope this helps.

    Thank you.

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