我根据JAVADOC的文档写了如下代码,但是可以写入数据,但是无法生成样式,请给予下支持。
Workbook excel = new Workbook();//创建excel
Worksheet worksheet=excel.getWorksheets().get(0);
Cells cells=worksheet.getCells();
cells.setColumnWidthPixel(0, 60);//定义列和宽度
cells.setColumnWidthPixel(1, 20);
cells.setColumnWidthPixel(2, 40);
cells.setColumnWidthPixel(3, 50);
ImageOrPrintOptions imageOrPrintOptions=new ImageOrPrintOptions();
StyleFlag flag1 = new StyleFlag();
flag1.setFontName(true);
flag1.setCellShading(true);
flag1.setBorders(true);
cells.getCell(0, 1).putValue("test1");//生成测试数据
cells.getCell(0, 2).putValue("test2");
cells.getCell(0, 3).putValue("test3");
cells.getCell(0, 4).putValue("test4");
Range range=cells.createRange("A1","A4");
Style style1 = excel.createStyle();
style1.setHorizontalAlignment(TextAlignmentType.CENTER);
style1.setForegroundColor(Color.getBlack());
style1.setBackgroundColor(Color.getRed());
range.setStyle(style1);//将style添加至表格
// excel.getWorksheets().get(0).getCells().get("A1").setStyle(style1);
// range.applyStyle(style1, flag1);
imageOrPrintOptions.setImageFormat(ImageFormat.getBmp());
SheetRender render = new SheetRender(worksheet,imageOrPrintOptions);
render.toImage(0, "C:\Users\Desktop\1.bmp");