当前位置:编程学习 > C#/ASP.NET >>

关于用c#写入word的程序要求问题

我开发的程序需要输出一个报表,但出现以下问题:
1)图片显示在报表中,我想让它显示在报表外
2)需要在第三行和第四行写入标题和报表,并且有字体大小要求,无法实现(现在无法显示,不知道原因)
3)如何需要在word最后一行写上单位名称,无法实现
4)很急,在线等啊,大侠帮帮忙啊。
附代码,求大侠指点:
 string strContent ="";
            string strFileName = filepath;
            if (System.IO.File.Exists((string)strFileName))
                System.IO.File.Delete((string)strFileName);
            Object Nothing = System.Reflection.Missing.Value;
            Microsoft.Office.Interop.Word.Document myWordDoc;
            Microsoft.Office.Interop.Word.Application myWordApp = new Microsoft.Office.Interop.Word.Application();
            myWordDoc = myWordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
            //设置页眉
            myWordApp.ActiveWindow.View.Type = WdViewType.wdOutlineView;
            myWordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekPrimaryHeader;
            myWordApp.Selection.InsertAfter(headstring);
            myWordApp.Selection.ParagraphFormat.Alignment =
                WdParagraphAlignment.wdAlignParagraphCenter;
            myWordApp.ActiveWindow.View.SeekView = WdSeekView.wdSeekMainDocument;
            //移动焦点并换行
            object count = 0;
            object WdLine = Word.WdUnits.wdLine;//换一行;
            myWordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
            myWordApp.Selection.TypeParagraph();//插入段落
            myWordApp.Selection.TypeParagraph();

            myWordDoc.Paragraphs.Last.Range.Text = "单位名称";
            myWordDoc.Paragraphs.Last.Range.Bold = 24;
            myWordDoc.Paragraphs.Last.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;

            myWordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);//移动焦点
            myWordApp.Selection.TypeParagraph();//插入段落

            myWordDoc.Paragraphs.Last.Range.Text = "日报表";
            myWordDoc.Paragraphs.Last.Range.Bold = 22;
            myWordDoc.Paragraphs.Last.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
            int hang = dt.Rows.Count;
            int lie = dt.Columns.Count;
            if (hang == 0 || lie == 0)
            {
                frmMain.myFu.strFrmMessageBox(1, pwin, "今天没有数据,无法生成报表!");
            }
            else
            {
                
                Microsoft.Office.Interop.Word.Table newTable = myWordDoc.Tables.Add(myWordApp.Selection.Range, hang+1, lie, ref  Nothing, ref  Nothing);
                //设置表头
                for (int intI = 0; intI < dt.Columns.Count; intI++)
                {

                    newTable.Cell(1, intI + 1).Range .Text  = dt.Columns[intI].ColumnName.ToString();
                }
                //写入表内容 
                for (int i = 0; i < hang; i++)
                {
                    for (int j = 0; j < lie; j++)
                    {
                        newTable.Cell(i + 2, j + 1).Range.Text = dt.Rows[i][j].ToString();
                    }

                }
                myWordApp.Selection.MoveDown(ref WdLine, ref count, ref Nothing);
                //myWordApp.Selection.Cells.VerticalAlignment =Microsoft.Office.Interop.Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//垂直居中
                //myWordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;//水平居中
                //插入图片
                string FileName = jpgpath;
                object LinkToFile = false;
                object Anchor = myWordDoc.Application.Selection.Range;
                myWordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, LinkToFile, ref Nothing, ref  Anchor);
                myWordDoc.Application.ActiveDocument.InlineShapes[1].Width = 100f;
                myWordDoc.Application.ActiveDocument.InlineShapes[1].Height = 100f;
                myWordDoc.Paragraphs.Last.Range.CopyAsPicture();

                myWordDoc.Paragraphs.Last.Range.Text = "文档创建时间:" + DateTime.Now.ToString();//落款
                myWordDoc.Paragraphs.Last.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;

                //将WordDoc文档对象的内容保存为DOC文档 
                try
                {
                    myWordDoc.SaveAs(strFileName);
                    //关闭WordDoc文档对象 
                    myWordDoc.Close(Nothing, Nothing, Nothing);
                    //关闭WordApp组件对象 
                    myWordApp.Quit(Nothing, Nothing, Nothing);
                    this.Close();
                    frmMain.myFu.strFrmMessageBox(1, pwin, "输出日报表成功!!!");
                }
                catch(Exception e)
                {
                   frmMain.myFu.strFrmMessageBox(1, frmMain.pWin, e.Message);
                }
            } --------------------编程问答-------------------- 不会没有人回答吧?????急急叽叽叽叽叽叽叽叽叽叽叽叽 --------------------编程问答-------------------- 速度来大神啊
补充:.NET技术 ,  其他语言
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,