We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Suggested that in the worksheet, the method of style should be changed to public instead of obfuscated

It is suggested that in the worksheet, the method of style should be changed to public instead of confusing,At present, it is troublesome to obtain and set styles only through reflection like this:

  //get Default Style  
  Method method = columns.getClass().getDeclaredMethod("a");
  method.setAccessible(true);
  Column column = (Column) method.invoke(columns);
  Style style = column.getStyle();
  color = style.getForegroundArgbColor();
  style.setForegroundArgbColor(0xFF000000);

  // set Default Style  
  method = column.getClass().getDeclaredMethod("a", Style.class);
  method.setAccessible(true);
  method.invoke(column, style);

@xutao,

Please note, we have Worksheet.Cells.Style attribute that is used to get/set the default style of the worksheet. Similarly we have Worksheet.Cells.GetCellStyle() that is used to obtain the style of the given cell. Moreover, we have ApplyStyle, ApplyRowStyle and ApplyColumnStyle methods, these methods are used to apply style/formatting to worksheet cells, a row or a column.

Hope, the above description will help you.

Thanks for your response。I want to replace the " ffffff00" background in the following sheet with “0xFF003300”. Now it is difficult to deal with it through the provided interface. You can get what you want through reflection processing in the following way, so I hope the corresponding method will become public
image.png (38.5 KB)
image.png (43.4 KB)

Workbook wb = new Workbook("3.xlsx");
Cells cells = wb.getWorksheets().get(0).getCells();
ColumnCollection columns = cells.getColumns();
Method method = columns.getClass().getDeclaredMethod("a");
method.setAccessible(true);
Column column = (Column) method.invoke(columns);
Style style = column.getStyle();
int color = style.getForegroundArgbColor();
System.out.println("Current:" + Integer.toHexString(color));
style.setForegroundArgbColor(0xFF003300);
method = column.getClass().getDeclaredMethod("a", Style.class);
method.setAccessible(true);
method.invoke(column, style);
wb.save("x4.xlsx");

What is the difficulty you got, please elaborate? We will check and discuss the matter.
Also, your devised code segment does not work for your requirements?

Although the code I devised does work my requirements, it is not readable through this reflection,give an example,like this code
Method method = columns.getClass().getDeclaredMethod("a");
Others have no idea what method this “a” calls and what does it do,Therefore, it is suggested that these methods should not be obfuscated

@xutao,

We evaluated it already. I am afraid we do not make Style property for Column object for the users, it is done intentional. Please note, to simulate the operation in MS Excel of applying specific style to one column, we need to check all existing cells in the underlying column and update their styles correspondingly. Also, Column.Style gives ambiguous meanings for some users. Most users might think by changing this property will get the same effect as applying style to the whole column which is wrong, some others may think it only changes one of Column object’s property.

So, considering the above circumstances and things, we only provide a separate ApplyStyle method for Column class to make it same with the operation of MS Excel.

By the way, if you do require to change the style property of Column object, for your special consideration and cases, such as, you do not need to change existing cell’s style and think the operation of updating existing cell’s style might cause unnecessary performance cost for your situation, then we may consider to provide new method to change the style of Column object only.