| 网站首页 | 业界新闻 | 技术文章 | 视频教程 | 下载频道 | 程序源码 | 个人空间 | 编程论坛 |
 
| 技术教程首页 | 开发语言 | WEB开发 | .NET技术 | 数据库 | 操作系统 | 网页制作 |
 
 
您现在的位置: 编程中国 >> 技术教程 >> .NET技术 >> ASP.NET >> ASP.NET技术资料 >> 正文
  ►  在.NET环境下将报表导出EXCEL和WORD
在.NET环境下将报表导出EXCEL和WORD
作者:不详    阅读人次:……    文章来源:不详    发布时间:2007-8-25    网友评论()条
 

 

        Next



        '得到的表所有行,赋值给单元格

        For Each Row In Table.Rows

          rowIndex = rowIndex + 1

          colIndex = 0

          For Each Col In Table.Columns

            colIndex = colIndex + 1

            xlApp.Cells(rowIndex, colIndex) = Row(Col.ColumnName)

          Next

        Next



        With xlSheet

          .Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Name = "黑体"

          '设标题为黑体字

          .Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Bold = True

          '标题字体加粗

          .Range(.Cells(1, 1), .Cells(rowIndex, colIndex)).Borders.LineStyle = 1

          '设表格边框样式

        End With



        With xlSheet.PageSetup

          .LeftHeader = "" & Chr(10) & "&""楷体_GB2312,常规""&10公司名称:"  ' & Gsmc

          .CenterHeader = "&""楷体_GB2312,常规""公司人员情况表&""宋体,常规""" & Chr(10) & "&""楷体_GB2312,常规""&10日 期:"

          .RightHeader = "" & Chr(10) & "&""楷体_GB2312,常规""&10单位:"

          .LeftFooter = "&""楷体_GB2312,常规""&10制表人:"

          .CenterFooter = "&""楷体_GB2312,常规""&10制表日期:"

          .RightFooter = "&""楷体_GB2312,常规""&10第&P页 共&N页"

        End With



        xlApp.Visible = True





3.将表中的内容导出到WORD

        Dim wordApp As New Word.Application()

        Dim myDoc As Word.Document

        Dim oTable As Word.Table



        Dim rowIndex, colIndex As Integer

        rowIndex = 1

        colIndex = 0



        wordApp.Documents.Add()

        myDoc = wordApp.ActiveDocument



        Dim Table As New DataTable()

        Table = CreaTable()



        oTable = myDoc.Tables.Add(Range:=myDoc.Range(Start:=0, End:=0), NumRows:=Table.Rows.Count + 1, NumColumns:=Table.Columns.Count)



        '将所得到的表的列名,赋值给单元格

        Dim Col As DataColumn

        Dim Row As DataRow

        For Each Col In Table.Columns

          colIndex = colIndex + 1

          oTable.Cell(1, colIndex).Range.InsertAfter(Col.ColumnName)

        Next



        '得到的表所有行,赋值给单元格

        For Each Row In Table.Rows

          rowIndex = rowIndex + 1

          colIndex = 0

          For Each Col In Table.Columns

            colIndex = colIndex + 1

            oTable.Cell(rowIndex, colIndex).Range.InsertAfter(Row(Col.ColumnName))

          Next

        Next



        oTable.Borders.InsideLineStyle = 1 

        oTable.Borders.OutsideLineStyle = 1



        wordApp.Visible = True



总结:

E_mail:lihonggen0@163.com

上一页  [1] [2] 

 

 
文章录入:编辑01    责任编辑:编辑01 
  • 上一篇文章:

  • 下一篇文章:

  •  
    相关文章
    原创地带
    24小时热门帖子