excel宏改成delphi语言,紧急求助,在线等 ( 积分: 0 )

  • 主题发起人 主题发起人 delphi_excel
  • 开始时间 开始时间
D

delphi_excel

Unregistered / Unconfirmed
GUEST, unregistred user!
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中如何表达?紧急求助,谢谢!
 
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中如何表达?紧急求助,谢谢!
 
为什么每次我提问都没有人回答?难道是问题太简单了?
可是我真的是不会,而且很着急
 
天亡我!没人帮我
 
天不亡你,我帮你..
不过要明天了
 
你可以用Delphi直接调用你Excel里面的宏就行了呀
 
你加入一个ExcelApplication、ExcelWorkbook、ExcelWorksheet设置各组件的关联
try
excelApplication1:=TexcelApplication.Create(self);
excelApplication1.Connect;
except
messagedlg('系统中没有安装Excel',mtError,[mbOk],0);
abort;
end;
excelApplication1.Visible[0]:=true;
ExcelApplication1.Workbooks.Add(emptyparam, 0);
excelworkbook1.ConnectTo(excelApplication1.Workbooks[1]);
ExcelWorksheet1.ConnectTo(excelworkbook1.Sheets[1] as _Worksheet);
定义一个变量 R: ExcelRange;

r:=ExcelWorksheet1.Range[ExcelWorksheet1.Cells.Item[1, 1], ExcelWorksheet1.Cells.Item[3, 3]];
r.HorizontalAlignment: = xlGeneral;
...
基本上每个对象都有相似的函数或过程操纵,我在编程时就是先按要求制作一个表格,用宏录制,然后在vba中看代码,移植到程序中,一试准灵
 
不知如何与:sword_liu,联系啊?!能给我发一分:"基本上每个对象都有相似的函数或过程操纵,我在编程时就是先按要求制作一个表格,用宏录制,然后在vba中看代码,移植到程序中,一试准灵:"这种东西吗?!俺想学学具体的操作如何作不知可否?!WWEI656@163.COMQQ:328844156
 
搞定,测试通过
procedure TForm1.Button1Click(Sender: TObject);
var exapp,exsheet,exbook,sh:variant;
begin
exapp:=createoleobject('excel.application');
exbook:=exapp.workbooks.add;
exsheet:=exapp.activesheet;
exapp.visible:=true;
exsheet.range['a1'].horizontalalignment:=$FFFFEFF4;
exsheet.range['a1'].VerticalAlignment:=$FFFFEFF4;
exsheet.range['a1'].ShrinkToFit:=false;
exsheet.range['a1','c3'].merge;
sh:=exsheet.shapes.addline(0,1.5,81, 42.75);
sh.left:=0;
sh.width:=81.75;
sh.top:=0.75;
sh.height:=42;
sh.flip(1);//水平翻转
sh:=exsheet.shapes.addline(83.25, 3, 164.25, 42);
sh.left:=78.75;
sh.width:=85.5;
sh.top:=0;
sh.height:=42;
sh:=exsheet.shapes.addline(55.5, 13.5, 109.5, 42);
sh.flip(0);//垂直翻转
sh:=exsheet.shapes.addline(109.5, 27, 135, 41.25);
sh.flip(0);
sh:=exsheet.shapes.addline(52.5, 15, 108.75, 40.5);
sh.flip(1);
sh.flip(0);
exsheet.shapes.addline(22.5, 29.25, 52.5, 43.5);
sh.flip(1);
sh.flip(0);
exsheet.range['a1'].select;
exsheet:=unassigned;
exbook:=unassigned;
exapp:=unassigned;
 
谢谢各位,我先试试
 
to 7030:太感谢了!
我不一定画3行3列,行列是一个变量,那些顶点坐标是怎么确定的?
 
顶点坐标你可根据excel录制宏的方法获得
 
行数和列数不是我来确定的,而是用户确定。也就是说,行数和列数必须是可变的,因此顶点坐标也是一个变量,那么顶点坐标又如何确定?
 
我想通过通过单元格边框来画斜线,这样是否比通过绘图工具直接画更清楚。
不过顶点坐标还是不好确定。还有
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
也不知在delphi中如何编写
 
高手都去过周末了,没人来帮我
 
谢谢各位!我做出来了
 
后退
顶部