如题
------解决方案--------------------------------------------------------
可以。参考下面内容:
- SQL code
*!* 1.创建Excel对象oExcel=Createobject("Excel.application")*!* 2.添加新工作簿oExcel.Workbooks.Add *!* 3.设置第3个工作表为激活工作表oExcel.Worksheets("sheet3").Activate *!* 4.打开指定工作簿oExcel.Workbooks.Open("c:/temp/ll.xls") *!* 5.显示Excel窗口oExcel.Visible=.T. *!* 6.更改Excel标题栏oExcel.Caption="VFP应用程序调用Microsoft Excel" *!* 7.给单元格赋值oExcel.cells(1,4).Value=XM(XM为数据库字段名) *!* 8.设置指定列的宽度(单位:字符个数)oExcel.ActiveSheet.Columns(1).ColumnWidth=5 *!* 9.设置指定行的高度(单位:磅)oExcel.ActiveSheet.Rows(1).RowHeight=1(设定行高为1磅,1磅=0.035厘米)oExcel.ActiveSheet.Rows("50:100").RowHeight=1 &&设置第50行至100行的高度 *!* 10.在第18行之前插入分页符oExcel.Worksheets("Sheet1").Rows(18).PageBreak=1 *!* 11.在第4列之前删除分页符oExcel.ActiveSheet.Columns(4).PageBreak=0 *!* 12.指定边框线宽度(Borders参数如下)ole.ActiveSheet.Range("b3:d3").BorderS(2).Weight=3 *!* 13.设置四个边框线条的类型oExcel.ActiveSheet.Range("b3:d3").BorderS(2).LineStyle=1(其中Borders参数:1-左、2-右、3-顶、4-底、5-斜、6-斜/;LineStyle值:1与7-细实、2-细虚、4-点虚、9-双细实线) *!* 14.设置页眉oExcel.ActiveSheet.PageSetup.CenterHeader="报表1" *!* 15.设置页眉(字体大小)oExcel.ActiveSheet.PageSetup.CenterHeader="&50报表1" &&'&'后面的50可以自定义,表示字体的大小 *!* 16.设置页脚oExcel.ActiveSheet.PageSetup.CenterFooter="第&P页" *!* 17.设置页脚(字体大小)oExcel.ActiveSheet.PageSetup.CenterFooter="&28第&P页" &&'&'后面的28可以自定义,表示字体的大小 *!* 18.设置页眉到顶端边距为2厘米oExcel.ActiveSheet.PageSetup.HeaderMargin=2/0.035 *!* 19.设置页脚到底边距为3厘米oExcel.ActiveSheet.PageSetup.FooterMargin=3/0.035 *!* 20.设置顶边距为2厘米oExcel.ActiveSheet.PageSetup.TopMargin=2/0.035 *!* 21.设置底边距为4厘米oExcel.ActiveSheet.PageSetup.BottomMargin=4/0.035 *!* 22.设置左边距为2厘米oExcel.ActiveSheet.PageSetup.LeftMargin=2/0.035 *!* 23.设置右边距为2厘米oExcel.ActiveSheet.PageSetup.RightMargin=2/0.035 *!* 24.设置页面水平居中oExcel.ActiveSheet.PageSetup.CenterHorizontally=.T. *!* 25.设置页面垂直居中oExcel.ActiveSheet.PageSetup.CenterVertically=.T. *!* 26.设置页面纸张大小(1-窄行8?5?11 39-宽行14?11 9:A4)oExcel.ActiveSheet.PageSetup.Papersize=1 *!* 27.打印单元格网线oExcel.ActiveSheet.PageSetup.PrintGridlines=.T. *!* 28.拷贝整个工作表oExcel.ActiveSheet.UsedRange.Copy *!* 29.拷贝指定区域oExcel.ActiveSheet.Range("A1:E2").Copy *!* 30.粘贴oExcel.WorkSheet("Sheet2").Range("A1").PasteSpecial *!* 31.在第2行之前插入一行oExcel.ActiveSheet.Rows(2).Insert *!* 32.在第2列之前插入一列oExcel.ActiveSheet.Columns(2).Insert *!* 33.设置字体oExcel.ActiveSheet.Cells(2,1).Font.Name="黑体" *!* 34.设置字体大小oExcel.ActiveSheet.Cells(1,1).Font.Size=25 *!* 35.设置字体为斜体oExcel.ActiveSheet.Cells(1,1).Font.Italic=.T. *!* 36.设置整列字体为粗体oExcel.ActiveSheet.Columns(1).Font.Bold=.T. *!* 37.清除单元格公式oExcel.ActiveSheet.Cells(1,4).ClearContents *!* 38.打印预览工作表oExcel.ActiveSheet.PrintPreview *!* 39.打印输出工作表oExcel.ActiveSheet.PrintOut *!* 40. oExcel.CommandBars(1).Controls(1).accChild(18).Execute &&打印(菜单序号18为Excel2003的‘打印’项)&&不同版本Excel的菜单序号可以通过以下程序取得*(需要在VFP7.0以上运行)oXls=Getobject("","excel.sheet")XlApp=oXLS.ApplicationXlSheet=XlApp.ActiveSheetbars=xlapp.CommandBars.CountStr1=''For i=1 To bars Str1=Str1+Chr(13)+Alltrim(Str(i))+'、'+xlapp.CommandBars(i).accName+'(NAME:'+xlapp.CommandBars(i).Name+' INDEX:'+Alltrim(Str(xlapp.CommandBars(i).Index))+')' bars2=xlapp.commandbars(i).accChildCount For j=1 To bars2 Try obj=xlapp.commandbars(i).Controls(j) Str1=Str1+Chr(13)+' '+Alltrim(Str(j))+'、'+xlapp.commandbars(i).Controls(j).accname+'(ID:'+Alltrim(Str(xlapp.CommandBars(i).Controls(j).Id))+')' For k=1 To obj.accChildCount Try If Not Empty(obj.Controls(k).accname ) Str1=Str1+Chr(13)+' '+Alltrim(Str(k))+'、'+obj.Controls(k).accName+' (ID:'+ Alltrim(Str(obj.Controls(k).Id))+')' Endif Catch Exit Endtry Endfor Catch Exit Endtry Endfor Wait Windows Alltrim(Str(i))+' / '+Alltrim(Str(bars))+' '+Str(i/bars*100,10,2)+'%' NowaitEndforSave To Xls.txt All Like Str1Modify Command Xls.txtReturn *!* 41.工作表另存为oExcel.ActiveWorkbook.SaveAs("c:/temp/22.xls")*检测当前目录是否有同名的EXCEL表,如果有先删除,再另存If !File(Sys(5) + Curdir() + "result.xls") oExcel.ActiveWorkbook.SaveAs(Sys(5) + Curdir() + "result.xls")Else lcFileName = loExcel.GetSaveAsFilename("result", "Excel (*.xls), *.xls") If !Empty(lcFileName) If File(lcFileName) Delete File (lcFileName) Endif oExcel.ActiveWorkbook.SaveAs(lcFileName) EndifEndif*!* 42.放弃存盘 && 避免出现保存对话框oExcel.ActiveWorkbook.saved=.T. *!* 43.存盘oExcel.ActiveWorkbook.Save *!* 44.关闭工作簿oExcel.Workbooks.Closeobjexcel.activeworkbook.Close(.F.) *!* 45.退出ExceloExcel.QuitRelease oExcel &&只有释放对象变量, EXCEL进程才会完全关闭 *!* 46.合并单元格oExcel.ActiveSheet.Range("A4:B5").MergeCells=.T. *!* 47.下列设置大家自己理解With crfole.ActiveSheet.PageSetup .LeftHeader = Chr(13)+"左页眉" .CenterHeader = "中页眉" .RightHeader = "右页眉" .LeftFooter = "左页脚" .CenterFooter = "中页脚" .RightFooter = "右页脚" .Orientation=1 &&1竖排,2横排EndwithWith crfole.Range("A4:C4") .MergeCells = .T. .WrapText =.F. .Orientation = 0 .AddIndent =.F. .ShrinkToFit = .F.Endwith *!* 48.文本对齐oExcel.Range("A4:c4").HorizontalAlignment =1 &&水平(1-默认、2-靠左、3-居中、4-靠右、5-填充、6=两端对齐、7=跨列居中、8=分散对齐)oExcel.Range("A4:c4").VerticalAlignment =2 &&垂直(1=靠上、2=居中、3=靠下、4=两端对齐、5=分散对齐) *!* 49.拷贝整个工作表(含格式)oExcel.activesheet.cells.Copy &&拷贝oExcel.sheets(1).Select &&选择第一工作表oExcel.ActiveSheet.Paste &&粘贴oExcel.ActiveSheet.Cells(3,4).Value && ActiveSheet 为当前的Sheet工作薄名字,Cells(3,4).value 为第3行第4列的值*以上控制调用语句在中文VFP5.0企业版下运行通过,运行环境为Excel 97及中文Windows 98 *!* 50.显示某个单元格的批注内容oExcel=Createobject("Excel.application")oExcel.Workbooks.Open("d:/TEST/testa.xls")oExcel.Visible=.T.?oExcel.Range("B5").Comment.Text &&显示B5单元格的批注内容oExcel.Workbooks.CloseoExcel.QuitRelease oExcel