如果文件处于打开状态,再点击按钮
此主题相关图片如下:2011-8-21 10-27-29.png
If FileSys.DirectoryExists("D:\My Documents\Reports") Then '目录存在
Else
FileSys.CreateDirectory("D:\My Documents\Reports") '创建目录
End If
Dim FName As String = "D:\My Documents\Reports\数据分类.xls"
If FileSys.FileExists(FName) Then
Try
Dim f As New System.IO.FileStream(FName,IO.FileMode.Open,IO.FileAccess.Read,IO.FileShare.None)
f.Dispose()
Catch ex As Exception
MessageBox.Show("目标文件处于打开状态")
End Try
End If
If DataTables.Contains("后台统计") Then '如果存在后台统计
Tables("后台统计").SaveExcel("D:\My Documents\退耕报表\数据分类.xls","后台统计")
Dim flg As New SaveExcelFlags
flg.MergedRanges = True
' CurrentTable.SaveExcel("D:\My Documents\退耕报表\数据分类.xls","后台统计",flg)
Tables("后台统计").SaveExcel("D:\My Documents\Reports\数据分类.xls","后台统计",flg)
Dim Result As DialogResult
Dim App As New MSExcel.Application
Dim Wb As MSExcel.WorkBook = App.WorkBooks.Open("D:\My Documents\Reports\数据分类.xls")
Dim Ws As MSExcel.WorkSheet = Wb.WorkSheets(1)
Dim Rg As MSExcel.Range = Ws.UsedRange
Rg.Borders.Linestyle = MSExcel.XlLineStyle.xlContinuous '边框线型
Rg.Borders.Weight = MSExcel.XlBorderWeight.xlThin '边框粗细
Rg.Borders.ColorIndex = 1 '边框颜色
Dim M As MSExcel.Range = Ws.Cells
M.EntireColumn.AutoFit '自动调整列宽
M.EntireRow.AutoFit '自动调整行高
App.Visible = True
Wb.Save
Else
MessageBox.show("先按后台统计按钮")
End If
[此贴子已经被作者于2011-8-21 11:57:14编辑过]