delphi 怎么读取excel文件 的打印纸张 大小,与方向。 不是设置excel 打印. 。我知道用vba可以读,怎么用delphi读(300)

  • 主题发起人 向红林
  • 开始时间

向红林

Unregistered / Unconfirmed
GUEST, unregistred user!
目前有一难题。delphi 怎么读取excel文件 的打印纸张 大小,与方向。我可以进行设置excel 打印纸张大小与方向,就是不能读。我知道用vba可以读,怎么用delphi读我看了对日开发中Delphi控制Excel的经验 :http://hi.baidu.com/yunfanleo/blog/item/65cb0ba8395a45beca130c24.html
 
Z

zbdzjx

Unregistered / Unconfirmed
GUEST, unregistred user!
既然可以設定,就可以讀啊,你試試下面的代碼:procedure TForm1.Button1Click(Sender: TObject);var msexcel: variant;begin msexcel:=CreateOleObject('excel.application'); msexcel.visible:=true; msexcel.workbooks.Open('c:/1.xls'); ShowMessage(msexcel.activesheet.pagesetup.Orientation); ShowMessage(msexcel.activesheet.pagesetup.PaperSize);end;
 
Z

zbdzjx

Unregistered / Unconfirmed
GUEST, unregistred user!
上面顯示的結果是數字,你試著在EXCEL文件中設定一下大小及方向,就可以知道具體的大小和方向對應的數字是多少了。
 

向红林

Unregistered / Unconfirmed
GUEST, unregistred user!
我知道这个可以,是属于vba,在对日开发中Delphi控制Excel的经验 :http://hi.baidu.com/yunfanleo/blog/item/65cb0ba8395a45beca130c24.html 有介绍,问题是如果 系统已经有运行的多个excel文件,有间断操作(比如去其他的excel操作了)这个方法找错误文件。我 用delphi的 office控件组,已经可以控制ecxe的文件与sheet的名称,可以进行精确读数据,唯独pagesetup.Orientation ,pagesetup.PaperSize总是0;我用的 Ea1: TExcelApplication; Es1: TExcelWorksheet;----------ea1.Connect;ea1.Workbooks.Open(ed1.Text ,null,null,null,null, null,null,null,null,null,null,null,null,null,null,0);es1.ConnectTo(ea1.Workbooks['my.xls'].Worksheets['设计']as ExcelWorksheet);其他的 es1 都可以读取,with form1.Es1 dobeginmm.txt.text :=Cells.Item[row,col]; // 内容mm.t := Cells.Item[row,col].top; //顶mm.l := cells.Item[row,col].left; //左mm.k:=0;r2:= Cells.Item[row,col].MergeArea.Rows.Count;mm.row2 :=R2;if (o1>=1) and (col>=1) then mm.l:= cells.Item[row,col].left-cells.Item[row,2].left; //左if (o1>=1) and (row>1)and (row>=row2) then mm.t:= cells.Item[row,col].top-cells.Item[row2,1].top; //顶 ms:= cells.Item[row,col].MergeCells; //检查是否为 合并单位if ms thenbeginr2:= Cells.Item[row,col].MergeArea.Rows.Count;c2:= Cells.Item[row,col].MergeArea.Columns.Count;mm.h := Cells.Item[row+r2,col].top-Cells.Item[row,col].top; //高度mm.w := Cells.Item[row,col+c2].left-Cells.Item[row,col].left;//宽度end elsebeginmm.h:= Cells.Item[row,col].height; //高度mm.w:= Cells.Item[row,col].width; //宽度end;if o1=3 thenbeginmm.txt .FontBold := Cells.Item[row,col].font.Bold; //字加粗mm.txt .FontItalic:= Cells.Item[row,col].Font.Italic; //字倾斜mm.txt .thi:=Cells.Item[row,col].HorizontalAlignment; //水平排列mm.txt .tvi:=Cells.Item[row,col].VerticalAlignment; //垂直排列mm.txt.fontname := Cells.Item[row,col].font.name; //字 名称mm.txt.fontSize := Cells.Item[row,col].font.Size; //字 大小mm.txt.fontcolor:= Cells.Item[row,col].font.ColorIndex;//字 颜色if mm.txt.fontcolor<=0 then mm.txt.fontcolor :=1;mm.txt.bcolor:= Cells.Item[row,col].Interior.ColorIndex;// 底颜色 //打印设置中 边距 上下左右p.TopMargin :=PageSetup.topMargin/2.8348;p.BottomMargin :=PageSetup.BottomMargin/2.8348;p.LeftMargin :=PageSetup.LeftMargin/2.8348; p.RightMargin :=PageSetup.RightMargin/2.8348;// 单元格边框//左 1If cells.Item[row,col].Borders[xlEdgeLeft].LineStyle = xlContinuous Then mm.k := 1 ;// 右2If cells.Item[row,col].Borders[xlEdgeRight].LineStyle = xlContinuous Then mm.k := mm.k + 2 ;// 上4If cells.Item[row,col].Borders[xlEdgeTop].LineStyle = xlContinuous Then mm.k := mm.k + 4 ;// '下8If cells.Item[row,col].Borders[xlEdgeBottom].LineStyle = xlContinuous Then mm.k := mm.k + 8 ;end with;唯独读 pagesetup.Orientation ,pagesetup.PaperSize总是0;设置又可以?????
 

向红林

Unregistered / Unconfirmed
GUEST, unregistred user!
我是在用excel 做 fastrep的设计排版模板。目前数据连接部分还没想好。除了打印纸大小设置与方向设置外其他大部分的已经完成了。这样 我可以用excel 直接设计fastrep 单元进行 的排版。反过了,这样fastrep 报表输出为excel或者 word文件就会很工整。类似 Report Machine 排版效果。网络都不好,微软 输入法不熟悉,老写错
 

向红林

Unregistered / Unconfirmed
GUEST, unregistred user!
var msexcel: variant; Ea1: TExcelApplication; Es1: TExcelWorksheet;=========================ea1.Connect;ea1.Workbooks.Open(ed1.Text ,null,null,null,null, null,null,null,null,null,null,null,null,null,null,0);es1.ConnectTo(ea1.Workbooks['my.xls'].Worksheets['设计']as ExcelWorksheet);******a2:=es1.PageSetup;a1:=a2.Orientation;a3:=a2.PaperSize;是最接近 我的效果了,目前不知道怎么释放 a1,a2,a3变量。不释放可以吗?
 

向红林

Unregistered / Unconfirmed
GUEST, unregistred user!
接受答案了.
 

Similar threads

S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
S
回复
0
查看
2K
SUNSTONE的Delphi笔记
S
D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
2K
DelphiTeacher的专栏
D
I
回复
0
查看
685
import
I
顶部