ImportTwoDimensionArray gives exception

Hi,

ImportTwoDimensionArray function give this exception: Aspose.Cells.CellsException: You want to put a string longer than 32K to Cell G1. MS Excel only allows to put a string shorter than 32K to a Cell.

Could you please have a look?

Thanks

@ServerSide527,

Thanks for your query.

I have tried to reproduce this issue using following sample code but no exception is observed. Please send us your sample console application(runnable) and template file(if any) which can be used here to observe the problem and provide our feedback.

Workbook wb = new Workbook();
string[,] array = new string[,]
{
    {"cat", "dog"},
    {"bird", "fish"},
};
wb.Worksheets[0].Cells.ImportTwoDimensionArray(array, 0, 6);//Copying data to column G and H
wb.Save("output.xlsx");

Hi and thank you for your prompt reply.
I totally agree with your solution but that is too small.

What about if i insert something > 32k in a single cell?
We get an exception correct. But is there any workaround for that?
I found this :
var txtLoadOptions = new TxtLoadOptions { ConvertDateTimeData = true, ConvertNumericData = true, LoadStyleStrategy = TxtLoadStyleStrategy.BuiltIn };
txtLoadOptions.CheckExcelRestriction = false;

Thanks

@ServerSide527,

TxtLoadOptions option can be used to load existing files containing long text. It cannot be used with ImportTwoDimensionArray(). You may please use some own logic to check the length of string in the array which is to be imported to Excel file.

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.

@ServerSide527,

I guess you may try to add a line of code to your code segment before importing the two dimensional arrays (containing a value greater than 32k):
e.g
Sample code:

..............
workbook.Settings.CheckExcelRestriction = false;
workbook.Worksheets[0].Cells.ImportTwoDimensionArray(array, 0, 6);

Please note, you should not save the workbook to MS Excel format(e.g XLS/XLSX, etc.) in this case as you might get some unexpected error when saving to MS Excel file format.

Hi,

it’s an MS Excel file, so i have to check the size and must be less than 32k.

Thanks

@ServerSide527,

Following sample code may clear the issue. You can upload more than 32K data by using workbook.Settings.CheckExcelRestriction property.

Workbook wb = new Workbook();
string[,] array = new string[,]
{
    {"cat", "dog"},
    {"bird", "fish"},
};
array[0, 0] = File.ReadAllText(path + "sample.txt");
wb.Settings.CheckExcelRestriction = false;
wb.Worksheets[0].Cells.ImportTwoDimensionArray(array, 0, 6);//Copying data to column G and H

sample.zip (301 Bytes)