C# 设置Excel单元格属性

数字(Range.NumberFormatlocal 属性)

常规:Range.NumberFormatlocal = "G/通用格式"

数值:Range.NumberFormatlocal = "0.000_ " --保留小数位数为3

Range.NumberFormatlocal = "0" --不要小数

Range.NumberFormatlocal = "#,##0.000 " --保留小数位数为3,并使用千位分隔符

货币:Range.NumberFormatlocal = "$#,##0.000"

百分比:Range.NumberFormatlocal = "0.000%"

分数:Range.NumberFormatlocal = "# ?/?"

科学计数:Range.NumberFormatlocal = "0.00E+00"

文本:Range.NumberFormatlocal = "@"

特殊:Range.NumberFormatlocal = "000000"---邮政编码

Range.NumberFormatlocal = "[DBNum1]G/通用格式"---中文小写数字

Range.NumberFormatlocal = "[DBNum2]G/通用格式"---中文大写数字

Range.NumberFormatlocal = "[DBNum2][$RMB]G/通用格式"---人民币大写

对齐

水平对齐:Range.HorizontalAlignment = etHAlignCenter ---居中

垂直对齐:Range.VerticalAlignment = etVAlignCenter---居中

是否自动换行:Range.WrapText = True

是否缩小字体填充:Range.ShrinkToFit = True

是否合并单元格:Range.MergeCells = False

文字竖排:Range.Orientation = etVertical

文字倾斜度数:Range.Orientation = 45 -----倾斜45度

字体(Font对象)

字体名称:Font.Name = "华文行楷"

字形:Font.FontStyle = "常规"

字号:Font.Size = "10"

下划线:Font.Strikethrough = True; Font.Underline = etUnderlineStyleDouble ---双下划线

上标:Font.Superscript = True

下标:Font.SubScript = True

删除线:Font.OutlineFont = True

边框(Borders对象)

Borders.Item(etEdgeTop):上边框

Borders.Item(etEdgeLeft):左边框

Borders.Item(etEdgeRight):右边框

Borders.Item(etEdgeBottom):下边框

Borders.Item(etDiagonalDown):左上--右下边框

Borders.Item(etDiagonalUp):左下--右上边框

Border.LineStyle = etContinuous 线条样式