操作Word的例子
来源:互联网 发布:最好的比价软件 编辑:程序博客网 时间:2024/05/17 01:59
Dim ThisApplication As New Word.Application()
Dim ThisDocument As Word.Document
ThisDocument = ThisApplication.Documents.Open("c:/new.doc")
ThisDocument.Range.Delete()
ThisDocument.Sections.PageSetup.Orientation = WdOrientation.wdOrientLandscape
Dim tabStops() As Single = {4, 6}
'==========================================
'Create header
ThisApplication.ScreenUpdating = False
Dim rng As Word.Range
rng = ThisDocument.Range(0, 0)
rng.InsertBefore("SQL Server data table name exported.")
rng.Font.Name = "Verdana"
rng.Font.Size = 16
rng.InsertParagraphAfter()
rng.InsertParagraphAfter()
rng.SetRange(start:=rng.End, End:=rng.End)
Dim fmt As Word.ParagraphFormat = rng.ParagraphFormat
fmt.TabStops.ClearAll()
fmt.TabStops.Add( _
ThisApplication.InchesToPoints(tabStops(0)), _
Word.WdTabAlignment.wdAlignTabLeft, _
Word.WdTabLeader.wdTabLeaderSpaces)
fmt.TabStops.Add( _
ThisApplication.InchesToPoints(tabStops(1)), _
Word.WdTabAlignment.wdAlignTabLeft, _
Word.WdTabLeader.wdTabLeaderSpaces)
rng.Text = _
"Author ID" & ControlChars.Tab & _
"Last Name" & ControlChars.Tab & _
"First Name" & ControlChars.Tab '& _
'"Phone" & ControlChars.Tab & _
'"Address" & ControlChars.Tab & _
'"City" & " " & _
'"State" & " " & _
'"Zip" & " " & _
'"Contract" & " "
rng.Font.Name = "Verdana"
rng.Font.Name = 10
rng.Font.Bold = CLng(True)
rng.Font.Underline = WdUnderline.wdUnderlineSingle
rng.InsertParagraphAfter()
rng.SetRange(Start:=rng.End, End:=rng.End)
fmt = rng.ParagraphFormat
' Set up the tabs for the columns.
fmt.TabStops.ClearAll()
fmt.TabStops.Add( _
ThisApplication.InchesToPoints(tabStops(0)), _
Word.WdTabAlignment.wdAlignTabLeft, _
Word.WdTabLeader.wdTabLeaderDots)
fmt.TabStops.Add( _
ThisApplication.InchesToPoints(tabStops(1)), _
Word.WdTabAlignment.wdAlignTabLeft, _
Word.WdTabLeader.wdTabLeaderDots)
' Insert a bookmark to use for the inserted data.
'ThisDocument.Bookmarks.Add( _
' Name:="data", Range:=DirectCast(rng, System.Object))
rng.InsertParagraphAfter()
Dim dr As SqlDataReader
Dim cmd As SqlCommand
Dim sw As New System.IO.StringWriter()
cmd = New SqlCommand("select au_id,au_lName,au_fname,phone," & _
"address,city,state,zip,contract from authors", cnn)
cmd.Connection.Open()
dr = cmd.ExecuteReader(CommandBehavior.CloseConnection)
' Loop through the data, creating tab-delimited output:
While dr.Read()
sw.WriteLine("{0}{1}{2}{3}{4}", _
dr(0), ControlChars.Tab, _
dr(1), ControlChars.Tab, _
dr(2), ControlChars.Tab)
End While
' Work with the previously created bookmark:
'rng = ThisDocument.Bookmarks("data").Range
rng.Text = sw.ToString()
rng.Font.Name = "Verdana"
rng.Font.Size = 10
If Not dr Is Nothing Then
dr.Close()
End If
cmd.Connection.Close()
ThisApplication.ScreenUpdating = True
ThisApplication.DisplayAlerts = False
ThisDocument.Save()
ThisApplication.Visible = True
'ThisApplication.Documents.Close()
'ThisApplication.Quit(Word.WdSaveOptions.wdSaveChanges)
Dim fileWord As String
Dim currentdate As Date
fileWord = "output" & currentdate.ToLongDateString & ".doc"
Page.Response.ContentType = "Application/unknown"
Response.AppendHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileWord, System.Text.Encoding.UTF8))
Response.WriteFile("c://new.doc")
Response.End()
- 操作Word的例子
- 用JAVA操作WORD的一个例子
- VC 操作Word 2003的简单例子
- 很好的C#操作word例子
- ASP操作Word文件的例子!!!
- vc操作word的简单例子
- 自己写的一个vc操作word的例子
- jacob操作Word的例子,office及pdf
- 3-jacob操作Word例子2
- word里的操作
- 对于word的操作
- .NET操作Word的实现:using Word
- 操作Excel的例子
- 文件操作的例子
- DataGrid导出excel和word的例子
- DataGrid导出excel和word的例子
- Itext导出Word文档的例子
- Itext导出Word文档的例子
- 高性能的Web应用程序开发
- 彻底明白javaIO (转)
- ASP.NET下MVC设计模式的实现
- 关于用户界面设计(转摘)
- Struts - 基于MVC设计模式的JSP (简单介绍)
- 操作Word的例子
- SUN技术社区论坛
- 批量安装部署web service到axis server
- 昨日发布 windows、LINUX 上浏览器新安全缺陷
- 你是我永世等待的新娘!
- RIP学习
- 震惊全球的完美钢琴CD---Daydreaming - Piano Solo Collection
- 计算机术语
- Sharpreader-最好用的开源RSS Reader?