Hi!
I have an issue when I want read the Cell’s Style’s properties.
I flagged only the border’s property and the other properties are not flagged, but (in my case) when I want read the property “isAlignmentApplied()” the method return TRUE.
I replicated the issue only once by one style created from scratch.
image.png (8.8 KB)
image.png (6.1 KB)
@PietroTGK
Hello!
It seems you’re experiencing an issue with the isAlignmentApplied() method returning TRUE even when you haven’t flagged the alignment property in your cell’s style. This can occur if the style was created from scratch and may have default values applied.
To troubleshoot this, you can check the following:
-
Inspect the Style Properties: Ensure that the alignment property is indeed not set. You can print out all the style properties to see if any default values are being applied.
-
Create a New Style: If the issue persists, try creating a new style from scratch and apply it to the cell to see if the problem continues.
-
Update Aspose.Cells: Ensure you are using the latest version of Aspose.Cells, as bugs are often fixed in newer releases.
Here’s a small code snippet to help you inspect the style properties:
var workbook = new Workbook("yourfile.xlsx");
var worksheet = workbook.Worksheets[0];
var cell = worksheet.Cells["A1"];
var style = cell.GetStyle();
Console.WriteLine("Is Alignment Applied: " + style.IsAlignmentApplied());
Console.WriteLine("Horizontal Alignment: " + style.HorizontalAlignment);
Console.WriteLine("Vertical Alignment: " + style.VerticalAlignment);
This will help you identify if any alignment settings are being applied unexpectedly.
If you continue to face issues, consider reaching out on the Aspose forums for more specific assistance.
@PietroTGK
Would you like to provide your sample file and runnable test code? If you could take a screenshot and highlight the error, it would be very helpful for us to locate the issue. We will check it soon.
This is the snippet of code I left a comments below the println method:
String workbookPath = "path\\.......\\song_e_napl_xlsx";
FileInputStream fis = new FileInputStream(workbookPath);
Workbook workbook = new Workbook(fis);
Style borderNew = workbook.createStyle();
Style border1 = workbook.createStyle();
for (int i = 0; i < workbook.getCountOfStylesInPool(); i++) {
Style customStyle = workbook.getStyleInPool(i);
if (customStyle.getName() != null) {
if (customStyle.getName().equals("BorderNew")) {
borderNew = customStyle;
}
if (customStyle.getName().equals("Border1")) {
border1 = customStyle;
}
}
}
/* In this case I created a new style on the Excel ribbon. In a first time I have flagged the Alignment property and
modified the parameter of horizontal alignment, but after I have unflagged it and I saved the style. */
System.out.println("Style name = " + borderNew.getName());
System.out.println("---------------------------");
System.out.println("Alignment = " + borderNew.isAlignmentApplied());
System.out.println("Border = " + borderNew.isBorderApplied());
System.out.println("Fill = " + borderNew.isFillApplied());
System.out.println("Font = " + borderNew.isFontApplied());
System.out.println("Number Format = " + borderNew.isNumberFormatApplied());
System.out.println("Protection = " + borderNew.isProtectionApplied());
/* In this case I created a new style on the Excel ribbon. I have unflagged all the properties except for the Border's
properties and I saved the style. */
System.out.println("\n===========================\n");
System.out.println("Style name = " + border1.getName());
System.out.println("---------------------------");
System.out.println("Alignment = " + border1.isAlignmentApplied());
System.out.println("Border = " + border1.isBorderApplied());
System.out.println("Fill = " + border1.isFillApplied());
System.out.println("Font = " + border1.isFontApplied());
System.out.println("Number Format = " + border1.isNumberFormatApplied());
System.out.println("Protection = " + border1.isProtectionApplied());
}
image.png (8.3 KB)
image.png (8.8 KB)
song_e_napl.zip (7.2 KB)
@PietroTGK
By testing on the latest version v25.10 using the following sample code, we can obtain the correct results.
Workbook book = new Workbook();
Style testStyle = book.createStyle();
testStyle.setHorizontalAlignment(TextAlignmentType.CENTER);
testStyle.setBorder(BorderType.BOTTOM_BORDER, CellBorderType.MEDIUM, Color.getRed());
// Set Gradient pattern on
testStyle.setGradient(true);
// Specify two color gradient fill effects
testStyle.setTwoColorGradient(Color.fromArgb(255, 255, 255), Color.fromArgb(79, 129, 189),
GradientStyleType.HORIZONTAL, 1);
testStyle.getFont().setItalic(true);
testStyle.setNumber(14);
testStyle.setProtectionApplied(true);
System.out.println("---------------------------");
System.out.println("Alignment = " + testStyle.isAlignmentApplied());
System.out.println("Border = " + testStyle.isBorderApplied());
System.out.println("Fill = " + testStyle.isFillApplied());
System.out.println("Font = " + testStyle.isFontApplied());
System.out.println("Number Format = " + testStyle.isNumberFormatApplied());
System.out.println("Protection = " + testStyle.isProtectionApplied());
The output:
---------------------------
Alignment = true
Border = true
Fill = true
Font = true
Number Format = true
Protection = true
By analyzing your sample code, we found that it only reads file data and displays the results. Would you like to describe how the sample file was generated? Was it manually created in Excel? We will check it soon.
@PietroTGK,
I tried your exact sample code snippet with your template XLSX file and it works fine and as expected. See the console output which I get using Aspose.Cells for Java v25.10 (please try it).
Style name = BorderNew
---------------------------
Alignment = false
Border = true
Fill = false
Font = false
Number Format = false
Protection = false
===========================
Style name = Border1
---------------------------
Alignment = false
Border = true
Fill = false
Font = false
Number Format = false
Protection = false
OK. The problem was already resolved with this ticket CELLSJAVA-46409 with the version 25.7.
I used the 24.6. This is the thread: Wrong retrieving of the isAlignmentApplied() flag on the custom style
Thanks!
@PietroTGK,
Thank you for your feedback. It’s good to hear that you’ve resolved the issue by upgrading to the newer version of Aspose.Cells for Java. And, yes, we already addressed similar issue with the isAlignmentApplied() flag for custom styles a few months ago. Moreover, using the latest version of the API is always advantageous, as it includes numerous improvements and bug fixes.