CellStyle stringStyle = workbook.createCellStyle();
stringStyle.setAlignment(HorizontalAlignment.CENTER);
Run Code Online (Sandbox Code Playgroud)
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);
Run Code Online (Sandbox Code Playgroud)
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.
您的apache poi类路径中必须具有不同的版本。因此您的IDE对此感到困惑。
在apache poi 3.12其中存在setAlignment(short align)无效并且存在公共最终静态short ALIGN_CENTER = 0x2; 。所以代码是
CellStyle stringStyle = workbook.createCellStyle();
stringStyle.setAlignment(CellStyle.ALIGN_CENTER);
Run Code Online (Sandbox Code Playgroud)
为apache poi 3.12。
但是,由于apache poi 3.15这种方法已被弃用,因为apache poi 3.17它被去除,现在只有空隙参考setAlignment(的HorizontalAlignment对齐)可以具有可以使用的HorizontalAlignment作为parammeter。所以代码是
CellStyle stringStyle = workbook.createCellStyle();
stringStyle.setAlignment(HorizontalAlignment.CENTER);
Run Code Online (Sandbox Code Playgroud)
为apache poi 3.17。
我怀疑你的问题,从这个事实你的IDE结果,那罐子从不同的版本apache poi 3.12,并apache poi 3.17在你的IDE的类路径。不支持此操作,必须避免。
| 归档时间: |
|
| 查看次数: |
2989 次 |
| 最近记录: |