Workbook open exception

Posted by: diegoar27 on 30 October 2017, 1:46 am EST

    • Post Options:
    • Link

    Posted 30 October 2017, 1:46 am EST

    Hi,

    I’m getting an exception when I try Workbook.open(…).

    I pasted the exception that I’m getting with the stack trace and I attached the excel file that I’m using as example.

    Just to clarify I’m converting the file to json and then to .xlsx because I’m simulating my internal process.

    Thanks in advance.

    Diego.

    Exception: Requested value ‘left’ was not found.

    StackTrace: at System.Enum.EnumResult.SetFailure(ParseFailureKind failure, String failureMessageID, Object failureMessageFormatArgument)

    at System.Enum.TryParseEnum(Type enumType, String value, Boolean ignoreCase, EnumResult& parseResult)

    at System.Enum.Parse(Type enumType, String value, Boolean ignoreCase)

    at ᤑ.ᜀ(XmlReader A_0)

    at ᤑ.ᜆ(XmlReader A_0)

    at ᤑ.ᜇ(XmlReader A_0)

    at ᤑ.ᜀ(ᤌ A_0, ᩁ A_1, ᤋ A_2)

    at ᤛ.ᜀ(ᤌ A_0, ᩁ A_1, ᨺ A_2, ᤋ A_3, Dictionary

    2 A_4, List
    1 A_5)

    at ᤛ.ᜀ(ᤌ A_0, ᩁ A_1, ᨺ A_2, Dictionary
    2 A_3, ᤋ A_4, Dictionary
    2 A_5)

    at ᤚ.ᜀ(ᤋ A_0, ᨺ A_1, IList
    1 A_2, Dictionary
    2 A_3)

    at ᤚ.ᜀ(ᤋ A_0, ᨺ A_1)

    at ᤎ.ᜀ(ᨺ A_0, Stream A_1)

    at GrapeCity.Documents.Spread.Workbook.Open(Stream fileStream, String password)

    at Sheets.Controllers.SPServiceController.AddNameSpService(String fileName) in C:\BNA\Test\Sheets\Sheets\Controllers\SPServiceController.cs:line 44

     
    var json = GetJsonByFileName(fileName);
    
                    using (var mems = new MemoryStream())
                    {
    
                        var expo = new Exporter(json);
                        expo.SaveExcel(mems, ExcelFileFormat.XLSX, ExcelSaveFlags.NoFlagsSet);
    
                        var workbook = new Workbook();
                        workbook.Open(mems);
    	}
    }
    private string GetJsonByFileName(string fileName)
            {
                try
                {
                    var filePath = Path.Combine(Server.MapPath("~/App_Data"), fileName);
                    using (var fileStream = System.IO.File.Open(filePath, FileMode.Open))
                    {
                        var result = new Importer()
                            .ImportExcel(fileStream);
    
                        return result;
                    }
                }
                catch (Exception e)
                {
                    return null;
                }
            }
    ```[zip filename="Test-Apportionment.zip"]public\uploads\411e5410f20fe037dab57e54d78de1201509374552730.zip[/zip]
  • Posted 30 October 2017, 10:45 pm EST

    Hello,

    I used the code as follows to open and then save the Excel file you provided with Spread.Services component and got it done without any issues:

    
    
     private IHostingEnvironment _hostingEnvironment;
    
            public HomeController(IHostingEnvironment environment)
            {
                _hostingEnvironment = environment;
            }
            public IActionResult Index()
            {
                var workbook = new Workbook();
                var path = Path.Combine(_hostingEnvironment.WebRootPath, "..\\Test-Apportionment.xlsx");
    
                workbook.Open(path);
                workbook.Save(@"C:\Data\outTest-Apportionment.xlsx");
                return View();      
            }
    
    
    

    Please refer to the attached resulted Excel file.

    Thanks,

    Deepak Sharma

    outTest-Apportionment.zip

  • Posted 31 October 2017, 12:35 am EST

    Thanks for you answer.

    The reason about I’m converting the excel file to Json before open the workbook is because on my database I have all spread.sheet stored as Json. Those spread.sheets were create by spreadjs.sheets or in ms excel and imported to my system.

    So I’m trying test all cases and to do that I makeing those steps.

    1- Convert excel file to Json (using ExcelIO.Importer library)

    2- Convert the Json string to Excel file (using ExcelIO.Exporter library)

    3- Open workbook (using GrapeCity.Documents.Spread.Workbook)

    Thanks!

    Diego.

  • Posted 1 November 2017, 2:43 am EST

    Hello,

    In that case may I know why are you not directly opening the JSON with Spread.Services?

    Thanks,

    Deepak Sharma

  • Posted 1 November 2017, 9:12 am EST

    @deepak, it’s because spread.services is unable to load the json created by spread.sheets as mentioned in this post: https://www.grapecity.com/en/forums/spread-services/exception-create-workbook-

  • Posted 1 November 2017, 7:53 pm EST

    Hello,

    Sorry for the wrong question, I mean to ask why can’t you open the Excel file directly.

    So I’m trying test all cases and to do that I makeing those steps.

    1- Convert excel file to Json (using ExcelIO.Importer library)

    2- Convert the Json string to Excel file (using ExcelIO.Exporter library)

    3- Open workbook (using GrapeCity.Documents.Spread.Workbook)

    Instead of converting the original Excel file to JSON you can directly open the Excel file with Spread.Services. Like I did in my example.

    Thanks,

    Deepak Sharma

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels