可以用Replace把他替换成空或别的字符:Vb的TAB表示方式为:vbTab 例:Replace(内容,vbTab,"")
在任丘等地区,都构建了全面的区域性战略布局,加强发展的系统性、市场前瞻性、产品创新能力,以专注、极致的服务理念,为客户提供成都网站设计、网站建设、外贸网站建设 网站设计制作按需定制开发,公司网站建设,企业网站建设,高端网站设计,营销型网站建设,外贸网站建设,任丘网站建设费用合理。
textBox1.Text = "a" vbTab "1" vbLf "b" vbTab "2"
其实是起了作用的,只不过vbTab跟4个字符有关系,所以显示的列,8的倍数个字符和不是8的倍数个字符之间就显示得有差异了。
tab就是如果不够4个字符就补齐4个字符的位置。 超过的话就是补齐4的整倍数个字符。
以下是我以前百度找的资料 希望对你有用 你读取DataGridView到DataGrid然后直接调用函数即可
Public Function ExportXLsD(ByVal datagrid As DataGrid) ', ByVal Title As String)
'Dim Mytable As New DataTable
'Mytable = CType(datagrid.DataSource, DataTable)
If mytable Is Nothing Then
MessageBox.Show("没有记录不能导出数据", "PurpleStar", MessageBoxButtons.OK, MessageBoxIcon.Information)
Exit Function
End If
If mytable.Rows.Count 0 Then
Dim MyFileName As String
Dim FileName As String
With SaveFileDialog1
.AddExtension = True '如果用户忘记添加扩展名,将自动家上
.DefaultExt = "xls" '默认扩展名
.Filter = "Excel文件(*.xls)|*.xls"
.Title = "文件保存到"
If .ShowDialog = DialogResult.OK Then
FileName = .FileName
End If
End With
MyFileName = Microsoft.VisualBasic.Right(FileName, 4)
If MyFileName = "" Then
Exit Function
End If
If MyFileName = ".xls" Or MyFileName = ".XLS" Then
Dim FS As FileStream = New FileStream(FileName, FileMode.Create)
Dim sw As StreamWriter = New StreamWriter(FS, System.Text.Encoding.Default)
sw.WriteLine(vbTab FileName vbTab Date.Now)
Dim i, j As Integer
Dim str As String = ""
For i = 0 To mytable.Columns.Count - 1
str = mytable.Columns(i).Caption
sw.Write(str vbTab)
Next
sw.Write(vbCrLf)
For j = 0 To mytable.Rows.Count - 1
For i = 0 To mytable.Columns.Count - 1
Dim strColName, strRow As String
strRow = IIf(mytable.Rows(j).Item(i) Is DBNull.Value, "", mytable.Rows(j).Item(i))
sw.Write(strRow vbTab)
Next
sw.Write(vbLf)
Next
sw.Close()
FS.Close()
MessageBox.Show("数据导出成功!", "PurpleStar", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
Exit Function
End If
Else
MessageBox.Show("没有记录不能导出数据", "PurpleStar", MessageBoxButtons.OK, MessageBoxIcon.Information)
End If
End Function
Private Sub OK_Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK_Button.Click
Dim saveExcel As SaveFileDialog
saveExcel = New SaveFileDialog
saveExcel.Filter = "Excel文件(.xls)|*.xls"
Dim filename As String
If saveExcel.ShowDialog = Windows.Forms.DialogResult.Cancel Then Exit Sub
filename = saveExcel.FileName
Dim excel As Excel.Application
excel = New Excel.Application
excel.DisplayAlerts = False
excel.Workbooks.Add(True)
excel.Visible = False
Dim i As Integer
For i = 0 To DataGridView1.Columns.Count - 1
excel.Cells(1, i + 1) = DataGridView1.Columns(i).HeaderText
Next
'设置标题
Dim j As Integer
For i = 0 To DataGridView1.Rows.Count - 1 '填充数据
For j = 0 To DataGridView1.Columns.Count - 1
excel.Cells(i + 2, j + 1) = DataGridView1(j, i).Value
Next
Next
excel.Workbooks(1).SaveCopyAs(filename) '保存
Me.Close()
End Sub
Sub Main()
Dim thr As Thread
For Pi As Integer=0 To 4 //启用5线程
MulParams =Pi vbTab sFile vbTab dFile vbTab 1 vbTab DelN vbTab cr vbTab cg vbTab cb vbTab IndexI
GlobalParamas(pi)=MulParams .Split(vbTab)
thr=New Thread(AddressOf MyMulThreadCaller)
thr.Start() //启动多线程进程
Application.DoEvents
Next
End Sub
这里的“某一周”是有歧义的:
一种可能是某日期所在的周
第二种是某年的第几周。这还有歧义。因为某年的第一周,可能开始于上一年,同时这一周也是上一年的最后一周,会重复计算。我们这里假设“不管是否重复计算”
第三种是每周从星期几开始。我们这里假设“从星期一开始”。
下面分别是输出“某日期所在的周始终日期”、“某年某周始终日期”、“某年各周始终日期”的代码!
如果每周从星期日开始,将vbMonday替换为vbSunday即可。
'某日期所在的周始终日期
Private Sub Command3_Click()
Dim dt As Date
Dim wd As Integer
dt = InputBox("请输入一个日期(Date格式):", "输入日期", Date)
wd = Weekday(dt, vbMonday) '某日是星期几,周一为第一天
firstDay = DateAdd("d", -wd + 1, dt) '本周的开始日期
endDay = DateAdd("d", 7 - wd, dt) '本周的开始日期
Text1.Text = "当前日期所在的周起止日期:"
Text1.Text = Text1.Text vbNewLine
Text1.Text = Text1.Text vbNewLine "每周从星期一开始"
Text1.Text = Text1.Text vbNewLine firstDay vbTab endDay
wd = Weekday(dt, vbSunday) '某日是星期几,周日为第一天
firstDay = DateAdd("d", -wd + 1, dt) '本周的开始日期
endDay = DateAdd("d", 7 - wd, dt) '本周的开始日期
Text1.Text = Text1.Text vbNewLine
Text1.Text = Text1.Text vbNewLine "每周从星期日开始"
Text1.Text = Text1.Text vbNewLine firstDay vbTab endDay
End Sub
'某年某周始终日期
Private Sub Command4_Click()
Dim y As Integer
Dim w As Integer
Dim dt As Date
Dim wd As Integer
y = InputBox("请输入年份:", "输入年份", Year(Date))
dt = DateSerial(y, 1, 1)
w = InputBox("请输入周数:", "第几周", "")
dt = DateAdd("ww", (w - 1), dt)
wd = Weekday(dt, vbMonday) '某日是星期几,周一为第一天
firstDay = DateAdd("d", -wd + 1, dt) '本周的开始日期
endDay = DateAdd("d", 7 - wd, dt) '本周的开始日期
Text1.Text = "当前日期所在的周起止日期:"
Text1.Text = Text1.Text vbNewLine
Text1.Text = Text1.Text vbNewLine "每周从星期一开始"
Text1.Text = Text1.Text vbNewLine firstDay vbTab endDay
End Sub
'某年各周始终日期
Private Sub Command2_Click()
Dim y As Integer
Dim w As Integer
Dim dt As Date
Dim dte As Date
Dim wd As Integer
y = InputBox("请输入年份:", "输入年份", Year(Date))
dt = DateSerial(y, 1, 1)
dte = DateAdd("yyyy", 1, dt) - 1 '某年最后一天
wd = Weekday(dt, vbMonday) '某日是星期几,周一为第一天
firstDay = DateAdd("d", -wd + 1, dt) '本周的开始日期
endDay = firstDay + 6 '本周的开始日期
Text1.Text = "当前日期所在的周起止日期:"
Text1.Text = Text1.Text vbNewLine "(每周从星期一开始)"
Text1.Text = Text1.Text vbNewLine
Text1.Text = Text1.Text vbNewLine firstDay vbTab endDay
Do While endDay dte
w = w + 1
firstDay = firstDay + 7
endDay = firstDay + 6
Text1.Text = Text1.Text vbNewLine firstDay vbTab endDay
Loop
End Sub