关于VB中程序设置EXCEL单元格格式问题2009-08-10 10:21xlsheet.Columns("f:g").NumberFormatLocal = "0.00" '6到7列保留两位小数
.NumberFormatLocal = "@" '为文本
.NumberFormatLocal = "G/通用格式" '为通用
Range("C2:C" & y).NumberFormatLocal = 0.00_ '小数点2位
Range("C2:C" & y).ClearContents为清空内容
-------------------------------------------------------------------------------------------
sh.Range("A1:C1").MergeCells = True '合并单元格
sh.Rows("1:1").EntireRow.AutoFit '第一行自动行高
sh.Rows("2:2").EntireRow.AutoFit '第二行自动行高
sh.Rows(2).Font.Bold = True
sh.Range("A3").Select
ex.Activewindow.FreezePanes = True '冻结窗口
---------------------------------------------------------------------------------------------
在EXCEL里选择录制宏.然后操作一遍.看看代码就知道了.
单元格居中
Range.HorizontalAlignment = xlCenter
Range.VerticalAlignment = xlCenter
加边框
With Range.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Range.Borders(xlEdgeTop)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Range.Borders(xlEdgeBottom)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
With Range.Borders(xlEdgeRight)
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With