[size=16px]同时导出4个datagridview到word中,要是表格形式的,和datagridview的样式差不多也可以,最好可以自己设计表格样式,在线等,急急急[/size]

解决方案 »

  1.   

    你直接拼接成html里面就能用<table>这类的html元素,然后改成doc的扩展名, 别人word打开看不出html的
      

  2.   

    可以自己画word表格,做成word模板,然后向里面填充数据,我以前做过一个类似的东西。
      

  3.   

    你会向word里面写数据吗?跟那个类似。
      

  4.   

    你把你的doc保存为html就可以看到结构是如何的了,然后么你用如何写txt文件的方式把内容放到一个文件里,保存为。doc扩展名
      

  5.   


     //根据数据的行数插入表格行            object start = 0;
                object end = 0;
                Range tableLocation = doc.Range(ref start, ref end);            //获得第十行表格并拆分成需要的行和列
                Cell cell = doc.Tables[1].Cell(10, 1);
                object Rownum = null;
                if (dt3.Rows.Count > 0)
                {
                    Rownum = dt3.Rows.Count;
                }
                else
                {
                    Rownum = 1;
                }            object Columnnum = 9;
                int num = 0;            cell.Split(ref Rownum, ref Columnnum);            if (Convert.ToInt32(Rownum) >= 1)
                {
                    while (num < dt3.Rows.Count)
                    {   //循环插入产品数据
                        for (int i = 10; i < 10 + Convert.ToInt32(Rownum); i++)
                        {
                            doc.Tables[1].Cell(i, 1).Range.Text = "0" + (num + 1).ToString();
                            if (dt3.Rows[num][0] != null)
                            {
                                doc.Tables[1].Cell(i, 2).Range.Text = dt3.Rows[num][0].ToString();
                            }
                            else
                            {
                                doc.Tables[1].Cell(i, 2).Range.Text = "";
                            }
                            if (dt3.Rows[num][1] != null)
                            {
                                doc.Tables[1].Cell(i, 3).Range.Text = dt3.Rows[num][1].ToString();
                            }
                            else
                            {
                                doc.Tables[1].Cell(i, 3).Range.Text = "";
                            }
                            if (dt3.Rows[num][2] != null)
                            {
                                doc.Tables[1].Cell(i, 4).Range.Text = dt3.Rows[num][2].ToString();
                            }
                            else
                            {
                                doc.Tables[1].Cell(i, 4).Range.Text = "";
                            }
                            if (dt3.Rows[num][3] != null)
                            {
                                doc.Tables[1].Cell(i, 5).Range.Text = dt3.Rows[num][3].ToString();
                            }
                            else
                            {
                                doc.Tables[1].Cell(i, 5).Range.Text = "";
                            }
                            if (dt3.Rows[num][4] != null)
                            {
                                doc.Tables[1].Cell(i, 6).Range.Text = dt3.Rows[num][4].ToString();
                            }
                            else
                            {
                                doc.Tables[1].Cell(i, 6).Range.Text = "";
                            }
                            if (dt3.Rows[num][5] != null)
                            {
                                doc.Tables[1].Cell(i, 7).Range.Text = dt3.Rows[num][5].ToString();
                            }
                            else
                            {
                                doc.Tables[1].Cell(i, 7).Range.Text = "";
                            }
                            if (dt3.Rows[num][6] != null)
                            {
                                doc.Tables[1].Cell(i, 8).Range.Text = dt3.Rows[num][6].ToString();
                            }
                            else
                            {
                                doc.Tables[1].Cell(i, 8).Range.Text = "";
                            }
                            doc.Tables[1].Cell(i, 9).Range.Text = "";
                            num++;
                        }
                    }
                }
                //页面Normal.dot模板保存问题
                doc.Application.NormalTemplate.Saved = true;            //页眉
                appWord.ActiveWindow.ActivePane.View.SeekView = WdSeekView.wdSeekCurrentPageHeader;//显示页眉
                appWord.Selection.ParagraphFormat.Borders[WdBorderType.wdBorderBottom].LineStyle = WdLineStyle.wdLineStyleNone;//去掉页眉线
                //生成word
                object filename = null;            if (dt2.Rows.Count > 0)
                {
                    if (dt2.Rows[0][3] != null)
                    {
                        if (isEnd)
                        {
                            filename = HostingEnvironment.ApplicationPhysicalPath + @"upload\word\" + @"" + number + ".doc";
                        }
                        else
                        {
                            filename = HostingEnvironment.ApplicationPhysicalPath + @"\upload\word\" + @"" + number + ".doc";
                        }
                    }
                    else
                    {
                        if (isEnd)
                        {
                            filename = HostingEnvironment.ApplicationPhysicalPath + @"upload\word\" + @"送货单.doc";
                        }
                        else
                        {
                            filename = HostingEnvironment.ApplicationPhysicalPath + @"\upload\word\" + @"送货单.doc";
                        }
                    }
                }
                else
                {
                    if (isEnd)
                    {
                        filename = HostingEnvironment.ApplicationPhysicalPath + @"upload\word\" + @"送货单.doc";
                    }
                    else
                    {
                        filename = HostingEnvironment.ApplicationPhysicalPath + @"\upload\word\" + @"送货单.doc";
                    }
                }
                object miss = System.Reflection.Missing.Value;
                doc.SaveAs(ref filename, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss, ref miss);
                object missingValue = System.Type.Missing;
                object doNotSaveChanges = WdSaveOptions.wdDoNotSaveChanges;
                doc.Close(ref doNotSaveChanges, ref missingValue, ref missingValue);
                appWord.Application.Quit(ref miss, ref miss, ref miss);
                doc = null;
                appWord = null;            //}
                //catch(Exception ex)
                //{            //}
            }
            #endregion
      

  6.   

    不知道你看不看得懂,首先新建一个word,在里面添加一个table,做成模板
    然后根据自己的需要插入数据,方法里你可以把四个datagridview用datatable作为参数传进去
      

  7.   


    楼上各位贴出了如何将dataGridView中的数据导出到word中,你同时导出4个dataGridView,只需要把4个datagridView的结果集放到一个数据集里,就可以了。