Range("A1:C3").Select
    With Selection
        .HorizontalAlignment = xlGeneral
        .VerticalAlignment = xlBottom
        .WrapText = False
        .Orientation = 0
        .AddIndent = False
        .ShrinkToFit = False
        .MergeCells = True
    End With
    ActiveSheet.Shapes.AddLine(0#, 1.5, 81#, 42.75).Select
    Selection.ShapeRange.Flip msoFlipHorizontal
    Selection.ShapeRange.Item("Line 1").Left = 0#
    Selection.ShapeRange.Item("Line 1").Width = 81.75
    Selection.ShapeRange.Item("Line 1").Top = 0.75
    Selection.ShapeRange.Item("Line 1").Height = 42#
    ActiveSheet.Shapes.AddLine(83.25, 3#, 164.25, 42#).Select
    Range("D3").Select
    ActiveSheet.Shapes("Line 2").Select
    Range("A1:C3").Select
    ActiveSheet.Shapes("Line 2").Select
    Selection.ShapeRange.Item("Line 2").Left = 78.75
    Selection.ShapeRange.Item("Line 2").Width = 85.5
    Selection.ShapeRange.Item("Line 2").Top = 0#
    Selection.ShapeRange.Item("Line 2").Height = 42#
    Range("A1:C3").Select
    ActiveSheet.Shapes.AddLine(55.5, 13.5, 109.5, 42#).Select
    Selection.ShapeRange.Flip msoFlipVertical
    Range("A1:C3").Select
    ActiveSheet.Shapes("Line 3").Select
    Selection.ShapeRange.Item("Line 3").Left = 55.5
    Selection.ShapeRange.Item("Line 3").Width = 52.5
    Range("A1:C3").Select
    ActiveSheet.Shapes.AddLine(109.5, 27#, 135#, 41.25).Select
    Selection.ShapeRange.Flip msoFlipVertical
    Range("C6").Select
    ActiveSheet.Shapes.AddLine(52.5, 15#, 108.75, 40.5).Select
    Selection.ShapeRange.Flip msoFlipHorizontal
    Selection.ShapeRange.Flip msoFlipVertical
    Range("A1:C3").Select
    ActiveSheet.Shapes.AddLine(22.5, 29.25, 52.5, 43.5).Select
    Selection.ShapeRange.Flip msoFlipHorizontal
    Selection.ShapeRange.Flip msoFlipVertical
    Range("A1:C3").Select
End Sub
在excel中先合并3行3列的单元格,用绘图工具画了一列斜线和对应的反斜线。
在delphi中如何表达?紧急求助,谢谢!

解决方案 »

  1.   

    //在excel中先合并3行3列的单元格,用绘图工具画了一列斜线和对应的反斜线。
    unit Unit1;interfaceuses
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
      Dialogs,ComObj, StdCtrls, Buttons;type
      TForm1 = class(TForm)
        BitBtn1: TBitBtn;
        procedure BitBtn1Click(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
      end;var
      Form1: TForm1;implementation{$R *.dfm}procedure TForm1.BitBtn1Click(Sender: TObject);
    var
     eclApp:Variant;
    begin
     try
       eclApp:= CreateOleObject('Excel.Application');
     except
       messagebox(handle,'您的机器里可能未安装Microsoft Excel或异常','无法生成',MB_OK  or MB_ICONWARNING);
       Exit;
     end;
     try
      eclApp.visible:=true;
      eclApp.WorkBooks.Open( 'c:\aaa.xls');
      eclApp.ActiveSheet.Range['a1:c3'].Merge;
      eclApp.ActiveSheet.Range[ 'a1:c3' ].Borders[5].Weight := 3;
      eclApp.ActiveSheet.Range[ 'a1:c3' ].Borders[6].Weight := 3;
       finally
       eclApp:= Unassigned;
     end;没看你的宏,就看了你的说明,好像符合你的要求。end;end.
      

  2.   

    To benny87:我好像用不成你的方法,出的效果不是我期望的,不过仍然谢谢你!
      

  3.   

    求助!如果宏换成如下: Columns("A:A").ColumnWidth = 2.5
        Columns("B:B").ColumnWidth = 2.5
        Columns("C:C").ColumnWidth = 2.5
        Columns("D:D").ColumnWidth = 2.5
        Columns("E:E").ColumnWidth = 2.5
        Columns("F:F").ColumnWidth = 2.5
        Range("C1,B2,A3").Select
        Range("A3").Activate
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        With Selection.Borders(xlDiagonalUp)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
        Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        Selection.Borders(xlEdgeRight).LineStyle = xlNone
        Range("D1,E2,F3").Select
        Range("F3").Activate
        With Selection.Borders(xlDiagonalDown)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
        Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        Selection.Borders(xlEdgeRight).LineStyle = xlNone
        Range("C3,D2").Select
        Range("D2").Activate
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        With Selection.Borders(xlDiagonalUp)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
        Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        Selection.Borders(xlEdgeRight).LineStyle = xlNone
        Range("E3").Select
        Selection.Borders(xlDiagonalDown).LineStyle = xlNone
        With Selection.Borders(xlDiagonalUp)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
        Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        Selection.Borders(xlEdgeRight).LineStyle = xlNone
        Range("D3,C2").Select
        Range("C2").Activate
        With Selection.Borders(xlDiagonalDown)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
        Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        Selection.Borders(xlEdgeRight).LineStyle = xlNone
        Range("B3").Select
        With Selection.Borders(xlDiagonalDown)
            .LineStyle = xlContinuous
            .Weight = xlThin
            .ColorIndex = xlAutomatic
        End With
        Selection.Borders(xlDiagonalUp).LineStyle = xlNone
        Selection.Borders(xlEdgeLeft).LineStyle = xlNone
        Selection.Borders(xlEdgeTop).LineStyle = xlNone
        Selection.Borders(xlEdgeBottom).LineStyle = xlNone
        Selection.Borders(xlEdgeRight).LineStyle = xlNone
        Range("G11").Select
    End Sub
    以上是想通过excel单元格边框来画斜线,我想这样出来的直线会比直接用绘图工具画出的斜线效果好,只是不知道如何用delphi编写