Free Support Forum - aspose.com

Issue with Sheet name having more than 31 characters

Hi Aspose team,

We are encoutering one issue with assigning the sheet name at runtime.

We are fetching the sheet names from one XML and assigning. There is a chance to add some additional characters to the sheet name at runtime based on data

Here is the sample:

string sheetName = <> + (adj.Private ? " Private" : "");

But if the sheet name is exceeding more than 31 characters, we have encountered the following issue

The max length of the sheet name is 31

Please let us know by any chance aspose handle this type of situations by truncating the extra characters.

Hi Kiranmayi,

Thank you for using Aspose products.

Aspose.Cells component follows MS Excel guidelines in its implementation, therefore you cannot set the sheet name having length greater than 31 characters using Aspose.Cells (all flavors). Moreover, Aspose.Cells API does not provide any means to truncate the sheet name in case the length exceeds the specified limit, instead it throws an appropriate exception as mentioned in your message. I am afraid, you have to write you own custom routines to check the text length before setting it as a sheet name. Similarly, if the text length exceeds the limit, you have to come up with your own custom logic to truncate the text accordingly.

Please feel free to write back in case you have further questions.

Hi @babar.raza,

Apache POI provides certain feature of creating safe sheet names,I wish the same feature to be built in ASPOSE as well,if that’s seems to senseful.

Best Regards,
Kushagra Sahni

@kushagra93,

Could you elaborate and provides complete details, what options and API Apache POI provides? We will check it soon.

Hi @Amjad_Sahi,

Kindly refer to the following:

Hope this helps.

Best Regards,
Kushagra

@kushagra93,

We were able to observe the issue but we need to look into it more. We have logged the issue in our database for investigation and for a fix if possible. Once, we will have some news for you, we will update you in this topic.

This issue has been logged as

CELLSNET-46298 – Create safe sheet names similar to Apache POI

@kushagra93,

This is to inform you that we have fixed your issue (logged earlier as “CELLSNET-46298”) now. We have added methods:

CellsHelper.CreateSafeSheetName(string nameProposal) and
CellsHelper.CreateSafeSheetName(string nameProposal, char replaceChar) for your requirements.

We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

@ahsaniqbalsidiqui
Cool! Thanks :slight_smile:

@kushagra93,

You are welcome.

@kushagra93,

Please try our latest version/fix: Aspose.Cells for .NET v18.8.3:

Your issue should be fixed in it.

Let us know your feedback

The issues you have found earlier (filed as CELLSNET-46298) have been fixed in Aspose.Cells for .NET v18.9. This message was posted using BugNotificationTool from Downloads module by Amjad_Sahi

@Amjad_Sahi Is it also available for Java?

@kushagra93,

Sure, you may please try the following sample code for Aspose.Cells for Java and provide feedback.

import com.aspose.cells.CellsHelper;
public class CreateSafeSheetNames {
	public static void main(String[] args) throws Exception {
        // Long name will be truncated to 31 characters
        String name1 = CellsHelper.createSafeSheetName("this is first name which is created using CellsHelper.CreateSafeSheetName and truncated to 31 characters");

        // Any invalid character will be replaced with _
        String name2 = CellsHelper.createSafeSheetName(" <> + (adj.Private ? \" Private\" : \")", '_');//? shall be replaced with _

        // Display first name
        System.out.println(name1);

        // Display second name
        System.out.println(name2);
	}
}