您好,欢迎来到图艺博知识网。
搜索
您的当前位置:首页关于VFP输出EXCEL的格式

关于VFP输出EXCEL的格式

来源:图艺博知识网
关于VFP输出EXCEL的格式Page 1 of 3

关于VFP输出EXCEL的格式 󰀠

--------------------------------------------------------------------------------󰀠 梦醒三分 于 00-8-31 17:27:55 发表:󰀠 关于VFP输出EXCEL的格式󰀠

以下是我在处理VFP输出EXCEL报表是用的一段程序片段,以供参考。󰀠 如有更好的建议,亦请拿出来讨论讨论。 tmpsheet = GETOBJECT('','excel.sheet')󰀠

if .not. ( type('tmpsheet')='O' ) && U 未能产生EXCEL对象󰀠 =messagebox( '创建报表失败!' + CHR(13) + CHR(13) + ;󰀠

'请检查你的系统是否正确安装 EXCEL 软件!' + CHR(13) + CHR(13) + ;󰀠 '请联络系统管理员' + CHR(13) + ;󰀠 '', 48, '')󰀠 return󰀠 endif󰀠

xlapp = tmpsheet.APPLICATION󰀠 xlapp.VISIBLE = .f.󰀠

=messagebox( '准备生成月帐单' + CHR(13) + CHR(13) + ;󰀠

'日期:' + dtoc(tt_this_day) + CHR(13) + CHR(13) + ;󰀠

'如有在使用 EXCEL ,请暂时不要使用打印预览功能!!!' + CHR(13) + CHR(13) + ;󰀠 '报表生成的过程中,请暂时不要使用计算机!!!', 48, '') * wait wind '正在生成'+ form_title +'报表,请稍侯......' nowait ***! 创建excel打印对象

*****------------------------------------------------------------------------------------󰀠 xlapp.workbooks.ADD()󰀠

xlapp.ActiveWindow.WindowState = 2 && 最大化 打开的工作本󰀠 xlsheet = xlapp.activesheet󰀠

lc_name = allt(file_name_check( &temp_dls2_a..kh_mc ))󰀠 xlsheet.name = lc_name󰀠 ***! 创建excel打印对象

*****------------------------------------------------------------------------------------󰀠 xlsheet.Columns(\"A:G\").Font.Size = 9 && 选择 列 󰀠

xlsheet.Columns(\"A:A\").ColumnWidth = 10 && 设置列 宽度󰀠 xlsheet.Columns(\"B:B\").ColumnWidth = 15 && 设置列 宽度󰀠 xlsheet.Columns(\"C:C\").ColumnWidth = 16 && 设置列 宽度󰀠 xlsheet.Columns(\"D:D\").ColumnWidth = 16 && 设置列 宽度󰀠 xlsheet.Columns(\"E:E\").ColumnWidth = 8 && 设置列 宽度󰀠 xlsheet.Columns(\"F:F\").ColumnWidth = 10 && 设置列 宽度󰀠 xlsheet.Columns(\"G:G\").ColumnWidth = 8 && 设置列 宽度 xlsheet.Columns(\"A:A\").NumberFormatLocal = \"@ \"󰀠 xlsheet.Columns(\"B:B\").NumberFormatLocal = \"@ \"󰀠 xlsheet.Columns(\"C:C\").NumberFormatLocal = \"@ \"󰀠 xlsheet.Columns(\"D:D\").NumberFormatLocal = \"@ \"󰀠 xlsheet.Columns(\"E:E\").NumberFormatLocal = \"0 \"󰀠

xlsheet.Columns(\"F:F\").NumberFormatLocal = \"0.00_ \"󰀠 xlsheet.Columns(\"G:G\").NumberFormatLocal = \"@ \"

xlsheet.Rows(\"5:5\").ShrinkToFit = .t. && 自动收缩为适当尺寸以适应有效列宽󰀠 xlsheet.Rows(\"5:5\").HorizontalAlignment = 3 && 水平 1左对齐,3居中,4右对齐󰀠 xlsheet.Rows(\"1:2\").HorizontalAlignment = 3 && 水平 1左对齐,3居中,4右对齐󰀠

* xlsheet.Columns(\"G:G\").ShrinkToFit = .t. && 自动收缩为适当尺寸以适应有效列宽󰀠 ***! 设置页面信息

*****------------------------------------------------------------------------------------󰀠 In_Po = 0.0393700787401575 && 将度量单位从英寸转换为磅 基础单位: 0.0393700787401575 英寸 -> 0.1磅󰀠

xlsheet.PageSetup.LeftMargin = xlapp.Application.InchesToPoints( In_Po * 10 )󰀠 xlsheet.PageSetup.RightMargin = xlapp.Application.InchesToPoints( In_Po * 10 )󰀠 xlsheet.PageSetup.TopMargin = xlapp.Application.InchesToPoints( In_Po * 10 )󰀠 xlsheet.PageSetup.BottomMargin = xlapp.Application.InchesToPoints( In_Po * 20 )󰀠 xlsheet.PageSetup.HeaderMargin = xlapp.Application.InchesToPoints( In_Po * 10 )󰀠 xlsheet.PageSetup.FooterMargin = xlapp.Application.InchesToPoints( In_Po * 10 )󰀠

xlsheet.PageSetup.Orientation = 1 && 设置打印方向: 1 纵 向 2横向󰀠

mk:@MSITStore:D:\\VFP知识\\在VFP中控制OFFICE的文章集合\\VFPOFFICE.chm...2010-06-15

关于VFP输出EXCEL的格式Page 2 of 3

xlsheet.PageSetup.PrintTitleRows = \"$1:$7\" && 设置 每页 的页头󰀠 xlsheet.PageSetup.RightFooter = \"第 &P 页,共 &N 页\"󰀠

xlsheet.PageSetup.CenterHorizontally = .t. && 页面水平居中󰀠 ***! 设置页面信息

*****------------------------------------------------------------------------------------ ***! 生成打印内容

*****------------------------------------------------------------------------------------󰀠 xlsheet.Cells( 2,1).VALUE = \"帐单时间:\" + t_this_yy + '年 '+t_this_mm + '月'󰀠 xlsheet.Cells( 3,1).VALUE = \"客户名称:\"+ allt(&temp_dls2_a..khmc) 󰀠 xlsheet.Cells( 4,1).VALUE = \"客户帐号:\"+ allt(&temp_dls2_a..zh) 󰀠 prn_line = 5󰀠

xlsheet.Cells( prn_line, 1).VALUE = \"主叫号码\"󰀠 xlsheet.Cells( prn_line, 2).VALUE = \"被叫号码\"󰀠 xlsheet.Cells( prn_line, 3).VALUE = \"开始时间\"󰀠 xlsheet.Cells( prn_line, 4).VALUE = \"结束时间\"󰀠 xlsheet.Cells( prn_line, 5).VALUE = \"时长\"󰀠

xlsheet.Cells( prn_line, 6).VALUE = \"话费(元)\"󰀠 xlsheet.Cells( prn_line, 7).VALUE = \"计费标识\"󰀠 lc_min_col = 1󰀠 lc_max_col = 7󰀠

for lo_Col = lc_min_col to lc_max_col󰀠

xlsheet.Cells( prn_line,lo_Col).Borders(4).Weight = 2 &&框线 宽度: 2细线 3粗线󰀠 endfor󰀠

prn_line = prn_line + 1󰀠 lc_sum_brhj = 0󰀠 lc_sum_bybrlj = 0󰀠 sele &dbf_j_yjd_a󰀠 count to max_sl 󰀠

sum &dbf_j_yjd_a..dj to sum_dj󰀠 go top󰀠 scan󰀠

wait wind '处理'+ lc_name + ' 第'+ str(recno()) + ' 总数:'+str(max_sl) nowait󰀠 xlsheet.Cells( prn_line, 1).VALUE = allt(&dbf_j_yjd_a..zjhm)󰀠 xlsheet.Cells( prn_line, 2).VALUE = allt(&dbf_j_yjd_a..bdhm)󰀠 xlsheet.Cells( prn_line, 3).VALUE = allt(&dbf_j_yjd_a..riqi)󰀠 xlsheet.Cells( prn_line, 4).VALUE = allt(&dbf_j_yjd_a..riqi2)󰀠 xlsheet.Cells( prn_line, 5).VALUE = &dbf_j_yjd_a..fz󰀠 xlsheet.Cells( prn_line, 6).VALUE = &dbf_j_yjd_a..dj󰀠

xlsheet.Cells( prn_line, 7).VALUE = allt(&dbf_j_yjd_a..jfbs)󰀠 prn_line = prn_line + 1󰀠 endscan󰀠

for lo_Col = lc_min_col to lc_max_col󰀠

xlsheet.Cells( prn_line,lo_Col).Borders(3).Weight = 2 &&框线 宽度: 2细线 3粗线󰀠 endfor󰀠

xlsheet.Range(\"A1:G1\").MergeCells = .t. && 合并单元格󰀠 xlsheet.Range(\"A2:G2\").MergeCells = .t. && 合并单元格󰀠 xlsheet.Range(\"A3:G3\").MergeCells = .t. && 合并单元格󰀠 xlsheet.Range(\"A4:G4\").MergeCells = .t. && 合并单元格󰀠 xlsheet.Range(\"A5:G5\").MergeCells = .t. && 合并单元格󰀠 xlsheet.Rows(\"1:1\").Font.Size = 11 && 选择 行󰀠 xlsheet.Rows(\"1:1\").Font.Bold = .t.󰀠

xlsheet.Rows(\"1:2\").RowHeight = 18.00 && 设置行 宽度󰀠

xlsheet.Rows(\"4:4\").HorizontalAlignment = 4 && 水平 1左对齐,3居中,4右对齐󰀠 xlsheet.Rows(\"5:5\").HorizontalAlignment = 1 && 水平 1左对齐,3居中,4右对齐 *! 完成删除 提示按扭

*****------------------------------------------------------------------------------------ file_name = all_path + lc_name + '.xls'󰀠 if file( file_name) = .t.󰀠 ??chr(7)󰀠

result=messagebox( file_name +'已存在,要替换该文件吗? ', 4+48+256, '' )󰀠 if result=6󰀠

mk:@MSITStore:D:\\VFP知识\\在VFP中控制OFFICE的文章集合\\VFPOFFICE.chm...2010-06-15

关于VFP输出EXCEL的格式

ERASE &file_name󰀠

xlapp.activeWorkbook.SaveAs( file_name )󰀠 endif󰀠 else󰀠

xlapp.activeWorkbook.SaveAs( file_name )󰀠 endif󰀠

xlapp.activeWorkbook.close(.f.)󰀠 endif󰀠 endscan󰀠

xlapp = tmpsheet.APPLICATION󰀠 xlapp.activeWorkbook.close(.f.)󰀠 xlapp.quit󰀠

=messagebox( '已完成报表输出!', 48, '')󰀠 return

Page 3 of 3

mk:@MSITStore:D:\\VFP知识\\在VFP中控制OFFICE的文章集合\\VFPOFFICE.chm...2010-06-15

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuoyibo.net 版权所有 湘ICP备2023021910号-2

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务