vb将查询结果导出到Excel问题 用vb将查询结果导出到EXCEL时,总有“内存溢出”的错误,紧接着又出现“应用程序定义或对象定义错误”的提示,然后就没反应了,请问这是什么原因? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 你试一试这里面的几种方法看看.http://expert.csdn.net/Expert/topic/2835/2835777.xml?temp=.8592646 Dim nRow As IntegerDim nCol As IntegerOn Error GoTo FillErrorReDim asArray(100000, adoRS.Fields.Count)nRow = 0 For nCol = 0 To adoRS.Fields.Count - 1 asArray(nRow, nCol) = adoRS.Fields(nCol).Name Next nCol nRow = 1Do While Not adoRS.EOF For nCol = 0 To adoRS.Fields.Count - 1 asArray(nRow, nCol) = adoRS.Fields(nCol).Value Next nCol adoRS.MoveNext nRow = nRow + 1LoopnRow = nRow + 1如果我用以上代码来导出的话,ReDim asArray(100000, adoRS.Fields.Count)这一句用ReDim asArray(adoRS.RecordCount + 2, adoRS.Fields.Count)代替是不是更好一些? 在Project-Reference中加入Microsoft Excel 10.0 Object Library(Office 2000)Dim uExcel As Excel.ApplicationDim uExcelBook As Excel.WorkbookSet uExcel = New Excel.Application uExcel.Visible = True uExcel.SheetsInNewWorkbook = 1 Set uExcelBook = uExcel.Workbooks.Add '打开Excel '边框设置 With uExcel.ActiveSheet.Range("A1:K" & (intRow + 1) & "").Borders .LineStyle = 1 .Weight = xlThin .ColorIndex = 1 End With '字体设置(第一行以粗体显示) 高度设为 20 'With uExcel.ActiveSheet.Range("A1:K1").Font '.Size = 14 '.Bold = True '.Italic = True '.ColorIndex = 3 'End With uExcel.ActiveSheet.Rows.HorizontalAlignment = xlVAlignCenter '水平居中 uExcel.ActiveSheet.Rows.VerticalAlignment = xlVAlignCenter '垂直居中 '设置第一行标题 With uExcel.ActiveSheet .Cells(1, 1).Value = "检查编号" .Cells(1, 2).Value = "测试编号" .Cells(1, 3).Value = "测试类型" End With'填充数据行 intI = 2 Do While Not adoRec.EOF With uExcel.ActiveSheet .Cells(intI, 1).Value = adoRec("StuCode") .Cells(intI, 2).Value = adoRec("TestCode") .Cells(intI, 3).Value = adoRec("TestType") End With intI = intI + 1 adoRec.MoveNext Loop adoRec.Close 'uExcel.ActiveSheet.PageSetup.Orientation = xlPortrait 'xlLandscape 'uExcel.ActiveSheet.PageSetup.PaperSize = xlPaperA4 '适应于A4纸 'uExcel.ActiveSheet.PrintOut'打印输出 'uExcel.DisplayAlerts = False '不保存后退出 'uExcel.Quit 'uExcel.DisplayAlerts = True 'uExcel.Quit Set uExcel = Nothing Set uExcelBook = Nothing VB读取WORD表单元内问题 WebBrowser如何显示整个网页 vb6自制控件的属性无法保存 对表的操作 哪位提供一个Crystal Reports 11专业版的序列号 怎样绑定text控件的格式? excel问题,急!请帮忙! sql高手请进 复选框的问题,急!!! vb ACCESS 中 请问下面SQL语句错在哪? 100分!请大家给出一个自定义打印机高度的例子,以控制打印机的走纸。 adodc 没有注册
http://expert.csdn.net/Expert/topic/2835/2835777.xml?temp=.8592646
Dim nCol As Integer
On Error GoTo FillError
ReDim asArray(100000, adoRS.Fields.Count)
nRow = 0
For nCol = 0 To adoRS.Fields.Count - 1
asArray(nRow, nCol) = adoRS.Fields(nCol).Name
Next nCol
nRow = 1
Do While Not adoRS.EOF
For nCol = 0 To adoRS.Fields.Count - 1
asArray(nRow, nCol) = adoRS.Fields(nCol).Value
Next nCol
adoRS.MoveNext
nRow = nRow + 1
Loop
nRow = nRow + 1
如果我用以上代码来导出的话,ReDim asArray(100000, adoRS.Fields.Count)这一句用ReDim asArray(adoRS.RecordCount + 2, adoRS.Fields.Count)代替是不是更好一些?
Dim uExcelBook As Excel.WorkbookSet uExcel = New Excel.Application
uExcel.Visible = True
uExcel.SheetsInNewWorkbook = 1
Set uExcelBook = uExcel.Workbooks.Add '打开Excel
'边框设置
With uExcel.ActiveSheet.Range("A1:K" & (intRow + 1) & "").Borders
.LineStyle = 1
.Weight = xlThin
.ColorIndex = 1
End With
'字体设置(第一行以粗体显示) 高度设为 20
'With uExcel.ActiveSheet.Range("A1:K1").Font
'.Size = 14
'.Bold = True
'.Italic = True
'.ColorIndex = 3
'End With
uExcel.ActiveSheet.Rows.HorizontalAlignment = xlVAlignCenter '水平居中
uExcel.ActiveSheet.Rows.VerticalAlignment = xlVAlignCenter '垂直居中
'设置第一行标题
With uExcel.ActiveSheet
.Cells(1, 1).Value = "检查编号"
.Cells(1, 2).Value = "测试编号"
.Cells(1, 3).Value = "测试类型"
End With'填充数据行
intI = 2
Do While Not adoRec.EOF
With uExcel.ActiveSheet
.Cells(intI, 1).Value = adoRec("StuCode")
.Cells(intI, 2).Value = adoRec("TestCode")
.Cells(intI, 3).Value = adoRec("TestType")
End With
intI = intI + 1
adoRec.MoveNext
Loop
adoRec.Close 'uExcel.ActiveSheet.PageSetup.Orientation = xlPortrait 'xlLandscape
'uExcel.ActiveSheet.PageSetup.PaperSize = xlPaperA4 '适应于A4纸
'uExcel.ActiveSheet.PrintOut'打印输出
'uExcel.DisplayAlerts = False '不保存后退出
'uExcel.Quit
'uExcel.DisplayAlerts = True
'uExcel.Quit
Set uExcel = Nothing
Set uExcelBook = Nothing