可以用SaveFileDialog1對(duì)話框加上對(duì)文件數(shù)據(jù)操作的類(lèi)來(lái)實(shí)現(xiàn),,用richtextbox自己的屬性方法也能行!我以前做過(guò)一個(gè)記事本程序就是那樣的!
成都創(chuàng)新互聯(lián)公司是一家專(zhuān)注于網(wǎng)站設(shè)計(jì)、網(wǎng)站制作與策劃設(shè)計(jì),汝南網(wǎng)站建設(shè)哪家好?成都創(chuàng)新互聯(lián)公司做網(wǎng)站,專(zhuān)注于網(wǎng)站建設(shè)10多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專(zhuān)業(yè)建站公司;建站業(yè)務(wù)涵蓋:汝南等地區(qū)。汝南做網(wǎng)站價(jià)格咨詢(xún):18980820575
添加一個(gè)SaveFileDialog,在保存excle選擇時(shí)候添加
SaveFileDialog1.show()
用法跟OpenFileDialog相同
保存文件的步驟為:
關(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
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