Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
創(chuàng)新互聯(lián)建站是一家專(zhuān)業(yè)提供奇臺(tái)企業(yè)網(wǎng)站建設(shè),專(zhuān)注與成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、H5開(kāi)發(fā)、小程序制作等業(yè)務(wù)。10年已為奇臺(tái)眾多企業(yè)、政府機(jī)構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專(zhuān)業(yè)網(wǎng)站設(shè)計(jì)公司優(yōu)惠進(jìn)行中。
'定義Word對(duì)象
Dim wordApp As New Word.ApplicationClass
'要轉(zhuǎn)換的文件名
Dim fileName As Object = "E:\Test.doc"
'默認(rèn)值
Dim miss As Object = System.Reflection.Missing.Value
'打開(kāi)要轉(zhuǎn)換的 DOC 文件
Dim doc As Word.Document = DirectCast(wordApp.Documents.Open(fileName, miss, miss, miss, miss, miss, _
miss, miss, miss, miss, miss, miss, _
miss, miss, miss, miss), Word.Document)
'轉(zhuǎn)換后的文件名
fileName = "E:\testDoc.HTML"
'保存的文件格式
Dim saveFormat As Object = Word.WdSaveFormat.wdFormatHTML
'按文本文件保存
doc.SaveAs(fileName, saveFormat, miss, miss, miss, miss, _
miss, miss, miss, miss, miss, miss, _
miss, miss, miss, miss)
'關(guān)閉是否保存文件,這里為不保存
Dim changes As Object = False
'關(guān)閉文件
doc.Close(changes, miss, miss)
'退出 Word 應(yīng)用程序
wordApp.Quit(changes, miss, miss)
End Sub
你就不能這樣保存么? ↓
Static SaveNumber as Integer
SaveNumber += 1
Dim SavePath as String = "C:\ytakqi" SaveNumber ".png"
bit.Save(SavePath)
可以用SaveFileDialog1對(duì)話框加上對(duì)文件數(shù)據(jù)操作的類(lèi)來(lái)實(shí)現(xiàn),,用richtextbox自己的屬性方法也能行!我以前做過(guò)一個(gè)記事本程序就是那樣的!
Public Class Cls導(dǎo)入數(shù)據(jù)
Dim xlApp As New Excel.Application()
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim A = "A"
Public Function 導(dǎo)出到Excel(ByVal Dt表 As DataTable) As Boolean
Dim rowIndex, colIndex As Integer
rowIndex = 1
colIndex = 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 = "黑體"
'設(shè)標(biāo)題為黑體字
.Range(.Cells(1, 1), .Cells(1, colIndex)).Font.Bold = True
'標(biāo)題字體加粗
.Range(.Cells(1, 1), .Cells(rowIndex, colIndex)).Borders.LineStyle = 1
'設(shè)表格邊框樣式
End With
With xlSheet.PageSetup
.LeftHeader = "" Chr(10) """楷體_GB2312,常規(guī)""10公司名稱(chēng):" ' Gsmc
.CenterHeader = """楷體_GB2312,常規(guī)""公司人員情況表""宋體,常規(guī)""" Chr(10) """楷體_GB2312,常規(guī)""10日 期:"
.RightHeader = "" Chr(10) """楷體_GB2312,常規(guī)""10單位:"
.LeftFooter = """楷體_GB2312,常規(guī)""10制表人:"
.CenterFooter = """楷體_GB2312,常規(guī)""10制表日期:"
.RightFooter = """楷體_GB2312,常規(guī)""10第P頁(yè) 共N頁(yè)"
End With
xlApp.SaveWorkspace()
MsgBox("保存完畢", MsgBoxStyle.Exclamation, "提示")
KillAllExcels()
'xlApp.Visible = True
End Function
Sub KillAllExcels()
Dim proc As System.Diagnostics.Process
For Each proc In System.Diagnostics.Process.GetProcessesByName("EXCEL")
proc.Kill()
Next
End Sub
end class
保存文件的步驟為:
關(guān)閉流,特別是寫(xiě)入流
關(guān)閉并保存文件
示例代碼如下:
Imports?System.Windows.Forms
Imports?System.IO
Imports?System.Text
Sub?SaveFileDemo()
'打開(kāi)文件。如果文件不存在則創(chuàng)建新的文件
Dim?myFile?As?New?IO.FileStream("d:\data.txt",?_
FileMode.OpenOrCreate,?_
FileAccess.Write)
'在文件末尾添加一行?
Dim?tw?As?New?StreamWriter(myFile)
myFile.Seek(0,?SeekOrigin.End)
tw.WriteLine("白刃格斗英雄連英模部隊(duì)方隊(duì)亮相閱兵")
'關(guān)閉流
tw.Close()
'關(guān)閉文件并保存文件
myFile.Close()
End?Sub
添加一個(gè)SaveFileDialog,在保存excle選擇時(shí)候添加
SaveFileDialog1.show()
用法跟OpenFileDialog相同