您的位置:程序门 -> vb -> 数据库(包含打印,安装,报表)



msflexgrid生成excel的问题,在线等待~~~~~~~~~~~~~~!msflexgrid生成excel的问题,在线等待~~~~~~~~~~~~~~!


[收藏此页] [打印本页]选择字色:背景色:字体:[][][]


msflexgrid生成excel的问题,在线等待~~~~~~~~~~~~~~!msflexgrid生成excel的问题,在线等待~~~~~~~~~~~~~~!
发表于:2008-01-11 15:19:21 楼主
private   sub   command12_click()     '生成xls
        if   msflexgrid1.textmatrix(1,   0)   =   ""   then
                msgbox   "没有生成内容!"
        else
                dim   oexcel
                dim   obook
                dim   osheet
                dim   jj   as   integer
                dim   ii   as   integer
   
                set   oexcel   =   getobject(,   "excel.application")
                set   oexcel   =   createobject("excel.application")
   
                oexcel.visible   =   false
                oexcel.screenupdating   =   false
   
                set   obook   =   oexcel.workbooks.add
                set   osheet   =   obook.worksheets(1)
   
                for   ii   =   0   to   msflexgrid1.rows   -   1
                        msflexgrid1.row   =   ii
                        for   jj   =   0   to   msflexgrid1.cols   -   1
                                    msflexgrid1.col   =   jj
                                    osheet.range(cells(ii   +   3,   jj   +   1),   cells(ii   +   3,   jj   +   1)).select             'excel文件有倆行表頭,而且是以第1行第一列開始計算,所以行加3而列加1
                                    activecell.formular1c1   =   msflexgrid1.text
                                    activecell.columnwidth   =   8.4
                        next   jj
                next   ii        
        end   if        
end   sub

执行进话我   子程序或涵数未定义!
发表于:2008-01-11 16:03:301楼 得分:0
set       oexcel       =       getobject(,       "excel.application")  
                                set       oexcel       =       createobject("excel.application")  
是不是写反了?
发表于:2008-01-11 16:05:092楼 得分:0
set               oexcel               =               getobject(,               "excel.application")      
set               oexcel               =               createobject("excel.application")      
是不是写反了?换过来试试
set               oexcel               =               createobject("excel.application")
set               oexcel               =               getobject(,               "excel.application")
发表于:2008-01-11 16:38:473楼 得分:0
我的写法如下,你只要把listview控件换成你的msgrid控件的写法就行
但一定要在“引用”里引用microsoft   excel   *.*   object   library(*.*是指安装的excel   版本)
vbscript code
public sub exptoexcel(lvwlist as listview) dim i as long dim newapp as new excel.application dim newbook as new excel.workbook dim newsheet as new excel.worksheet set newapp = new excel.application set newbook = newapp.workbooks.add set newsheet = newbook.worksheets(1) if lvwlist.listitems.count = 0 then exit sub dim arrdata() as string redim arrdata(0 to lvwlist.listitems.count, 0 to lvwlist.columnheaders.count) as string dim j as integer for j = 1 to lvwlist.columnheaders.count arrdata(0, j - 1) = lvwlist.columnheaders(j).text next for i = 1 to lvwlist.listitems.count arrdata(i, 0) = lvwlist.listitems(i).text for j = 1 to lvwlist.columnheaders.count - 1 arrdata(i, j) = lvwlist.listitems(i).subitems(j) next next newsheet.range(newsheet.cells(1, 1), newsheet.cells(i, j)) = arrdata newsheet.columns.autofit newapp.visible = true set newsheet = nothing set newbook = nothing set newapp = nothing end sub
发表于:2008-01-11 16:47:244楼 得分:0
都一样,不行!请各位再帮帮忙!
发表于:2008-01-11 16:58:055楼 得分:0
错误是什么先??????
发表于:2008-01-15 12:45:326楼 得分:0
会不会是在引用中没有添加excel啊
发表于:2008-01-15 13:17:297楼 得分:0
在工程菜单选引用中添加micorsoft   excel   object     11.0       labrary   试试。
发表于:2008-01-15 13:30:308楼 得分:0
马克


快速检索

最新资讯
热门点击