C# Word Document Generation?



  • I'm working on a system that needs to generate a lot of reports, and I'm looking for a way to replace what we currently have. The way documents are created now is via a 4,000 line class that picks apart an RTF, replaces data in its specified location, and then recreates a new RTF. This. Is. Ugly. Making changes to these reports is a pain in the rear, and I'm looking for a more versitile solution.

    I've looked at using COM objects to generate Word documents, but they're just too darn slow. Does anyone know of a good library that exists for creating/altering Word documents (via C#)? I'm ok with a either an open source or a commercial solution, but I'd like to know if anyone else has run into this before, and what their experiences have been. Anyone have any insight into some of the libraries that exist? What should I stay away from, what should I take a closer look at, etc?

    Thanks for any help you can provide... I'm just so tired of wading through all the lines upon lines of RTF special codes inside the code we have now.

     -SF



  • If your looking just for the SDK for generating Word 2007 documents for .Net then your looking for the Open XML Format SDK. Version 2.0 is available from here (requires .Net 3.5 I do believe). Version 1.0 for .Net 3.0 is available here.



  • Hmm, I'll have to look into it. Currently, the apps that have to
    generate reports are in .NET 1.1 and 2.0, but there's no reason I can't
    upgrade them to 3.0 or 3.5. Anyone else have any ideas? If I don't have
    to make the migration to 3.x that would be ideal, but I might have to
    in the end.

    -SF



  • If all you are doing is generating reports, is there a reason you are not using a reporting component library that offers RTF / Word export capabilities? Almost all the big reporting components like Crystal Reports, Active Reports, DevExpress, NetAdvantage have this capability.



  • I probably should have been a bit more black and white with what this is going to be used for from the beginning. Now that my coffee has kicked in, here's the deal. All I really need is to be able to:

    • Combine Word documents programatically.
    • Replace text in Word documents programatically.

    Mostly this is being used to generate letters/bills with info filled in from a MySql database, and like I said earlier, I'm tired of maintaining the code that generates RTFs from scratch. I'll take a look at the things you mention above, and see what they can do for me. Anything that will let me crack open a Word doc, find/replace, then save it to a new location will make my days much, much brighter.

     -SF



  • Is there some reason you can't use VBA to do this? I've never tried to automate Office apps with it myself, but I understand it's really quite powerful.



  • In that case, you may want to look at Visual Studio Tools for Office.  It's available for .Net 2.0 or higher and VS 2005 and 2008 and if I remember correctly works with Office 2003 / 2007 documents.  It pretty much wraps all the existing COM objects anyways so it is probably still "slow", but it does make Office Automation a hell of a lot easier than it was a few years ago.



  • @SheepFister said:

    Mostly this is being used to generate letters/bills with info filled in from a MySql database

    Any reason you can't do this using a Mail Merge in Word?



  • Was about to say "that sounds like a Mail Merge" but someone beat me to it.

    Yah, Crystal Reports, SSRS.. quite a number of off-the-shelf ways of doing it.



  • @Cassidy said:

    Was about to say "that sounds like a Mail Merge" but someone beat me to it.

    Yah, Crystal Reports, SSRS.. quite a number of off-the-shelf ways of doing it.

    I was about to say "HOLY CRAP WHAT A NECRO" but... oh wait, nobody beat me to it.

    HOLY CRAP WHAT A NECRO.



  • Ah, crap - I didn't look at the dates, I caught Scarlet's last post, whipped up to catch the gist and thumped my reply in.

    Doh!



  • @Cassidy said:

    Ah, crap - I didn't look at the dates, I caught Scarlet's last post, whipped up to catch the gist and thumped my reply in.

    Doh!

    Don't worry, I'm sure the user from 3 years ago will come here and see the post and think "Oh, MailMerge... OF COURSE!"


  • ObXKCD:




  • @Sutherlands said:

    HOLY CRAP WHAT A NECRO.

    Damn it! I didn't look at the dates either, it showed up at the top of the list with the unread posts indicator and I didn't recognise the material so I assumed it was new. I guess the thread was bumped by a spam post which got deleted before I saw it. Sorry, everyone.


  • Discourse touched me in a no-no place

    @Scarlet Manuka said:

    I guess the thread was bumped by a spam post which got deleted[...]
    It was.



  • @Cassidy said:

    ObXKCD:


    I have a story about this happening to me.  It was with a highly unusual oracle error that I searched online and only found one thread from 2 years ago asking the same thing and with no solution given.  Looking at the description of the program he was working on it looked exactly like one of the systems on our program.  Upon some questioning with the team who was responsible for that system, I found the guy who actually started the thread and he did eventually figure out how to solve the issue.  The issue had something to do with a combination of a project build setting, oracle patch version, and server platform that caused the error, and with a few obscure setting changes with oracle and it worked.


  • @Anketam said:

    I found the guy
     

    In a sense, you found DenverCoder9.

    You are a legend.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.