现在我已经将数据写到了EXCEL里面,我想最后在这个数据区域内显示网格。这个代码怎么写?

解决方案 »

  1.   

    这是在宏里编写的,没用delphi写过,估计也差不多,你作为参考吧!
     Range("A1:E6").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
      

  2.   

    给一段代码看看,Weight 是粗细,Borders是那边。
        s_Range := ExcelApp.range[ExcelApp.Cells[18, 1], ExcelApp.Cells[18, 10]];
        //1-左  2-右  3-顶  4-底  5-斜(  \  )  6-斜(  /  )
        s_range.Borders[1].Weight := 2;
        ExcelApp.Cells[18, 10].Borders[2].Weight := 3;
        s_range.Borders[3].Weight := 3;
        s_range.Borders[4].Weight := 2;