选择显示字体大小

在.net环境下将报表导出excel和word

     在vb.net同样可以将报表导出到excel和word进行输出,制作出专业水平的报表。具体操作如下:(注:首先需添加引用,选择com-->选择microsoft word object library和microsoft excel object library组件)
  
  private function creatable() as datatable
   dim dt as new datatable()
   dt.columns.add("列1", gettype(string))
   dt.columns.add("列2", gettype(integer))
   dt.columns.add("列3", gettype(string))
   dt.columns.add("列4", gettype(string))
   dim row, row1 as datarow
   row = dt.newrow()
   row!列1 = "行1"
   row!列2 = 1
   row!列3 = "d"
   row!列4 = "a"
   dt.rows.add(row)
   row1 = dt.newrow()
   row1!列1 = "行2"
   row1!列2 = 12
   row1!列3 = "b"
   row1!列4 = "c"
   dt.rows.add(row1)
   return dt
  end function
  
  '2.将表中的内容导出到excel
  
  dim xlapp as new excel.application()
  dim xlbook as excel.workbook
  dim xlsheet as excel.worksheet
  dim rowindex as integer = 1
  dim colindex as integer = 0
  xlbook = xlapp.workbooks().add
  xlsheet = xlbook.worksheets("sheet1")
  
  dim table as new datatable()
  table = creatable()
  
  '将所得到的表的列名,赋值给单元格
  
  dim col as datacolumn
  dim row as datarow
  for each col in table.columns
   colindex = colindex + 1
   xlapp.cells(1, colindex) = col.columnname
  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
  
  
    


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons