Is there a way to generate word documents dynamically without having word on the machine

后端 未结 8 1879
轻奢々
轻奢々 2021-01-30 15:15

I am planning on generating a Word document on the webserver dynamically. Is there good way of doing this in c#? I know I could script Word to do this but I would prefer another

相关标签:
8条回答
  • 2021-01-30 15:22

    Here is the component that generates document based on the custom template. The documents are generated from the sharepoint list ... so the data is pulled from the list item into the document on the fly: http://store.sharemuch.com/products/generate-word-documents-from-sharepoint-list

    Hope that helps,

    Yaroslav Pentsarskyy Blog: www.sharemuch.com

    0 讨论(0)
  • 2021-01-30 15:25

    Creating the old .DOC files (pre-Word 2007) is nigh-impossible without Word itself. The format is just too complex. Microsoft has released the format description, but it's enough to reduce a grown programmer to tears. There is a reason for that too (historical), but that doesn't make things better.

    The new .DOCX would be easier, although quite a bit of hassle still. However depending on which Word versions you are targeting, there are some other options too.

    For one, there is the classic .RTF. The format is pretty complex still, yet well documented and has strong support across many applications and platforms. And you might use some string-replacing into template files to make things easier (it's non-binary).

    Then there are the "old" Word XML files. I think they worked starting with Word XP. Kinda the predecessors of .DOCX. I've used them, not bad. And the documentation is pretty OK.

    Finally, the easy way that I would choose, is to make a simple HTML. Word can load HTML files just fine starting with version 2000. In the simplest way just change the extension of a HTML file to .DOC and you have it. You can also add a few word-specific tags and comments to make it look even better in Word. Use the Word's Save As...HTML option to see what they are.

    0 讨论(0)
  • 2021-01-30 15:27

    In Office 2007 Microsoft introduced a new file format called the Microsoft Open Office XML Format (.docx). This format is not compatible with older versions of Microsoft Word. Since this is XML you can create or read with out having a Word installed.

    0 讨论(0)
  • 2021-01-30 15:29

    If want to generate Office 2007 documents check the Open XML File Formats, they're simple zipped XML files, check this links:

    • Open XML File Formats: What is it, and how can I get started?
    • Introducing the Office (2007) Open XML File Formats

    Edit: Check this project, can serve you as a good starting point:

    • DocumentMaker

    Seems very simple and customizable, look this code snippet:

    Paragraph p = new Paragraph();
    p.Runs.Add(new Run("Text can have multiple format styles, they can be "));
    p.Runs.Add(new Run("bold and italic", 
            TextFormats.Format.Bold | TextFormats.Format.Italic));
    doc.Paragraphs.Add(p);
    
    0 讨论(0)
  • 2021-01-30 15:29

    Word will quite happily open a HTML with a .doc extension. If you include an internal style sheet, you can have it fully formatted. There was previous post on this subject:

    Export to Word Document in C#

    0 讨论(0)
  • 2021-01-30 15:34

    You'd be better off generating an rtf file, which word will know how to open.

    0 讨论(0)
提交回复
热议问题