日期:2014-05-18  浏览次数:20767 次

asp.net 用后台代码实现打印服务器的word文档
功能说明:

  用户在网页上直接点击网页上的一个打印按钮,服务器就直接打印相对应的word文档出来。。


兄弟姐妹们,有搞过的快帮忙一下。。先谢谢!

------解决方案--------------------
服务器安装Word

以Com组件方式调用Word

具体实现可以找找网上的调用Excel或者Word的代码

要是自己试的话,先在引用里面添加Com引用,把Word添加进去,然后再实例化Word,打开文件,打印,退出。
------解决方案--------------------
在网上找找有没有第三方的打印控件?
------解决方案--------------------
C# code
 
///==============================================================

/// Office File Reader

///==============================================================

using System;

using System.Text;

using System.Runtime.InteropServices;


namespace OfficeFileReader
{
  #region Stuff you Dont even need to look at
  [Flags]

  public enum IFILTER_INIT
  {

    NONE = 0,

    CANON_PARAGRAPHS = 1,

    HARD_LINE_BREAKS = 2,

    CANON_HYPHENS = 4,

    CANON_SPACES = 8,

    APPLY_INDEX_ATTRIBUTES = 16,

    APPLY_CRAWL_ATTRIBUTES = 256,

    APPLY_OTHER_ATTRIBUTES = 32,

    INDEXING_ONLY = 64,

    SEARCH_LINKS = 128,

    FILTER_OWNED_VALUE_OK = 512

  }


  [Flags]

  public enum IFILTER_FLAGS
  {

    OLE_PROPERTIES = 1

  }


  public enum CHUNK_BREAKTYPE
  {

    CHUNK_NO_BREAK = 0,

    CHUNK_EOW = 1,

    CHUNK_EOS = 2,

    CHUNK_EOP = 3,

    CHUNK_EOC = 4

  }


  [Flags]

  public enum CHUNKSTATE
  {

    CHUNK_TEXT = 0x1,

    CHUNK_VALUE = 0x2,

    CHUNK_FILTER_OWNED_VALUE = 0x4

  }


  public enum PSKIND
  {

    LPWSTR = 0,

    PROPID = 1

  }


  [StructLayout(LayoutKind.Sequential)]

  public struct PROPSPEC
  {

    public uint ulKind;

    public uint propid;

    public IntPtr lpwstr;

  }


  [StructLayout(LayoutKind.Sequential)]

  public struct FULLPROPSPEC
  {

    public Guid guidPropSet;

    public PROPSPEC psProperty;

  }


  [StructLayout(LayoutKind.Sequential)]

  public struct STAT_CHUNK
  {

    public uint idChunk;

    [MarshalAs(UnmanagedType.U4)]
    public CHUNK_BREAKTYPE breakType;

    [MarshalAs(UnmanagedType.U4)]
    public CHUNKSTATE flags;

    public uint locale;

    [MarshalAs(UnmanagedType.Struct)]
    public FULLPROPSPEC attribute;

    public uint idChunkSource;

    public uint cwcStartSource;

    public uint cwcLenSource;

  }


  [StructLayout(LayoutKind.Sequential)]

&nbs