如何用vb.net给excel加边框

dm0351 2006-08-22 09:23:35
我按照excel中加边框的宏代码写了点。但是属性值总显示未定义
Selection.Borders(xlDiagonalDown).LineStyle = xlNone ‘xlNone总显示未定义
最好给出具体点的代码
...全文
1604 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
izarel 2006-08-22
  • 打赏
  • 举报
回复
Public Sub ChooseFrameLine(ByVal startColumn As Integer, ByVal startRow As Integer, ByVal endColumn As Integer, ByVal endRow As Integer, ByVal line As String)
Me._openExcel.Range(Me._openExcel.Cells(startRow, startColumn), Me._openExcel.Cells(endRow, endColumn)).Select()
If line.IndexOf("Left") >= 0 Then
Me._openExcel.Selection.borders(7).linestyle = 1
End If
If line.IndexOf("Right") >= 0 Then
Me._openExcel.Selection.borders(10).linestyle = 1
End If
If line.IndexOf("Top") >= 0 Then
Me._openExcel.Selection.borders(8).linestyle = 1
End If
If line.IndexOf("Bottom") >= 0 Then
Me._openExcel.Selection.borders(9).linestyle = 1
End If
If line.IndexOf("Vertical") >= 0 Then
Me._openExcel.Selection.borders(11).linestyle = 1
End If
If line.IndexOf("Horizontal") >= 0 Then
Me._openExcel.Selection.borders(12).linestyle = 1
End If
Me._openExcel.Columns.AutoFit()
End Sub
  • 打赏
  • 举报
回复
搂主在代码里加上以下代码即可
private Const xlEdgeBottom = 9
private Const xlEdgeLeft = 7
private Const xlEdgeRight = 10
private Const xlEdgeTop = 8
private Const xlNone = -4142
Const xlDiagonalDown = 5
const xlDiagonalUp = 6


fansino 2006-08-22
  • 打赏
  • 举报
回复
'adjust data
Dim oXL As Excel.Application
Dim oWB As Excel.Workbook
Dim oSheet As Excel.Worksheet
Dim oRng As Excel.Range
'
Dim i As Integer
Dim j As Integer
Dim Rows As Integer
Dim Cols As Integer


' Start Excel and get Application object.
oXL = CreateObject("Excel.Application")
oXL.Visible = True

' Get a new workbook.
oWB = oXL.Workbooks.Add
oSheet = oWB.ActiveSheet
' Add table headers going cell by cell.
oSheet.Cells(1, 7).Value = "淮安市祥弘机械有限公司员工工资发放一览表"
' oSheet.Cells(2, 1).Value = ""
'oSheet.Cells(2, 2).Value = ""
'oSheet.Cells(2, 3).Value = ""
'oSheet.Cells(2, 4).Value = ""
'oSheet.Cells(2, 5).Value = "导出日期:" & Now
oSheet.Cells(3, 1).Value = "姓名"
oSheet.Cells(3, 2).Value = "月份"
oSheet.Cells(3, 3).Value = "基本工资"
oSheet.Cells(3, 4).Value = "补助"
oSheet.Cells(3, 5).Value = "工人平均工资"
oSheet.Cells(3, 6).Value = "系统"
oSheet.Cells(3, 7).Value = "应发工资合计"
oSheet.Cells(3, 8).Value = "借款"
oSheet.Cells(3, 9).Value = "饭款"
oSheet.Cells(3, 10).Value = "养老保险"
oSheet.Cells(3, 11).Value = "预发工资"
oSheet.Cells(3, 12).Value = "罚款"
oSheet.Cells(3, 13).Value = "事假"
oSheet.Cells(3, 14).Value = "其它"
oSheet.Cells(3, 15).Value = "应扣金额合计"
oSheet.Cells(3, 16).Value = "实发金额"
oSheet.Cells(3, 17).Value = "是否发放"

' Format A1:D1 as bold, vertical alignment = center.
With oSheet.Range("A1", "q1")
'设置字体
.Font.Bold = True
'设置垂直方式
.VerticalAlignment = Excel.XlVAlign.xlVAlignCenter
'设置水平方式
.HorizontalAlignment = Excel.XlVAlign.xlVAlignCenter
'设置行宽
.ColumnWidth = Excel.XlColumnDataType.xlSkipColumn.GetTypeCode.Decimal
'设置行高
.RowHeight = Excel.XlColumnDataType.xlSkipColumn.GetTypeCode.Decimal
'Excel.XlColumnDataType.xlTextFormat.xlSkipColumn
End With

oXL.Visible = True
oXL.UserControl = True
' Make sure that you release object references.
oRng = Nothing
oSheet = Nothing
oWB = Nothing
oXL.Quit()
oXL = Nothing
Exit Sub
fansino 2006-08-22
  • 打赏
  • 举报
回复
不知你不是想在导出数据到excel中并加上边框?
arice1983 2006-08-22
  • 打赏
  • 举报
回复
Selection.Borders(xlDiagonalDown).LineStyle = Excel.XlLineStyle.xlLineStyleNone
dm0351 2006-08-22
  • 打赏
  • 举报
回复
为什么我调用这个函数没有反映啊
Public Sub biankuang()
Dim exl As Excel.Application = New Excel.Application
Dim range As Excel.Range
mWorkSheet = mWorkBook.ActiveSheet
'mWorkSheet.Range("B11").Select()
'With mWorkSheet.Range("B11")
' .Borders.LineStyle = Excel.XlLineStyle.xlContinuous
Me.mWorkSheet.Range(Me.mExlApp.Cells(9, 1), Me.mExlApp.Cells(9, 10)).Select()

With mWorkSheet.Range(Me.mExlApp.Cells(9, 1), Me.mExlApp.Cells(9, 10))
.Borders(XlBordersIndex.xlDiagonalDown).LineStyle = Excel.XlLineStyle.xlLineStyleNone
.Borders(XlBordersIndex.xlDiagonalUp).LineStyle = Excel.XlLineStyle.xlLineStyleNone
.Borders(XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlLineStyle.xlContinuous
.Borders(XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlLineStyleNone
.Borders(XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlLineStyle.xlLineStyleNone
.Borders(XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlLineStyle.xlContinuous

End With
Me.mWorkSheet.Columns.AutoFit()

'End With





End Sub

16,722

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧