"You want to put a string longer than 32K..." error with non-excel formats

Hi, using Aspose .NET 5.2.1, I’m getting the following error: You want to put a string longer than 32K to Cell B5. MS Excel only allows to put a string shorter than 32K to a Cell.


I understand the excel file format won’t allow values greater than this length, and so I would expect this error when trying to save to excel. However, I get this when adding values to a workbook whose SaveOptions.SaveFormat has been set to SaveFormat.CSV,
SaveFormat.Pdf, or any other (non-excel) format.

Why should the excel limitation prevent me from exporting un-truncated data to an unrelated format? Is there no workaround? My intention had been to truncate the data when exporting to excel, and leaving it as it is when exporting to other formats. It would seem that Aspose isn’t capable of this.

Hi,

Thanks for your posting and using Aspose.Cells for .NET.

Your have given a valid reason.

Please download and try the latest version:
Aspose.Cells
for .NET v7.2.0.4

and see if it resolves the problem. Let us know your feedback.

If the problem still occurs, then please provide us your sample test code to replicate this issue. We will look into it and log it as a bug.

I can confirm that this error still occurs in v7.2.0.4.


The following code should reproduce the error, although I don’t believe this is correct behaviour:

// make a string with 33000 characters, which is longer than excel’s (and aspose’s?) 32767 character limit
StringBuilder sb = new StringBuilder(33000);
for ( int i=0; i<33000; i++ )
sb.Append(“x”);
string longVal = sb.ToString();

// prepare a workbook to be saved as a CSV file
Workbook workbook = new Workbook(FileFormatType.CSV);
workbook.Worksheets[0].Name = “Test file”;

// attempt to put the value in the cell here. Gives “excel” error even though it is to be saved as a CSV file.
workbook.Worksheets[0].Cells[0,0].PutValue(longVal);

workbook.Save(“test.csv”);

Hi,

Thanks for your code example. I was able to replicate this issue using your code with the latest version:
Aspose.Cells
for .NET v7.2.0.5



I have attached the screenshot for a reference.

I have logged this issue in our database. Development team will investigate this issue and once the issue is resolved or we have some other update for you, we will let you know asap.

This issue has been logged as CELLSNET-40646.

C#


// make a string with 33000 characters, which is longer than excel’s (and aspose’s?) 32767 character limit

StringBuilder sb = new StringBuilder(33000);

for (int i = 0; i < 33000; i++)

sb.Append(“x”);

string longVal = sb.ToString();


// prepare a workbook to be saved as a CSV file

Workbook workbook = new Workbook(FileFormatType.CSV);

workbook.Worksheets[0].Name = “Test file”;


// attempt to put the value in the cell here. Gives “excel” error even though it is to be saved as a CSV file.

workbook.Worksheets[0].Cells[0, 0].PutValue(longVal);


workbook.Save(“test.csv”);



Exception:
Aspose.Cells.CellsException was unhandled
Message="You want to put a string longer than 32K to Cell A1. MS Excel only allows to put a string shorter than 32K to a Cell."
Source="Aspose.Cells"
StackTrace:
at Aspose.Cells.Cell.PutValue(String stringValue)

Screenshot:

Thanks for your help.

Hi,

Please try the new fix v7.2.0.6.

We have provided a new option:

Workbook.Settings.CheckExcelRestriction

When you set this property as false, we will not
give exception for long string value that is longer than 32K and you can save
it completely to CSV file later. However, if you save the workbook as Excel
files, such as XLS, XLSX with such kind of invalid cell value, unexpected
problem may occur for the created Excel file.


Thank you.

Brilliant, that’s a really quick turn-around! That does exactly what I needed.


Thanks!


The issues you have found earlier (filed as CELLSNET-40646) have been fixed in this update.


This message was posted using Notification2Forum from Downloads module by aspose.notifier.

This works for me too.
Thank you!!

@Aviw,

Good to know that your issue is sorted out by the suggested attribute. Feel free to contact us any time if you need further help or have some other issue or queries, we will be happy to assist you soon.