有关DATAGRIDVIEW向excel导数据问题
请问用vb.net写excel区域所有连框,还有合并居中加粗怎么写?谢谢了!
[解决办法]
Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet
Dim myRange As Excel.Range
ShowMsg("创建Excel程序...")
xlApp = New Excel.Application
xlBook = xlApp.Workbooks.Add
xlSheet = xlBook.Worksheets.Item(1)
'....
ShowMsg("格式化单元格边框线条.")
myRange = xlSheet.Range(xlSheet.Cells(1, 1), xlSheet.Cells(5,5))
With myRange
.Borders(Excel.XlBordersIndex.xlInsideHorizontal).LineStyle = Excel.XlLineStyle.xlDot
.Borders(Excel.XlBordersIndex.xlInsideVertical).LineStyle = Excel.XlLineStyle.xlDot
.Borders(Excel.XlBordersIndex.xlEdgeTop).LineStyle = Excel.XlLineStyle.xlContinuous
.Borders(Excel.XlBordersIndex.xlEdgeRight).LineStyle = Excel.XlLineStyle.xlContinuous
.Borders(Excel.XlBordersIndex.xlEdgeLeft).LineStyle = Excel.XlLineStyle.xlContinuous
.Borders(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = Excel.XlLineStyle.xlContinuous
End With
With myRange
.Merge() '合并单元格
.WrapText = True '文本对齐
.Font.Bold = True '字体粗体
.Font.Size = FontSize '字体大小
.HorizontalAlignment = AlignNum '.HorizontalAlignment = 1默认,2 左对齐,3 居中对齐,4右对齐
'.VerticalAlignment = '1顶部 默认 2居中 3底部对齐 4顶部对齐
If FUnderline = True Then '下划线
.Borders(Excel.XlBordersIndex.xlEdgeBottom).LineStyle = 7 '7,9 细实线
End If
.Value = "文本内容"
End With