asp中从数据库导出EXCEL时,EXCEL宏应用的边框设置
2009-09-15 16:44
615 查看
Set xlApp = CreateObject("Excel.Application")
xlApp.DisplayAlerts = false '不显示警告
'xlApp.Application = false '不显示界面
xlapp.Workbooks.add
set objExcelBook = xlapp.ActiveWorkBook
set objExcelSheets = objExcelBook.Worksheets
set xlSheet = objExcelBook.Sheets(1)
EXCEL中设置边框,录制的宏
Sub Macro1()
'
' Macro1 Macro
' 宏由 YlmF 录制,时间: 2009-9-15 test
'
' 快捷键: Ctrl+q
'
Range("A3:G32").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
运行会出现“类型不匹配: 'range'”或者“selection错误”之类的错误,所以在vb中用msgbox查看了下述的值
'xlDiagonalDown=5
'xlDiagonalUp=6
'xlEdgeLeft=7
'xlEdgeTop=8
'xlEdgeBottom=9
'xlEdgeRight=10
'xlInsideVertical=11
'xlInsideHorizontal=12
'xlNone=-4142
改为
xlsheet.Range("A3","G"&startrow-1&"").Borders(xlDiagonalDown).LineStyle = xlNone
运行出现“未知的运行时错误”的错误
改为
xlsheet.Range("A3","G"&startrow-1&"").Borders("5").LineStyle = "-4142"
运行出现“不能设置类 Border 的 LineStyle 属性”的错误
最后正确运行代码如下:
xlsheet.Range("A3","G"&startrow-1&"").Borders("5").LineStyle = xlNone
xlsheet.Range("A3","G"&startrow-1&"").Borders("6").LineStyle = xlNone
With xlsheet.Range("A3","G"&startrow-1&"").Borders("7")
.LineStyle = xlContinuous
.Weight = "2" 'xlThin
.ColorIndex = xlAutomatic
End With
With xlsheet.Range("A3","G"&startrow-1&"").Borders("8")
.LineStyle = xlContinuous
.Weight = "2" 'xlThin
.ColorIndex = xlAutomatic
End With
With xlsheet.Range("A3","G"&startrow-1&"").Borders("9")
.LineStyle = xlContinuous
.Weight = "2" 'xlThin
.ColorIndex = xlAutomatic
End With
With xlsheet.Range("A3","G"&startrow-1&"").Borders("10")
.LineStyle = xlContinuous
.Weight = "2" 'xlThin
.ColorIndex = xlAutomatic
End With
With xlsheet.Range("A3","G"&startrow-1&"").Borders("11")
.LineStyle = xlContinuous
.Weight = "2" 'xlThin
.ColorIndex = xlAutomatic
End With
With xlsheet.Range("A3","G"&startrow-1&"").Borders("12")
.LineStyle = xlContinuous
.Weight = "2" 'xlThin
.ColorIndex = xlAutomatic
End With
代码正确了,但是关于录制的宏在asp中应用还是有很多疑问,比如上例中 .Weight = "2" ,如果是.Weight = xlThin就出现“不能设置类 Border 的 Weight属性”的错误,这个和
xlsheet.Range("A3","G"&startrow-1&"").Borders("5").LineStyle = "-4142" 不一致
贴出来,共勉共勉
xlApp.DisplayAlerts = false '不显示警告
'xlApp.Application = false '不显示界面
xlapp.Workbooks.add
set objExcelBook = xlapp.ActiveWorkBook
set objExcelSheets = objExcelBook.Worksheets
set xlSheet = objExcelBook.Sheets(1)
EXCEL中设置边框,录制的宏
Sub Macro1()
'
' Macro1 Macro
' 宏由 YlmF 录制,时间: 2009-9-15 test
'
' 快捷键: Ctrl+q
'
Range("A3:G32").Select
Selection.Borders(xlDiagonalDown).LineStyle = xlNone
Selection.Borders(xlDiagonalUp).LineStyle = xlNone
With Selection.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideVertical)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Selection.Borders(xlInsideHorizontal)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
End Sub
运行会出现“类型不匹配: 'range'”或者“selection错误”之类的错误,所以在vb中用msgbox查看了下述的值
'xlDiagonalDown=5
'xlDiagonalUp=6
'xlEdgeLeft=7
'xlEdgeTop=8
'xlEdgeBottom=9
'xlEdgeRight=10
'xlInsideVertical=11
'xlInsideHorizontal=12
'xlNone=-4142
改为
xlsheet.Range("A3","G"&startrow-1&"").Borders(xlDiagonalDown).LineStyle = xlNone
运行出现“未知的运行时错误”的错误
改为
xlsheet.Range("A3","G"&startrow-1&"").Borders("5").LineStyle = "-4142"
运行出现“不能设置类 Border 的 LineStyle 属性”的错误
最后正确运行代码如下:
xlsheet.Range("A3","G"&startrow-1&"").Borders("5").LineStyle = xlNone
xlsheet.Range("A3","G"&startrow-1&"").Borders("6").LineStyle = xlNone
With xlsheet.Range("A3","G"&startrow-1&"").Borders("7")
.LineStyle = xlContinuous
.Weight = "2" 'xlThin
.ColorIndex = xlAutomatic
End With
With xlsheet.Range("A3","G"&startrow-1&"").Borders("8")
.LineStyle = xlContinuous
.Weight = "2" 'xlThin
.ColorIndex = xlAutomatic
End With
With xlsheet.Range("A3","G"&startrow-1&"").Borders("9")
.LineStyle = xlContinuous
.Weight = "2" 'xlThin
.ColorIndex = xlAutomatic
End With
With xlsheet.Range("A3","G"&startrow-1&"").Borders("10")
.LineStyle = xlContinuous
.Weight = "2" 'xlThin
.ColorIndex = xlAutomatic
End With
With xlsheet.Range("A3","G"&startrow-1&"").Borders("11")
.LineStyle = xlContinuous
.Weight = "2" 'xlThin
.ColorIndex = xlAutomatic
End With
With xlsheet.Range("A3","G"&startrow-1&"").Borders("12")
.LineStyle = xlContinuous
.Weight = "2" 'xlThin
.ColorIndex = xlAutomatic
End With
代码正确了,但是关于录制的宏在asp中应用还是有很多疑问,比如上例中 .Weight = "2" ,如果是.Weight = xlThin就出现“不能设置类 Border 的 Weight属性”的错误,这个和
xlsheet.Range("A3","G"&startrow-1&"").Borders("5").LineStyle = "-4142" 不一致
贴出来,共勉共勉
相关文章推荐
- asp.net从数据库导出数据到word、excel、txt文本文件
- 【导出EXCEL汇编】asp.net 将数据导出到excel中,并设置其格式
- Asp.Net中应用Aspose.Cells输出报表到Excel 及样式设置
- asp.net实现Gradview绑定数据库数据并导出Excel的方法
- 【导出EXCEL汇编】asp.net 将数据导出到excel中,并设置其格式
- asp.net从数据库导出数据到word、excel、txt文本文件
- asp.net中从数据库导出为excel问题
- asp.net网页中导出EXCEL,WORD的环境设置验证实例
- 【导出EXCEL汇编】asp.net 将数据导出到excel中,并设置其格式
- asp.net实现Gradview绑定数据库数据并导出Excel的方法
- C# asp.net 导出数据库二进制字段到excel
- asp.net怎样使用NPOI 导出到excel和从excel导入到数据库
- asp.net从数据库导出数据到word、excel、txt文本文件
- Asp导出数据库数据到Excel
- ASP.Net MVC中数据库数据导出Excel,供HTTP下载(转)
- asp.net从数据库导出数据到word、excel、txt文本文件
- asp将数据库的数据转换成excel导出
- asp.net 导出Excel并设置其字段为数字乱码的列
- ASP.Net MVC中数据库数据导出Excel,供HTTP下载
- asp.net 导出Excel并设置格式