VFP操作Excel命令大全 联系客服

发布时间 : 星期四 文章VFP操作Excel命令大全更新完毕开始阅读4769d5d433d4b14e852468e2

oleapp.ActiveSheet.PictureS.Insert(\图片文件名\oleapp.Selection.ShapeRange.LockAspectRatio =.T. oleapp.Selection.ShapeRange.Height = 57

*!* 68.类型为字符型的字段输出到excel 中,前面的零被自动去掉,例如“009877”变为“9877”,怎么解决?

1.在字符串前面加半角单引号“ ' ”, 例如:

o.Cells(1,1).Value=\或用变量

cString=\其中0123可以取自表中一个字段 o.Cells(1,1).Value=cString &&o.Range(\2.

oExcel.CELLS(1,1).Select &&或eole.Range(\

oExcel.Selection.NumberFormatLocal = \把被选定的单元格设为文本格式 oExcel.Cells(1,1).Value=\给所选单元格覆值 *!* 69.在 Excel 中插入行和列 :

objExcel.Rows(1).Insert() &&在第一行前面插入一行 objExcel.Columns(2).Insert() &&在第二列前面插入一列 *!* 70.获取 Excel 记录数

loXls = Createobject(\

bookExcel = loXls.Application.Workbooks.Open(\nrows=bookExcel.Worksheets('pz') UsedRange =nrows.UsedRange

r=UsedRange.Rows.Count &&有数据的总行数 c=UsedRange.Columns.Count &&有数据的总列数 loXls.Workbooks.Close loXls.Quit

*!* 71.在EXCEL中如何在打开文件的同时自动执行一个宏命令。 只要将宏的命名为 AUTO_OPEN 即可。

如果要在文件关闭时运行,则命名为auto_close 。 *!* 72.在VFP中可以执行EXCEL的选择性粘贴吗? .Range(\会出错 .Range(\也会出错 .Range(\只好这样了 *!* 73.如何才能只粘贴值呢? xlPasteValues=-4163

oExcel.Range(\oExcel.Selection.Copy

oExcel.Range(\

*注意:在Excel 中,\是一个常量,它的值是一个数值型的:-4163 oExcel.Range(\

oExcel.Range(\粘贴行、列宽 oExcel.Range(\粘贴格式 *!* 74.如何从excel读取数据

*******建立一个excel对象******* Local hb1 As excel.Application

csheetname=Trim(Thisform.text2.Value)&&读取用户要读取excel的sheet名 ***读取数据源所在的EXCEL文件名**** If Empty(Trim(Thisformset.filepath))

Messagebox(\请先选择要导入的excel文件!\提示\ Return Endif

If Empty(Trim(csheetname))

Messagebox(\请先选择要导入的工作表sheet名称!\提示\ Return Endif Try

hb1=Createobject(\Catch

Messagebox(\请检查你是否已安装microsoft excel应用程序!\提示\Endtry

***打开EXCEL对象,开始读取数据******** HB1.workbooks.Open(Trim(Thisformset.filepath)) hb1.Sheets(csheetname).Select

Sele Store&&这是要读取的数据存放的表 Zap

isend=.F. &&用于判断是否记录已到底 i=1

Do While isend=.F. Append Blank crq=Dtoc(drq)

cdh=hb1.Cells(i,1).Value If Isnull(cdh) cdh=\ Endif

**用于判断数据类型,数据类型一定要判断是否为NULL,** ** 然后如果不是指定的类型,还要进行转换************* If Type(\

cdh=Alltrim(Str(cdh)) Endif

cdwmc=Trim(hb1.Cells(i,2).Value) If Isnull(cdwmc) cdwmc=\ Endif

cgg=hb1.Cells(i,3).Value If Isnull(cgg) cgg=\ Else

If Type(\

cgg=Alltrim(Str(cgg)) Endif Endif

cjldw=hb1.Cells(i,4).Value If Isnull(cjldw) cjldw=\ Endif

cjldw=Iif(Type(\ nsl=hb1.Cells(i,5).Value If Isnull(nsl) nsl=0 Endif

cch=Trim(hb1.Cells(i,6).Value) If Isnull(cch) cch='' Endif

cxh=hb1.Cells(i,8).Value If Isnull(cxh) cxh=\ Else

If Type(\ cxh=Trim(Str(cxh)) Else

cxh=Trim(cxh) Endif Endif

ccpmc=hb1.Cells(i,9).Value If Isnull(ccpmc) ccpmc='' Endif

If Type(\

ccpmc=Alltrim(Str(ccpmc)) Else

ccpmc=Trim(ccpmc) Endif

Select Store

Replace rq With crq,dh With cdh,dwmc With cdwmc,gg With cgg,jldw With cjldw,sl With nsl,ch With cch,cpbh With cxh,cpmc With ccpmc

i=i+1

&&如果一行全为空,记作记录到底,如果中间存在多行的问题,我没有做考虑**** If Empty(cxh) And nsl=0 And Empty(cch) And Empty(cjldw) And Empty(cdh) And Empty(cgg)

isend=.T.

Endif Enddo

Dele &&最后一行为空行,删除

Wait \共转换得到\条记录!\hb1.Quit

*!* 75.本程序通过将原dbf表拷成excel格式,然后导入并设置报表格式 Para tablename

Local hb1 As excel.Application

Wait \正在导出数据,请稍侯……\bhaveerror=.F. &&定义一个变量判断是否发生错误 Try

hb1=Createobject(\Catch

Messagebox(\请检查你是否已安装microsoft excel应用程序!\提示\ bhaveerror=.T. Endtry

If bhaveerror=.T. Return Endif

If Right(curr_path,1)<>'\\' curr_path=curr_path+\Endif

ctablename=tablename+\filepath=curr_path+\*filepath=\If !File(filepath)

Messagebox(\数据源的excel文件未生成,报表生成被终止!\ Return Endif

HB1.workbooks.Open(filepath) HB1.SHEETS(\

hb1.sheets(1).Rows(1).entirerow.Insert hb1.sheets(1).Rows(1).entirerow.Insert Sele (ctablename) nfieldcount=Fcount() nreccount=Reccount()

hbdygs=\HB1.Range(hbdygs).Select

****合并两行作为报表标题*************

HB1.Selection.HorizontalAlignment = 3 &&水平方向 2左对齐,3居中,4右对齐 HB1.Selection.VerticalAlignment = 2 &&垂直方向 1靠上,2居中,3靠下 HB1.Selection.WrapText = .F. && ?? HB1.Selection.Orientation = 0 && ?? HB1.Selection.AddIndent = .F. && ??