[SOLVED] JsonUtility.ImportData Error 'Row number or column number cannot be zero'

I’m having issues with my JSON ImportData throwing the error ‘Row number or column number cannot be zero’. Here’s my code:

private static void ConvertToExcel(string json)
{
//Create workbook
Workbook workbook = new Workbook();
//Worksheet worksheet = workbook.Worksheets[0];

        //Read JSON files
        JsonLayoutOptions options = new JsonLayoutOptions();

        //Import JSON data
        JsonUtility.ImportData(json, workbook.Worksheets[0].Cells, 0, 0, options); //Error occurs here

        //Save Excel file
        DateTime today = DateTime.Now;
        workbook.Save("../../../" + today.ToString("MMM-dd-yyyy") + "_SurveyResponses.xlsx");
    }

I tried reader other threads with similar problems but I wasn’t able to fix the error using those threads

@AndrewHo21,
Could you please check if your JSON is valid by viewing it with JSON Visualizer of Visual Studio. If there is no problem then share it as a JSON file in the form of ZIP directory.

JSON.zip (1.1 KB)
Here’s the json, there is an extra {} at the beginning and end of the json, but those get removed when I run .toString() on it so I don’t think it affects the JsonUtility.ImportData function

@AndrewHo21,
We have tested the scenario using the JSON text as it is but it failed. This text is declared invalid JSON by online tool https://jsonlint.com. However after removing the extra curly braces at the start and end, which results into a valid JSON text, still issue is observed. We have logged this issue in our database for detailed analysis and will write back here once any feedback is ready to share.

This issue is logged as:

CELLSNET-47462 - Error while importing JSON to Excel

1 Like

When will we have a working solution do you think?

@AndrewHo21,
Well for simple issues it normally takes 3 to 5 working days from analysis to hot fix preparation after detailed analysis, implementation and thorough testing. However for complex issues it may take more time. We hope that we may provide you feedback about the ETA in a couple of days and you may get hot fix in the coming week.

@AndrewHo21,
This is to inform you that we have fixed your issue (logged earlier as “CELLSNET-47462”) now. We will soon provide you the fixed version after performing QA and incorporating other enhancements and fixes.

@AndrewHo21,

Please try our latest version/fix: Aspose.Cells for Java v20.6.4:
aspose-cells-20.6.4-java.zip (7.1 MB)

Your issue should be fixed in it.

Let us know your feedback.

I’m actually using C#. I’m sorry, I should have mentioned that before. I’m using Aspose.Cells v20.6.0

@AndrewHo21,

Please try the .NET fixed version:
Aspose.Cells20.6.4 For .Net2_AuthenticodeSigned.Zip (5.4 MB)
Aspose.Cells20.6.4 For .Net4.0.Zip (5.4 MB)

Let us know your feedback.

I’m sorry if this is a dumb question but I’ve never imported a dll from my computer before and have only ever installed packages using NuGet for VS. How do I go about importing these two files that you have given me? I added the dll as a dependency. I can see the dll in the project assemblies. Am I doing that right?

@AndrewHo21,
Could you please share your project target framework? It seems that you are using .NET Core and if yes, then we need to provide you a different dll i.e. .NET Standard for your project.

The framework I’m using is Microsoft.NETCore.App

@AndrewHo21,
We have logged a request to provide a dll for .NET Core based project as follows.

CELLSNETCORE-70 - Error while importing JSON to Excel

@AndrewHo21,

Please try our latest version/fix: Aspose.Cells for .NET v20.6.5 (attached) - please choose Aspose.Cells for .NET Standard version for your requirements.
Aspose.Cells20.6.5 For .Net2_AuthenticodeSigned.Zip (5.4 MB)
Aspose.Cells20.6.5 For .Net4.0.Zip (5.4 MB)
Aspose.Cells20.6.5 For .NetStandard20.Zip (5.3 MB)

Your issue should be fixed in it.

Let us know your feedback.

I’ve tried the dlls that you have given me. I’ve referenced each DLL and I still get a System.IO.FileNotFoundException

@AndrewHo21,
.NETCore project for Aspose.Cells require the following two dlls only.

  • Aspose.Cells 20.6.5 from Aspose.Cells20.6.5 For .NetStandard20.zip attached above

  • System.Drawing.Common

The other two Dlls are for .NET projects which are not required in the .NET Core project.

Here I am attaching complete solution for your reference. You may give it a try and share the feedback.
TestCells.zip (5.8 MB)

Note that when NuGet package manager is used for downloading the Aspose.Cells dll, the System.Drawing.Common.dll is added automatically as it is part of the dependencies as shown in the .NetStandard2.0 section in the following link:

1 Like

@AndrewHo21,
The issues you have found earlier (filed as CELLSNET-47462) have been fixed in Aspose.Cells for .NET v20.7. This message was posted using Bugs notification tool by ahsaniqbalsidiqui

Hi ahsaniqbalsidiqui,

Is there any option to add static stirng on CELL A1(kind of adding summary of excel)
and JSON string from CELL A2

I tried it but it is giving he Row number or Coloum number cannot be zero

I took row number as 1 instead of 0.
JsonUtility.ImportData(json, workbook.Worksheets[0].Cells, 1, 0, options);

I want to add like this
worksheet.Cells[“A1”].PutValue(“abcde”);

@manipriya,

Which version of Aspose.Cells for .NET you are using? I tested your scenario/case with sample JSON data to import it starting from A2 using our latest version/fix: Aspose.Cells for .NET 22.6.1, it works fine and I do not get any issue or error. The output file is fine tuned.
e.g.
Sample code:

            string inputJson = @"[
                                    { BEFORE: 'before cell', TEST: 'asd1', AFTER: 'after cell' },
                                    { BEFORE: 'before cell', TEST: 'asd2', AFTER: 'after cell' },
                                    { BEFORE: 'before cell', TEST: 'asd3', AFTER: 'after cell' },
                                    { BEFORE: 'before cell', TEST: 'asd4', AFTER: 'after cell' }
                                ]";
            string sheetName = "Sheet1";
            int row = 1; 
            int column = 0;

            Workbook workbook = new Workbook();
            Worksheet worksheet = workbook.Worksheets[sheetName];

            Aspose.Cells.Utility.JsonLayoutOptions options = new Aspose.Cells.Utility.JsonLayoutOptions { ArrayAsTable = true };
            Aspose.Cells.Utility.JsonUtility.ImportData(inputJson, worksheet.Cells, row, column, options);
           
            workbook.Save("e:\\test2\\out1.xlsx");

Please try newer version and let us know if you still find any issue.