How to apply style on cells

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





<cfset alignmentTechnical.putHorizontal(2)>
<cfset alignmentTechnical.putOrientation(-90)>


<cfset patternTechOrient.putPattern( 1 )>
<cfset patternTechOrient.putBackgroundColor(“13434879”)>





<cfset Top.putStyle( 1 )>


<cfset Left.putStyle( 1 )>


<cfset Right.putStyle( 1 )>


<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 wksht.getCells().hideColumn(16)>

<cfset cell.putValue(“Rev”)>

<cfset style1.getFont().setName(“Arial”)>
<cfset style1.getFont().setSize(“10”)>
<cfset style1.setPattern(BackgroundType.NONE)>




<cfset cell.setStyle(style1)>

but its a long method.

can you tell me a short method using aspose.

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

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
















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:
http://www.aspose.com/documentation/java-components/aspose.cells-for-java/adding-borders-to-cells.html

Thank you.

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 -






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.

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.putValue(“Val1”)>
<cfset cell.setStyle(style1)>

<cfset cell.putValue(“Val2”)>
<cfset cell.setStyle(style1)>

<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.