欢迎来到天天文库
浏览记录
ID:40562093
大小:38.00 KB
页数:4页
时间:2019-08-04
《PB对excel的操作》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、Pb中对Excel文件的应用Oleobject ole_object//建立OLE对象ole_object=create oleobject//创建对象integer li_retli_ret=ole_object.connecttoobject("","Excel.Application")//建立连接if li_ret<>0 then//如果Excel还没有打开,则新建。li_ret=ole_object.ConnectToNewObject("Excel.Application")if
2、 li_ret<>0 thenmessagebox("OLE错误","OLE无法连接!错误号:"+string(li_ret))returnend ifole_object.Visible=trueend ifpointer oldpointer//设置鼠标oldpointer=setpointer(HourGlass!)ole_object.Workbooks.Add//新建工作薄ole_object.Application.DisplayAlerts=False//关闭警告消息对话框,防止提示ol
3、e_object.Application.Workbooks.Open(as_exccccccccccccccccccccccccccccccccccel_filename)//打开Excel文件//ole_object.Application.ActiveWorkbook.SaveAs(as_text_filename,-4158)//把打开的Excel文件另存为//Text文件,第二参数表示数据以制表符TAB分隔ole_object.Application.Quit()//退出Excelole_o
4、bject.activeworkbook.saved=true//放弃存盘ole_object.workbooks.close//关闭工作簿ole_object.Cells(1,1).Value=reptitleole_object.Range('A1').Selectole_object.Selection.Font.Size=24ole_object.selection.HorizontalAlignment=3//水平对齐方式:ole_object.Range('A1:'+f_columname
5、(ll_colnum)+'1').Selectole_object.Range('A1:'+f_columname(ll_colnum)+'1').Mergeole_object.Columns(i).ColumnWidth=ld_widthole_object.Columns(i).HorizontalAlignment=3ole_object.Columns(i).Borders.LineStyle=1ole_object.Columns(i).Font.Bold=Trueole_object.c
6、ells(i,j).NumberFormat="@"ole_object.cells(i,j).Font.Bold=falseole_object.cells(i,j).value=ls_valueOLE_MyExcel.ActiveWorkbook.Activesheet.UsedRange.Rows.CountSheets.Add基本操作:Ole_object.Workbooks.add//新建一个Excel文件Ole_object.Workbooks.Open("FileName")//打开一个
7、已存在Excel文件Ole_object.ActiveWorkBook.Sheets("SheetName").Select//选择文件中一个工作表Ole_object.Application.Run("MacroName")//运行宏Ole_object.Application.Visible=TRUE//Excel文件可见Ole_object.Application.ScreenUpdating=true//设置可见属性②格式设置Ole_object.ActiveSheet.Columns("A:
8、U").AutoFit//列宽自动调整Ole_object.ActiveSheet.Columns("A:Z").ColumnWidth=6.75//列宽Ole_object.ActiveSheet.Rows("1:100").RowHeight=12//行高Ole_object.Application.StandardFont="ArialNarrow";//设置字体Ole_object.Application.StandardFontSize="8"
此文档下载收益归作者所有