Save unauthorized character

Hello.

I want to generate an Excel file using the following code:

var wb = new Workbook();
wb.save(@"D:\Temp\[2025_05_20-12_03_00_496] test.xlsx");

After what the file is generated but It’s cannot be opened.
image.png (7.6 KB)
With the following error :
image.png (4.6 KB)

When i tried to generate a blank Excel file and save as : “[2025_05_20-12_03_00_496] tes2t.xlsx”.
Excel returning the following error :
image.png (9.1 KB)

If you can block or raise an error for this case.
Thanks by advanced.

@B.Leveille

Can you please provide the code you are using to generate the Excel file and any specific error messages you are encountering?

@B.Leveille
[2025_05_20-12_03_00_496] test.zip (6.7 KB)
The file could be opened in my machine.
As MS Excel does not allow ‘[’ and ‘]’ as the part of the file name, please do not use them in the file name, or you can add a check by yourself before saving the file.

@B.Leveille,

Moreover, please see the following simple sample code for your reference on how to implement the check for the presence of invalid characters in the file name which throws an exception if any of chars are found.
e.g.,
Sample code:

final java.util.regex.Pattern INVALID_CHARS_PATTERN = java.util.regex.Pattern.compile("[<>:\"/\\\\|?*\\[\\]]");
String fileName = "[2025_05_20-12_03_00_496] test.xlsx";

try {
        
            if (INVALID_CHARS_PATTERN.matcher(fileName).find()) {
                throw new IllegalArgumentException("Filename contains invalid characters: < > : \" / \\ | ? * [ ]");
            }


            // Proceed with creating workbook only if filename is valid
            com.aspose.cells.Workbook wb = new com.aspose.cells.Workbook();
            wb.save("D:\\Temp\\" + fileName);

            System.out.println("Excel file created successfully.");

} catch (IllegalArgumentException e) {
            System.err.println("Invalid filename: " + e.getMessage());
} catch (Exception e) {
            e.printStackTrace();
}

Hope, this helps a bit.