CellStyle stringStyle = workbook.createCellStyle();
stringStyle.setAlignment(HorizontalAlignment.CENTER);
this code produces error:
method setAlignment in interface CellStyle cannot be applied to given types;
required: short
found: HorizontalAlignment
reason: actual argument HorizontalAlignment cannot be converted to short by method invocation conversion
so I change the code to use a short:
CellStyle stringStyle = workbook.createCellStyle();
stringStyle.setAlignment((short)1);
And my IDE complains saying:
setAlignment (org.apache.poi.ss.usermodel.HorizontalAlignment) in CellStyle cannot be applied to (short)
So it complains that it wants a short when I give it a HorizontalAlignment and that it wants a HorizontalAligment when I give it a short.
You must have different apache poi versions in classpath. So your IDE is confused about this.
In apache poi 3.12 there is void setAlignment(short align) and there is public final static short ALIGN_CENTER = 0x2;. So code would be
CellStyle stringStyle = workbook.createCellStyle();
stringStyle.setAlignment(CellStyle.ALIGN_CENTER);
for apache poi 3.12.
But since apache poi 3.15 this method is deprecated and since apache poi 3.17 it is removed and now only void setAlignment(HorizontalAlignment align) can be used having HorizontalAlignment as the parameter. So code would be
CellStyle stringStyle = workbook.createCellStyle();
stringStyle.setAlignment(HorizontalAlignment.CENTER);
for apache poi 3.17.
I suspect your problem with your IDE results from the fact, that jars from different versions apache poi 3.12 and apache poi 3.17 are in classpath of your IDE. This is not supported and must be avoided.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With