Aspose Cells for java技术问题

我根据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");

@changmi,

您可以使用最新版本Aspose.Cells for Java 19.4.0尝试以下示例代码并提供您的反馈。

// Create a workbook.
Workbook workbook = new Workbook();

// Create a new style object.
Style style = workbook.createStyle();

// Set the number format.
style.setNumber(14);

// Set the font color to red color.
style.getFont().setColor(com.aspose.cells.Color.getRed());
style.setPattern(BackgroundType.SOLID);
style.setForegroundColor(com.aspose.cells.Color.getYellow());

// Name the style.
style.setName(“MyCustomDate”);

// Get the first worksheet cells.
Cells cells = workbook.getWorksheets().get(0).getCells();

// Specify the style (described above) to A1 cell.
cells.get(“A1”).setStyle(style);

// Create a range (B1:D1).
Range range = cells.createRange(“B6”, “D10”);

// Initialize styleflag object.
StyleFlag flag = new StyleFlag();

// Set all formatting attributes on.
flag.setAll(true);

Style style2 = workbook.getNamedStyle(“MyCustomDate”);

// Apply the style (described above)to the range.
range.applyStyle(style2, flag);

cells.get(“C8”).putValue(43105);

// Save the excel file.
workbook.save(“outputModifyThroughStyleObject.xlsx”);
ImageOrPrintOptions imageOrPrintOptions=new ImageOrPrintOptions();
imageOrPrintOptions.setImageType((ImageType.BMP));

SheetRender render = new SheetRender(workbook.getWorksheets().get(0),imageOrPrintOptions);

render.toImage(0, “1.bmp”);