NPOI woes



  • In short - I have a spreadsheet. It looks kinda like this.

    I'm processing it with the following code (which should do absolutely nothing other than opening the file, saving it to a MemoryStream and pushing it onwards)

    var culture = Thread.CurrentThread.CurrentCulture;
    try
    {
        Thread.CurrentThread.CurrentCulture = System.Globalization.CultureInfo.InvariantCulture;
        ISheet ws;
        using (var fs = new FileStream(filename, FileMode.Open))
        {
             ws = WorkbookFactory.Create(fs, ImportOption.All).GetSheetAt(0);
        }
        using (var ms = new MemoryStream())
        {
             ws.Workbook.Write(ms);
             var bytes = ms.ToArray();
             //send the byte[] array to client
        }
    }
    finally
    {
        Thread.CurrentThread.CurrentCulture = culture;
    }
    

    But now, my spreadsheet looks like this:

    The fuck is going on out there?


  • 🚽 Regular

    I don't know if this will be of any help, but I switched to EPPlus after NPOI pissed me off with this kind of event too many times.
    It wasn't that big a deal to switch even with a large report generator I had.



  • Well, at least it's not COM interop, which most of the project uses.

    Colleague said he had more luck with the beta version. I wonder which other places will break...



  • Why don't you use Microsoft's Office Automation DLLs?



  • We're trying to move away from having to install Office at the server. It's XML, not rocket science, it shouldn't require the whole thing running all the time.



  • @Maciejasjmj said:

    We're trying to move away from having to install Office at the server.

    I understand this as it is frustrating, but in my experience every substitute has it's own slight differences. If you can put up with an office replacement's oddities then you can swap it out, but you need to be ready to put office back in place if you can't stand the slight variations.

    EDIT: I've not used what you are using as a replacement only other stuff.



  • @Maciejasjmj said:

    We're trying to move away from having to install Office at the server. It's XML, not rocket science, it shouldn't require the whole thing running all the time.

    Seriously? This is your reasoning? Do you have any... good reasons?



  • Well it's not my project anyway. I'd give something else a try, but the project is already a clusterfuck of libraries and we're trying not to make it worse, so we settled on NPOI.

    It sucks, but hey, that new beta does the job so far.



  • @blakeyrat said:

    Seriously? This is your reasoning? Do you have any... good reasons?

    Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

    Look, Microsoft says so, so I'm right.



  • Oh noes. Blakeyrat is defeated.



  • Yeah -- Office might (*shock, horror* 😮) throw up this thing called a "dialog box" that will invariably send your app into a tailspin because it keeps trying to COM automate an Office app that can't hear what your app is saying because the Office app is sitting in a dumb modal loop that has no clue about COM automation messages, and your app has no clue that there's a dialog box on screen.



  • You wouldn't defy the Word of Microsoft, would ya.



  • Huh, I honestly thought it does some sort of "silent mode" or something like that. If it doesn't, it's really not a good idea to put that as a service on a web server...



  • @Maciejasjmj said:

    Huh, I honestly thought it does some sort of "silent mode" or something like that. If it doesn't, it's really not a good idea to put that as a service on a web server...

    Nope, there's no silent mode to be had. Quoting your earlier link (emphasis in original):

    **Interactivity with the desktop:** Office applications assume that they are being run under an interactive desktop. In some circumstances, applications may need to be made visible for certain Automation functions to work correctly. If an unexpected error occurs, or if an unspecified parameter is needed to complete a function, Office is designed to prompt the user with a modal dialog box that asks the user what the user wants to do. A modal dialog box on a non-interactive desktop cannot be dismissed. Therefore, that thread stops responding (hangs) indefinitely. Although certain coding practices can help reduce the likelihood of this issue, these practices cannot prevent the issue entirely. **This fact alone makes running Office Applications from a server-side environment risky and unsupported.**


  • IIRC Microsoft tried doing a silent mode for a while but "pop a dialog for this" was so thoroughly built into the code of the different office apps that they gave up and put the warnings about not using it in something unattended. Note: you can sometimes do things like wait X minutes and if it hasn't finished assume a dialog popped up so kill. This lets you still use office, but you need handling for when those cases happen (have seen: route to manual process, say that specific thingy is unsupported, and a few other options). If you are trying to build something good and without internal tickets don't do it, but sometimes the cost is worth it.


  • ♿ (Parody)

    @blakeyrat said:

    Oh noes. Blakeyrat is defeated.

    Tune in next week to watch another blakeydefeat. Same blakeytime. Same blakeychannel.


  • kills Dumbledore

    Holy Mac Classic, Blakeyrat



  • Not to mention trying to figure out how to license Office when used this way.

    2. Multiple or pooled connections. You may not use hardware or software to multiplex or pool connections, or otherwise allow multiple users or multiple computers or devices to access or use the software indirectly through the licensed computer.


  • Simple! Just expose it over VNC.

    charlie.bz:5901

    @Jaime said:

    1. Multiple or pooled connections. You may not use hardware or software to multiplex or pool connections, or otherwise allow multiple users or multiple computers or devices to access or use the software indirectly through the licensed computer.

    Hmmm, that might be a problem.



  • @tarunik said:

    certain coding practices

    like running a permanent AutoIt script on your server that immediately fake-types Alt-F4 into any window that opens after it starts. That usually works.



  • @flabdablet said:

    like running a permanent AutoIt script on your server that immediately fake-types Alt-F4 into any window that opens after it starts. That usually works.

    Doesn't work when you have to run as a service, where you no longer have an interactive desktop to play with...


  • ♿ (Parody)

    ITALTF4ROBOT<ftw>



  • @tarunik said:

    Doesn't work when you have to run as a service

    If you're already so far down the path of Wrong that you're installing Office on your server, merely needing to launch it on the virtual console's desktop to give it somewhere to put its dialogs is scarcely enough additional Wrong to register.


  • Discourse touched me in a no-no place

    @tarunik said:

    Doesn't work when you have to run as a service, where you no longer have an interactive desktop to play with...

    You can probably use the same tool to open a command prompt, paste "net stop [service]" and close the command prompt.



  • @FrostCat said:

    You can probably use the same tool to open a command prompt, paste "net stop [service]" and close the command prompt.

    However, the service we are talking about here is IIS. Stopping it would have "undesirable side effects".


Log in to reply