C#编写打印word文档(包含图片)代码,可以实现吗?
         谢谢!急用!!!!!!

解决方案 »

  1.   

    C#调用word打印
      

  2.   

    //打印的代码如下:
     2 Microsoft.Office.Interop.Word.Application app = null;
     3            Microsoft.Office.Interop.Word.Document doc = null;
     4            object missing = System.Reflection.Missing.Value;
     5            object templateFile = Application.StartupPath + @"\表单模版.doc";
     6            try
     7            {
     8                app = new Microsoft.Office.Interop.Word.ApplicationClass();
     9                doc = app.Documents.Add(ref templateFile, ref missing, ref missing, ref missing);
    10                try
    11                {
    12                    foreach (Microsoft.Office.Interop.Word.Book bm in doc.Books)
    13                    {
    14                        bm.Select();
    15                        string item = bm.Name;
    16                        if (item.Equals("in_time"))
    17                        {
    18                            bm.Range.Text = table.inTime == null ? "" : table.inTime.ToString();
    19                        }
    20                        else if (item.Equals("car_id"))
    21                        {
    22                            bm.Range.Text = table.carID == null ? "" : table.carID.ToString();
    23                        }
    24                                       }
    25                }
    26                catch
    27                {
    28                }
    29                //打印
    30               doc.PrintOut(ref missing, ref missing, ref missing, ref missing, 
    31                    ref missing, ref missing, ref missing, ref missing, ref missing, 
    32                    ref missing, ref missing, ref missing, ref missing, ref missing, 
    33                    ref missing, ref missing, ref missing, ref missing);
    34                     }
    35            catch (Exception exp)
    36            {
    37                MessageBox.Show(exp.Message, this.Text);
    38            }
    39//销毁word进程
    40            finally
    41            {
    42               object saveChange = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
    43                if (doc != null)
    44                    doc.Close(ref saveChange, ref missing, ref missing);
    45                if (app != null)
    46                    app.Quit(ref missing, ref missing, ref missing);
    47            }
    48 
    49
      

  3.   

    为什么建议使用报表实现?前不久刚做过一个输出Word的项目,当输出数据量较大时(超过3页),明显感觉到那个数据一个一个在Word文档中蹦出来,看起来就像有个打字高手在旁边打字一样!好像回到了386时代!
      

  4.   


    水晶或者MS ReportViewer
    后者免费!