使用HSSFCellStyle旋转列 Headers 使用方法setRotation正常工作如下程序---
public static void main(String[] args)throws Exception
{
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFSheet spreadsheet = workbook.createSheet(
"Text direction");
HSSFRow row = spreadsheet.createRow(2);
HSSFCellStyle myStyle = workbook.createCellStyle();
myStyle.setRotation((short) 0);
HSSFCell cell = row.createCell(1);
cell.setCellValue("0D angle");
cell.setCellStyle(myStyle);
myStyle=workbook.createCellStyle();
myStyle.setRotation((short) 90);
cell = row.createCell(3);
cell.setCellValue("30D angle");
cell.setCellStyle(myStyle);
myStyle=workbook.createCellStyle();
myStyle.setRotation((short) -90);
cell = row.createCell(5);
cell.setCellValue("90D angle");
cell.setCellStyle(myStyle);
FileOutputStream out = new FileOutputStream(
new File("textdirection.xlsx"));
workbook.write(out);
out.close();
System.out.println(
"textdirection.xlsx written successfully");
}
但是相同的代码使用XSSF输出文件列 Headers 不能旋转 . 下面的代码使用XSSF--
public static void main(String[] args)throws Exception
{
XSSFWorkbook workbook = new XSSFWorkbook();
XSSFSheet spreadsheet = workbook.createSheet(
"Text direction");
XSSFRow row = spreadsheet.createRow(2);
XSSFCellStyle myStyle = workbook.createCellStyle();
myStyle.setRotation((short) 0);
XSSFCell cell = row.createCell(1);
cell.setCellValue("0D angle");
cell.setCellStyle(myStyle);
myStyle=workbook.createCellStyle();
myStyle.setRotation((short) 180);
cell = row.createCell(3);
cell.setCellValue("30D angle");
cell.setCellStyle(myStyle);
myStyle=workbook.createCellStyle();
myStyle.setRotation((short) -180);
cell = row.createCell(5);
cell.setCellValue("90D angle");
cell.setCellStyle(myStyle);
FileOutputStream out = new FileOutputStream(
new File("textdirection.xlsx"));
workbook.write(out);
out.close();
System.out.println(
"textdirection.xlsx written successfully");
}
所以任何人都可以给我一个暗示 .
谢谢 .
1 回答
这些都与XLS和XLSX表格和工作簿的格式有关 - 它们是不同的 .
这是
setRotation()
在setRotation()
方法上的一部分:所以,这是你愿意做的正确的例子:
}