Excel found unreadable content- xlsx format and filename is not set in xls

Hello Team,

I am using aspose.cells version 7…0.2 in .NET environment. I was having 2 issues-

1. When extracting the data and creating a .xls file, the file name is not being set based on the file name set in the code. It is set only when the user is getting prompted to open the file. When the file is opened, the name of the file is set to the name of the .aspx page.

Below is my code:
Workbook workbook = new Workbook();
MemoryStream ms = new MemoryStream();
workbook.Save(ms, FileFormatType.Excel97To2003);
this.Response.ContentType = “application/vnd.ms-excel”;
this.Response.AddHeader(“content-disposition”, “inline; filename=Report.xls”);
this.Response.BinaryWrite(ms.ToArray());

2. While trying to create a .xlsx file, it gives me an error- Excel found unreadable content.

Below is the changed code:

workbook.Save(stream, new OoxmlSaveOptions(SaveFormat.Xlsx));


// Send the stream back to the client

this.Response.AddHeader(“Content-Type”, “application/xlsx”);
this.Response.AddHeader(“Content-Disposition”, “inline; filename=Report.xls”);
this.Response.BinaryWrite(ms.ToArray());

Could you please let me know how to rectify this?

Thanks

Hi,

  1. Well, it might be HTTP / SSL or compression issue on your end, please see the document for your reference:
  1. Please try our latest version/fix: Aspose.Cells for .NET (Latest Version)

If you still find the issue, we need a sample project with v7.3.0.3, zip it and post it here to show the issue on our end, we will check it soon.

Also, it looks line an issue in your coding lines, the code may be written as following (see the bold line):

workbook.Save(stream, new OoxmlSaveOptions(SaveFormat.Xlsx));

// Send the stream back to the client

this.Response.AddHeader(“Content-Type”, “application/xlsx”);

this.Response.AddHeader(“Content-Disposition”, “inline; filename=Report.xlsx”);

this.Response.BinaryWrite(ms.ToArray());

Thank you.

I am still getting the error. Here is my code

                    oTargetExcelWorkBook.Save(oITOTargetFileName, new OoxmlSaveOptions(saveFormat));
I am using the latest version of Aspose Cells.

Hi,

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

Please use this code to save your file in XLS or in XLSX format in Response stream.

C#


//Save file and send to client browser using selected format
if (yourFileFormat == “XLS”)
{
workbook.Save(HttpContext.Current.Response, “output.xls”, ContentDisposition.Attachment, new XlsSaveOptions(SaveFormat.Excel97To2003));

}
else
{
workbook.Save(HttpContext.Current.Response, “output.xlsx”, ContentDisposition.Attachment, new OoxmlSaveOptions(SaveFormat.Xlsx));
}

HttpContext.Current.Response.End();

Thanks Shakeel for your reply. I would have been more helpful, if I posted my steps.

I am loading a Tab delimited Text file as follows

                    loadOptions = new LoadOptions(LoadFormat.TabDelimited);
                    loadOptions.ConvertNumericData = true;
                    loadOptions.LoadDataOnly = true;
                    loadOptions.LoadDataOptions.ImportFormula = false;
                ExcelColumnDelimiter = <span style="color: rgb(163, 21, 21);">"\t"</span>;
                txtLoadOptions.ConvertDateTimeData = <span style="color: blue;">false</span>;
                txtLoadOptions.LoadDataOnly = <span style="color: blue;">true</span>;
                txtLoadOptions.LoadDataOptions.ImportFormula = <span style="color: blue;">false</span>;
        <span style="color: green;">//Specify the separator</span>
        txtLoadOptions.Separator = <span style="color: rgb(43, 145, 175);">Convert</span>.ToChar(ExcelColumnDelimiter);
        <span style="color: green;">//Specify the encoding type</span>
        txtLoadOptions.Encoding = System.Text.<span style="color: rgb(43, 145, 175);">Encoding</span>.UTF8;
        sourceFileFormat = <span style="color: rgb(43, 145, 175);">CellsHelper</span>.DetectFileFormat(oITOSourcelFileName);

                        oITOExcelWorkBook = new Workbook(oITOSourcelFileName, txtLoadOptions);
 
 
And Saving the translated Excel file as below
                    oTargetExcelWorkBook = new Workbook(FileFormatType.Xlsx);
            oTargetExcelWorkBook.Worksheets.Clear();
                    if (oITOExcelWorkBook.Worksheets[wsIdx].Cells[startRow, columnId].Value == key)
                    {
                        Worksheet destSheet = oTargetExcelWorkBook.Worksheets[key];
                        Worksheet sourceSheet = oITOExcelWorkBook.Worksheets[wsIdx];
                        Range sourceRange = sourceSheet.Cells.CreateRange(startRow, columnId + 1, (endRow - startRow) + 1, sourceSheet.Cells.MaxDataColumn);
                        Range destRange = destSheet.Cells.CreateRange(0, 0,
                              (endRow - startRow) + 1, sourceSheet.Cells.MaxDataColumn);
                        sourceRange.CopyStyle(destRange);
                        destRange.CopyData(sourceRange);
                        destRange.Worksheet.AutoFitColumns(0, 0,
                              (endRow - startRow) + 1, sourceSheet.Cells.MaxDataColumn);
                    }
oTargetExcelWorkBook.Save(oITOTargetFileName, new OoxmlSaveOptions(saveFormat));
 
 
Thanks for your help
Arul
 

Hi,


I could not test your code properly as there are some objects and pointers for which I do not know about their values. Also, please provide the source Tab Delimited file. Please create a sample application (as requested earlier) with your template and output files to reproduce your issues. You may zip the project (runnable) prior attaching here. We will check your issues soon.

Also, we recommend you to kindly try our latest fix/version: Aspose.Cells for .NET (Latest Version)

Tahnk you.

Arajaram:

Thanks Shakeel for your reply. I would have been more helpful, if I posted my steps.

I am loading a Tab delimited Text file as follows

                    loadOptions = new LoadOptions(LoadFormat.TabDelimited);
                    loadOptions.ConvertNumericData = true;
                    loadOptions.LoadDataOnly = true;
                    loadOptions.LoadDataOptions.ImportFormula = false;
                ExcelColumnDelimiter = <span style="color: rgb(163, 21, 21);">"\t"</span>;
                txtLoadOptions.ConvertDateTimeData = <span style="color: blue;">false</span>;
                txtLoadOptions.LoadDataOnly = <span style="color: blue;">true</span>;
                txtLoadOptions.LoadDataOptions.ImportFormula = <span style="color: blue;">false</span>;
        <span style="color: green;">//Specify the separator</span>
        txtLoadOptions.Separator = <span style="color: rgb(43, 145, 175);">Convert</span>.ToChar(ExcelColumnDelimiter);
        <span style="color: green;">//Specify the encoding type</span>
        txtLoadOptions.Encoding = System.Text.<span style="color: rgb(43, 145, 175);">Encoding</span>.UTF8;
        sourceFileFormat = <span style="color: rgb(43, 145, 175);">CellsHelper</span>.DetectFileFormat(oITOSourcelFileName);

                        oITOExcelWorkBook = new Workbook(oITOSourcelFileName, txtLoadOptions);
 
 
And Saving the translated Excel file as below
                    oTargetExcelWorkBook = new Workbook(FileFormatType.Xlsx);
          oTargetExcelWorkBook.Worksheets.Clear();
                    if (oITOExcelWorkBook.Worksheets[wsIdx].Cells[startRow, columnId].Value == key)
                    {
                        Worksheet destSheet = oTargetExcelWorkBook.Worksheets[key];
                        Worksheet sourceSheet = oITOExcelWorkBook.Worksheets[wsIdx];
                        Range sourceRange = sourceSheet.Cells.CreateRange(startRow, columnId + 1, (endRow - startRow) + 1, sourceSheet.Cells.MaxDataColumn);
                        Range destRange = destSheet.Cells.CreateRange(0, 0,
                              (endRow - startRow) + 1, sourceSheet.Cells.MaxDataColumn);
                        sourceRange.CopyStyle(destRange);
                        destRange.CopyData(sourceRange);
                        destRange.Worksheet.AutoFitColumns(0, 0,
                              (endRow - startRow) + 1, sourceSheet.Cells.MaxDataColumn);
                    }
oTargetExcelWorkBook.Save(oITOTargetFileName + ".out.xlsx", new OoxmlSaveOptions(SaveFormat.Xlsx));
 
 
Thanks for your help
Arul
 
Hi,

Thanks for your sample code and using Aspose.Cells for .NET.

Please remove the RED line in the above code. Probably, this line is corrupting your output workbook. You are removing all worksheets.

Please also make changes as highlighted RED in the last line.

If your problem still occurs, then please provide us sample runnable project replicating your issue.

We will soon look into it and advise you asap.

Thanks Shakeel

I used the Cells 7.3.4 today and removed the Clear statement as you mentioned, I am still facing the same issue. Please advise.

Thanks

Arul

PS: Please find the attached files.

TXT file is the source

XLS and XLSX are the generated files from Aspose .Net component

Hi,

Thanks for your posting and providing us the files.

We will look into your issue with your given code and files and try to reproduce at our end using the latest version: Aspose.Cells for .NET (Latest Version) and help/advise you asap.

Hi,

Thanks for using Aspose.Cells for .NET.

Please check the following code. It loads a template file, then it creates a new workbook from scratch and copy all the worksheets inside a template file to a new workbook.

It makes use of MaxDisplayRange property to get the maximum range of source worksheet.

The code is a modified form of your existing code.

After the execution of code, two output files in Xls and Xlsx formats are created.

1 - template.xls (this is a source template file)
2 - template.xls.out.xls (this is output xls file created by the code)
3 - template.xls.out.xlsx (this is output xlsx file created by the code)

I have attached the template file and the output files and screenshot for your reference. Both output xls and xlsx files are correct and open fine without any error.

C#


string filePath = @“F:\Shak-Data-RW\Downloads\template.xls”;


Workbook oITOExcelWorkBook = new Workbook(filePath);

Workbook oTargetExcelWorkBook = new Workbook();

oTargetExcelWorkBook.Worksheets.Clear();


for (int i = 0; i < oITOExcelWorkBook.Worksheets.Count; i++)

{

Worksheet sourceSheet = oITOExcelWorkBook.Worksheets[i];


Worksheet destSheet = oTargetExcelWorkBook.Worksheets.Add(sourceSheet.Name);


Range maxRange = sourceSheet.Cells.MaxDisplayRange;


Range sourceRange = sourceSheet.Cells.MaxDisplayRange;


Range destRange = destSheet.Cells.CreateRange(0, 0,

sourceRange.RowCount, sourceRange.ColumnCount);


sourceRange.CopyStyle(destRange);

destRange.CopyData(sourceRange);


destRange.Worksheet.AutoFitColumns(0, 0,

sourceRange.RowCount, sourceRange.ColumnCount);

}



//Save target workbook in Xlsx format

oTargetExcelWorkBook.Save(filePath + “.out.xlsx”, new OoxmlSaveOptions(SaveFormat.Xlsx));


//Save target workbook in Xls format

oTargetExcelWorkBook.Save(filePath + “.out.xls”, new XlsSaveOptions(SaveFormat.Excel97To2003));


Screenshot:

Thanks Shakeel.

I tried your build and followed the code changes suggested, but did not work. Here is my code block

        void SeperateWorkSheets(int columnId, ITOFileFormat fileFormat)
        {
            string prevWsName = string.Empty;
            string currWsName = string.Empty;
            int worksheetIdx = -1;
            Dictionary<string, string> worksheetNames = new Dictionary<string, string>();
            Dictionary<string, int> worksheetRows = new Dictionary<string, int>();
        <span style="color: blue;">for</span> (<span style="color: blue;">int</span> wsIdx = 0; wsIdx < oITOExcelWorkBook.Worksheets.Count; wsIdx++)
        {
            <span style="color: blue;">int</span> maxRow = oITOExcelWorkBook.Worksheets[wsIdx].Cells.MaxDataRow;
            <span style="color: blue;">if</span> (maxRow < oITOExcelWorkBook.Worksheets[wsIdx].Cells.MaxRow)
                maxRow = oITOExcelWorkBook.Worksheets[wsIdx].Cells.MaxRow;
            maxRow++;
            <span style="color: blue;">for</span> (<span style="color: blue;">int</span> rowIdx = 0; rowIdx < maxRow; rowIdx++)
            {
                currWsName = oITOExcelWorkBook.Worksheets[wsIdx].Cells[rowIdx, columnId].StringValue;
                <span style="color: blue;">if</span> (prevWsName != currWsName)
                {
                    worksheetNames[currWsName] = currWsName;
                    worksheetRows[currWsName + <span style="color: rgb(163, 21, 21);">"[START]"</span>] = rowIdx;
                    <span style="color: blue;">if</span> (rowIdx > 0)
                    {
                        worksheetRows[prevWsName + <span style="color: rgb(163, 21, 21);">"[END]"</span>] = rowIdx - 1;
                        worksheetNames[prevWsName] = prevWsName;
                    }
                    prevWsName = currWsName;
                }
            }
            worksheetRows[currWsName + <span style="color: rgb(163, 21, 21);">"[END]"</span>] = oITOExcelWorkBook.Worksheets[wsIdx].Cells.MaxDataRow;
        }

        <span style="color: green;">/* Create the new Worksheets */</span>
        <span style="color: blue;">int</span> tempWsId;
        <span style="color: blue;">foreach</span> (<span style="color: blue;">string</span> key <span style="color: blue;">in</span> worksheetNames.Keys)
        {
            oTargetExcelWorkBook.Worksheets.Add(key);
            <span style="color: green;">// tempWsId = oTargetExcelWorkBook.Worksheets.Add(key);</span>
            <span style="color: green;">/*</span>

if (worksheetIdx < 0)
worksheetIdx = tempWsId - 1;
if (oTargetExcelWorkBook.Worksheets[key] != null)
oTargetExcelWorkBook.Worksheets[key].Name = (key + new Guid().ToString()).Substring(0, 30);
*/
// oTargetExcelWorkBook.Worksheets[tempWsId].Name = key;
}

        <span style="color: green;">/* Split them */</span>
        <span style="color: blue;">foreach</span> (<span style="color: blue;">string</span> key <span style="color: blue;">in</span> worksheetNames.Keys)
        {
            <span style="color: blue;">int</span> startRow = worksheetRows[key + <span style="color: rgb(163, 21, 21);">"[START]"</span>];
            <span style="color: blue;">int</span> endRow = worksheetRows[key + <span style="color: rgb(163, 21, 21);">"[END]"</span>];
            <span style="color: blue;">for</span> (<span style="color: blue;">int</span> wsIdx = 0; wsIdx < oITOExcelWorkBook.Worksheets.Count; wsIdx++)
            {
                <span style="color: green;">//if (oITOExcelWorkBook.Worksheets[wsIdx].Name != key)</span>
                <span style="color: green;">//{</span>
                <span style="color: blue;">if</span> (oITOExcelWorkBook.Worksheets[wsIdx].Cells[startRow, columnId].Value == key)
                {
                    <span style="color: rgb(43, 145, 175);">Worksheet</span> destSheet = oTargetExcelWorkBook.Worksheets[key];
                    <span style="color: rgb(43, 145, 175);">Worksheet</span> sourceSheet = oITOExcelWorkBook.Worksheets[wsIdx];
                    <span style="color: rgb(43, 145, 175);">Range</span> sourceRange;
                    <span style="color: green;">//= sourceSheet.Cells.CreateRange(startRow, columnId + 1, (endRow - startRow) + 1, sourceSheet.Cells.MaxDataColumn);</span>
                    sourceRange = sourceSheet.Cells.MaxDisplayRange;
                    <span style="color: rgb(43, 145, 175);">Range</span> destRange;
                    <span style="color: green;">//= destSheet.Cells.CreateRange(0, 0, (endRow - startRow) + 1, sourceSheet.Cells.MaxDataColumn);</span>
                    destRange = destSheet.Cells.CreateRange(0, 0, sourceRange.RowCount, sourceRange.ColumnCount);
                    sourceRange.CopyStyle(destRange);
                    destRange.CopyData(sourceRange);
                    <span style="color: green;">// destRange.Worksheet.AutoFitColumns(0, 0, (endRow - startRow) + 1, sourceSheet.Cells.MaxDataColumn);</span>
                    destRange.Worksheet.AutoFitColumns(0, 0, sourceRange.RowCount, sourceRange.ColumnCount);
                }
                <span style="color: green;">//}</span>
            }
        }

        <span style="color: green;">/* Now Remove the Original Ones * /</span>

for (int wsIdx = worksheetIdx; wsIdx >= 0; wsIdx–)
oITOExcelWorkBook.Worksheets.RemoveAt(wsIdx);

/* Remove the Extra Column * /
for (int wsIdx = 0; wsIdx < oITOExcelWorkBook.Worksheets.Count; wsIdx++)
try { oITOExcelWorkBook.Worksheets[wsIdx].Cells.Columns.RemoveAt(columnId); }
catch { }
*/

        <span style="color: green;">/* Process the File Format */</span>
        <span style="color: blue;">if</span> (fileFormat != <span style="color: blue;">null</span>)
        {
            <span style="color: rgb(43, 145, 175);">Worksheet</span> styleSheet;
            <span style="color: rgb(43, 145, 175);">Range</span> styleRange;
            <span style="color: rgb(43, 145, 175);">Style</span> style;
            <span style="color: rgb(43, 145, 175);">StyleFlag</span> styleFlag;

            <span style="color: blue;">foreach</span> (<span style="color: rgb(43, 145, 175);">ITOFileFormatStyle</span> itoFileFormatStyle <span style="color: blue;">in</span> fileFormat.StyleItems.Values)
            {
                styleFlag = <span style="color: blue;">new</span> <span style="color: rgb(43, 145, 175);">StyleFlag</span>();
                styleFlag.All = <span style="color: blue;">false</span>;
                styleSheet = <span style="color: blue;">null</span>;
                <span style="color: blue;">try</span>
                {
                    styleSheet = oTargetExcelWorkBook.Worksheets[itoFileFormatStyle.WORKSHEETNAME];
                    <span style="color: blue;">if</span> (styleSheet != <span style="color: blue;">null</span>)
                    {
                        styleRange = styleSheet.Cells.CreateRange(itoFileFormatStyle.RangeStartRow, itoFileFormatStyle.RangeStartCol, itoFileFormatStyle.RangeTotalRows, itoFileFormatStyle.RangeTotalCols);

                        style = oTargetExcelWorkBook.Styles[oTargetExcelWorkBook.Styles.Add()];
                        <span style="color: green;">/* We need this for the BG Color */</span>
                        style.Pattern = <span style="color: rgb(43, 145, 175);">BackgroundType</span>.Solid;
                        <span style="color: green;">/* BGCOLOR */</span>
                        <span style="color: blue;">if</span> (itoFileFormatStyle.BGColorValue != Color.Empty)
                        {
                            styleFlag.CellShading = <span style="color: blue;">true</span>;
                            style.ForegroundColor = itoFileFormatStyle.BGColorValue;
                            style.BackgroundColor = itoFileFormatStyle.BGColorValue;
                        }
                        <span style="color: green;">/* FORECOLOR */</span>
                        <span style="color: blue;">if</span> (itoFileFormatStyle.ForeColorValue != Color.Empty)
                        {
                            styleFlag.FontColor = <span style="color: blue;">true</span>;
                            style.Font.Color = itoFileFormatStyle.ForeColorValue;
                        }

                        <span style="color: green;">/* BORDER */</span>
                        <span style="color: blue;">if</span> (itoFileFormatStyle.TopBorderValue != <span style="color: rgb(43, 145, 175);">CellBorderType</span>.None)
                        {
                            styleFlag.TopBorder = <span style="color: blue;">true</span>;
                            style.Borders[<span style="color: rgb(43, 145, 175);">BorderType</span>.TopBorder].LineStyle = itoFileFormatStyle.TopBorderValue;
                        }
                        <span style="color: blue;">if</span> (itoFileFormatStyle.LeftBorderValue != <span style="color: rgb(43, 145, 175);">CellBorderType</span>.None)
                        {
                            styleFlag.LeftBorder = <span style="color: blue;">true</span>;
                            style.Borders[<span style="color: rgb(43, 145, 175);">BorderType</span>.LeftBorder].LineStyle = itoFileFormatStyle.LeftBorderValue;
                        }
                        <span style="color: blue;">if</span> (itoFileFormatStyle.BottomBorderValue != <span style="color: rgb(43, 145, 175);">CellBorderType</span>.None)
                        {
                            styleFlag.BottomBorder = <span style="color: blue;">true</span>;
                            style.Borders[<span style="color: rgb(43, 145, 175);">BorderType</span>.BottomBorder].LineStyle = itoFileFormatStyle.BottomBorderValue;
                        }
                        <span style="color: blue;">if</span> (itoFileFormatStyle.RightBorderValue != <span style="color: rgb(43, 145, 175);">CellBorderType</span>.None)
                        {
                            styleFlag.RightBorder = <span style="color: blue;">true</span>;
                            style.Borders[<span style="color: rgb(43, 145, 175);">BorderType</span>.RightBorder].LineStyle = itoFileFormatStyle.RightBorderValue;
                        }
                        <span style="color: green;">/* FORMAT */</span>
                        <span style="color: blue;">if</span> (itoFileFormatStyle.FormatValue < 0 && !<span style="color: blue;">string</span>.IsNullOrEmpty(itoFileFormatStyle.FORMAT))
                            style.Custom = itoFileFormatStyle.FORMAT;
                        style.Number = itoFileFormatStyle.FormatValue;
                        <span style="color: blue;">if</span> (itoFileFormatStyle.FormatValue != 0 && !<span style="color: blue;">string</span>.IsNullOrEmpty(itoFileFormatStyle.FORMAT))
                            styleFlag.NumberFormat = <span style="color: blue;">true</span>;
                        styleRange.ApplyStyle(style, styleFlag);
                    }
                }
                <span style="color: blue;">catch</span> (<span style="color: rgb(43, 145, 175);">Exception</span> ex)
                { LogException(ex); }
            }
        }

        <span style="color: green;">/* Worksheet Autofitcolumn */</span>
        <span style="color: blue;">for</span> (<span style="color: blue;">int</span> wsIdx = 0; wsIdx < oTargetExcelWorkBook.Worksheets.Count; wsIdx++)
        {
            <span style="color: blue;">try</span> { oTargetExcelWorkBook.Worksheets[wsIdx].AutoFitColumns(); }
            <span style="color: blue;">catch</span> { }
        }

        <span style="color: green;">/* Error Check Option */</span>
        <span style="color: blue;">for</span> (<span style="color: blue;">int</span> wsIdx = 0; wsIdx < oTargetExcelWorkBook.Worksheets.Count; wsIdx++)
        {
            <span style="color: blue;">try</span> {
                <span style="color: rgb(43, 145, 175);">ErrorCheckOptionCollection</span> opts = oTargetExcelWorkBook.Worksheets[wsIdx].ErrorCheckOptions;
                <span style="color: blue;">int</span> optionIdx = opts.Add();
                <span style="color: rgb(43, 145, 175);">ErrorCheckOption</span> opt = opts[optionIdx];
                opt.SetErrorCheck(Aspose.Cells.<span style="color: rgb(43, 145, 175);">ErrorCheckType</span>.InconsistFormula, <span style="color: blue;">false</span>);
                optionIdx = opts.Add();
                opt = opts[optionIdx];
                opt.SetErrorCheck(Aspose.Cells.<span style="color: rgb(43, 145, 175);">ErrorCheckType</span>.InconsistRange, <span style="color: blue;">false</span>);
                optionIdx = opts.Add();
                opt = opts[optionIdx];
                opt.SetErrorCheck(Aspose.Cells.<span style="color: rgb(43, 145, 175);">ErrorCheckType</span>.TextDate, <span style="color: blue;">false</span>);
                optionIdx = opts.Add();
                opt = opts[optionIdx];
                opt.SetErrorCheck(Aspose.Cells.<span style="color: rgb(43, 145, 175);">ErrorCheckType</span>.TextNumber, <span style="color: blue;">false</span>);
                optionIdx = opts.Add();
                opt = opts[optionIdx];
                opt.SetErrorCheck(Aspose.Cells.<span style="color: rgb(43, 145, 175);">ErrorCheckType</span>.Validation, <span style="color: blue;">false</span>);
            }
            <span style="color: blue;">catch</span> { }
        }
    }
}

v

Hi,

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

It seems, there is some issue with your code and it is not that Aspose.Cells for .NET has some bug.

If you feel, your issue is occurring because of some Aspose.Cells for .NET bug, then please provide us a simple runnable sample/project replicating this issue.

Your current code is complex and it is also not runnable. It gives me build errors when I try to execute it. Please remove all your extra code and use hardcoded values to make it runnable to look into this issue further.

It’s better if you attach runnable project without any build errors so that we could run and experiment it and could advise you better.

Shakeel,

I am offended by your reply blaming our code. Here is my simplest project eliminating all code specific to our needs and I am able to reproduce the issue.

Now, I am looking for a solution. Let us know ASAP.

I did not attach the License and the Aspose Assemblies. (v7.3.4.1)

Thanks

Arul

Hi,

Thanks for your sample project. It will surely be helpful in sorting out this issue.

Now, the project is runnable and I am able to run your project and after initial test, the issue is also replicable. We will look into this issue further. If the code is fixable, we will fix the code and if it is Aspose.Cells bug, we will fix the bug.

Please spare us some time to investigate this issue further. We will update you asap.

Hi,

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

We have further investigated your project and fixed the code. Please download the attached fixed project and run it. Now it generates correct xlsx file. I have also attached the output xlsx file for your reference.

Please specific the range which the error check options are applied to. Please check the following code:

C#


for (int wsIdx = 0; wsIdx < oTargetExcelWorkBook.Worksheets.Count; wsIdx++)

{

try {

ErrorCheckOptionCollection opts = oTargetExcelWorkBook.Worksheets[wsIdx].ErrorCheckOptions;




int optionIdx = opts.Add();


ErrorCheckOption opt = opts[optionIdx];


opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.InconsistFormula, false);


opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.InconsistRange, false);


opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.TextDate, false);


opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.TextNumber, false);


opt.SetErrorCheck(Aspose.Cells.ErrorCheckType.Validation, false);


int maxRow = oTargetExcelWorkBook.Worksheets[wsIdx].Cells.MaxRow;


int maxColumn = oTargetExcelWorkBook.Worksheets[wsIdx].Cells.MaxColumn;


maxRow = Math.Max(maxRow, 0);


maxColumn = Math.Max(maxColumn, 0);


opt.AddRange(CellArea.CreateCellArea(0, 0,


maxRow, maxRow));


}


catch { }

}



Shakeel,

Thanks for the help. The fix works.

Arajaram:

Shakeel,

Thanks for the help. The fix works.

Hi,
Thanks for your feedback.

We are pleased to know that this issue is resolved now.

In case, if you encounter any other problem, please feel free to post on Aspose.Cells forums, we will be glad to assist you further.