为方便问题说明:
个人简历包括一张个人基本信息表(一对一),一张工作经历表(一对多)现在个人简历包括个人基本信息和工作经历,做成一个这样格式的表格。

解决方案 »

  1.   

    问题解决我再加一百分送上,EXCEL也行,只要是能把一对一的表和一对多的表都导出到一个页面下就可以。
    不要告诉我网上一搜一大把这的话。
      

  2.   

    再问:由于我有合并过纵向单元格。采用的是生成一个大数目的行,然后生成完毕后(有一些是多行记录,故行数不确定),最后删除没被填充的空行故用wordDoc.Tables[1].Rows[i].Delete()无法获取所需要的行
      

  3.   

    大哥,你这个怎么不使用水晶报表,将水晶报表做导成WORD呢
      

  4.   


    //stemplate_path  WORD模版位置
    //ssave_path      保存WORD位置
    public bool StatToWord(string stemplate_path, string ssave_path)
    {
                WordHelper wordHelper = new WordHelper();
                try
                {
                    wordHelper.Open(stemplate_path);
                    wordHelper.GotoBookMark("姓名");
                    wordHelper.InsertText("张三");
                    wordHelper.GotoBookMark("年龄");
                    wordHelper.InsertText("22");
                    wordHelper.SaveAs(ssave_path);                
                    return true;
                }
                catch
                {
                    return false;
                }
                finally
                {
                    wordHelper.Quit();
                }
    }
      

  5.   

    using System;
    using System.ComponentModel;
    using System.Data;
    using Word;namespace BLL
    {
        //WORD操作的类
        /// <summary>
        /// 在使用前需要先在程序中引入WORD的COM类库
        /// </summary>
        public class WordHelper
        {
            private Word.ApplicationClass oWordApplic;
            private Word.Document oDoc;        public WordHelper()
            {
                oWordApplic = new Word.ApplicationClass();
            }
            ~WordHelper()
            {
                if (oWordApplic != null)
                {
                    object missing = System.Reflection.Missing.Value;
                    oWordApplic.Quit(ref missing, ref missing, ref missing);
                    oWordApplic = null;
                }        }
            /// <summary>
            /// 打开指定的WORD文档 
            /// </summary>
            /// <param name="strFileName">物理路径</param>
            public void Open(string strFileName)
            {
                object fileName = strFileName;
                object readOnly = false;
                object isVisible = true;
                object missing = System.Reflection.Missing.Value;            oDoc = oWordApplic.Documents.Open(ref fileName, ref missing, ref readOnly,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing);            oDoc.Activate();
            }
            /// <summary>
            /// 创建一个新的文档
            /// </summary>
            public void Open()
            {
                object missing = System.Reflection.Missing.Value;
                oDoc = oWordApplic.Documents.Add(ref missing, ref missing, ref missing, ref missing);            oDoc.Activate();
            }
            /// <summary>
            /// 退出程式
            /// </summary>
            public void Quit()
            {
                object missing = System.Reflection.Missing.Value;
                oWordApplic.Quit(ref missing, ref missing, ref missing);
                oWordApplic = null;
            }
            public void QuitWithoutSave()
            {
                object notSave = Word.WdSaveOptions.wdDoNotSaveChanges;
                object missing = System.Reflection.Missing.Value;
                oWordApplic.Quit(ref notSave, ref missing, ref missing);
                oWordApplic = null;
            }
            /// <summary>
            /// 打开指定文件是保存项
            /// </summary>
            public void Save()
            {
                oDoc.Save();
            }
            /// <summary>
            /// 新建文件时候保存项
            /// </summary>
            /// <param name="strFileName">物理文件名</param>
            public void SaveAs(string strFileName)
            {
                object missing = System.Reflection.Missing.Value;
                object fileName = strFileName;            oDoc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing);
            }
            /// <summary>
            /// 保存为HTML形式
            /// </summary>
            /// <param name="strFileName">物理路径</param>
            public void SaveAsHtml(string strFileName)
            {
                object missing = System.Reflection.Missing.Value;
                object fileName = strFileName;
                object Format = (int)Word.WdSaveFormat.wdFormatHTML;
                oDoc.SaveAs(ref fileName, ref Format, ref missing, ref missing, ref missing, ref missing, ref missing,
                    ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
            }
            /// <summary>
            /// 插入文字
            /// </summary>
            /// <param name="strText">要插入的文字</param>
            public void InsertText(string strText)
            {
                oWordApplic.Selection.TypeText(strText);
            }
            #region  插入段落
            /// <summary>
            /// 插入段落
            /// </summary>
            public void InsertParagraphBreak()
            {
                oWordApplic.Selection.TypeParagraph();
            }
            /// <summary>
            /// 插入段落
            /// </summary>
            /// <param name="nline">插入的段落的个数</param>
            public void InsertParagraphBreak(int nline)
            {
                for (int i = 0; i < nline; i++)
                    oWordApplic.Selection.TypeParagraph();
            }
            #endregion
            /// <summary>
            /// 改变插入的当前段落的对齐方式
            /// </summary>
            /// <param name="strType">Center Left Right Justify</param>
            public Word.WdParagraphAlignment SetAlignment(string strType)
            {
                Word.WdParagraphAlignment oldType = oWordApplic.Selection.ParagraphFormat.Alignment;
                switch (strType)
                {
                    case "Center"://正中
                        oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphCenter;
                        break;
                    case "Left"://左
                        oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
                        break;
                    case "Right"://右
                        oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
                        break;
                    case "Justify"://分散
                        oWordApplic.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphJustify;
                        break;
                }
                return oldType;
            }
            public Word.WdParagraphAlignment SetAlignment(Word.WdParagraphAlignment SType)
            {
                Word.WdParagraphAlignment oldType = oWordApplic.Selection.ParagraphFormat.Alignment;
                oWordApplic.Selection.ParagraphFormat.Alignment = SType;
                return oldType;
            }        
      

  6.   


    /// <summary>
            /// 设置文档的字的FONT
            /// </summary>
            /// <param name="strType">Bold Italic Underlined</param>
            public void SetFont(string strType)
            {
                switch (strType)
                {
                    case "Bold":
                        oWordApplic.Selection.Font.Bold = 1;
                        break;
                    case "Italic":
                        oWordApplic.Selection.Font.Italic = 1;
                        break;
                    case "Underlined":
                        oWordApplic.Selection.Font.Subscript = 0;
                        break;
                }
            }
            //取消已设置的各项FONT
            public void SetFont()
            {
                oWordApplic.Selection.Font.Bold = 0;
                oWordApplic.Selection.Font.Italic = 0;
                oWordApplic.Selection.Font.Subscript = 0;        }
            /// <summary>
            ///设置字体名
            /// </summary>
            /// <param name="strType">字体名字</param>
            public string SetFontName(string strType)
            {
                string oldName = oWordApplic.Selection.Font.Name;
                oWordApplic.Selection.Font.Name = strType;
                return oldName;
            }
            /// <summary>
            /// 设置字体大小
            /// </summary>
            /// <param name="nSize">字体大小</param>
            public float SetFontSize(int nSize)
            {
                float oldFont = oWordApplic.Selection.Font.Size;
                oWordApplic.Selection.Font.Size = nSize;
                return oldFont;
            }
            //插入分页符
            public void InsertPagebreak()
            {
                object pBreak = (int)Word.WdBreakType.wdPageBreak;
                oWordApplic.Selection.InsertBreak(ref pBreak);
            }
            /// <summary>
            /// 跳转到指定的书签
            /// </summary>
            /// <param name="strBookMarkName">书签名</param>
            public void GotoBookMark(string strBookMarkName)
            {
                object missing = System.Reflection.Missing.Value;            object Book = (int)Word.WdGoToItem.wdGoToBook;
                object NameBookMark = strBookMarkName;
                oWordApplic.Selection.GoTo(ref Book, ref missing, ref missing, ref NameBookMark);
            }
            //跳转到文档末尾
            public void GoToTheEnd()
            {
                object missing = System.Reflection.Missing.Value;
                object unit;
                unit = Word.WdUnits.wdStory;
                oWordApplic.Selection.EndKey(ref unit, ref missing);
            }
            //跳转到文档的开头
            public void GoToTheBeginning()
            {
                object missing = System.Reflection.Missing.Value;
                object unit;
                unit = Word.WdUnits.wdStory;
                oWordApplic.Selection.HomeKey(ref unit, ref missing);        }
            /// <summary>
            /// 跳转到表
            /// </summary>
            /// <param name="ntable">要跳转的表的序号</param>
            public void GoToTheTable(int ntable)
            {
                object missing = System.Reflection.Missing.Value;
                object what;
                what = Word.WdUnits.wdTable;
                object which;
                which = Word.WdGoToDirection.wdGoToFirst;
                object count;
                count = 1;
                oWordApplic.Selection.GoTo(ref what, ref which, ref count, ref missing);
                oWordApplic.Selection.Find.ClearFormatting();            oWordApplic.Selection.Text = "";
            }
            #region 跳转到下一个表格
            public void GoToRightCell()
            {
                object missing = System.Reflection.Missing.Value;
                object direction;
                direction = Word.WdUnits.wdCell;
                oWordApplic.Selection.MoveRight(ref direction, ref missing, ref missing);
            }        public void GoToLeftCell()
            {
                object missing = System.Reflection.Missing.Value;
                object direction;
                direction = Word.WdUnits.wdCell;
                oWordApplic.Selection.MoveLeft(ref direction, ref missing, ref missing);
            }        public void GoToDownCell()
            {
                object missing = System.Reflection.Missing.Value;
                object direction;
                direction = Word.WdUnits.wdLine;
                oWordApplic.Selection.MoveDown(ref direction, ref missing, ref missing);
            }        public void GoToUpCell()
            {
                object missing = System.Reflection.Missing.Value;
                object direction;
                direction = Word.WdUnits.wdLine;
                oWordApplic.Selection.MoveUp(ref direction, ref missing, ref missing);
            }
            #endregion
            /// <summary>
            /// 下面的是向文档中加入图片
            /// </summary>
            /// <param name="path">物理路径</param>
            public void InsertPicture(string strPath)
            {
                object linktofile = false;
                object savetofile = true;
                object missing = System.Reflection.Missing.Value;
                oWordApplic.Selection.InlineShapes.AddPicture(strPath, ref linktofile, ref savetofile, ref missing);
            }
            /// <summary>
            /// 插入一个表格
            /// </summary>
            /// <param name="nRow">行数</param>
            /// <param name="nColums">列数</param>
            public Word.Table InsertTable(int nRow, int nColums)
            {
                object missing = System.Reflection.Missing.Value;
                return oWordApplic.Selection.Tables.Add(oWordApplic.Selection.Range, nRow, nColums, ref missing, ref missing);
            }
            /// <summary>
            /// 下面的是从数据表中得到数据填充表格
            /// </summary>
            /// <param name="sTable">数据源</param>
            /// <param name="iTable">表在WORD中的序数</param>
            public void FillTableFromDb(DataTable sTable, int iTable)
            {
                int nRow, nColumns;
                nRow = sTable.Rows.Count;
                nColumns = sTable.Columns.Count;
                GoToTheTable(iTable);
                for (int i = 0; i <= nRow; i++)
                {
                    for (int j = 0; j < nColumns; j++)
                    {
                        if (i == 0)
                        {
                            string txt;
                            txt = sTable.Columns[j].ColumnName;
                            InsertText(txt);
                        }
                        else
                        {
                            string txt;
                            txt = sTable.Rows[i - 1].ItemArray[j].ToString();
                            InsertText(txt);
                        }
                        if (j != nColumns - 1)
                            GoToRightCell();
                    }
                    if (i != nRow)
                    {
                        for (int m = 1; m < nColumns; m++)
                            GoToLeftCell();
                        GoToDownCell();
                    }
                }
            }
           
      

  7.   


    是解决了,操作WORD的方法我也有,只是一直头疼动态行数的插入,最后自己出来算法来实现。头疼照片有纵向合并,而无法追加和删除行的问题。水晶报表达不到我的需求,WORD模板页满足不了需求,都是多表多行的动态插入。