1,将查询的数据导出到Excel中,自动显示EXCEL,将查询的数据导出到Excel中,根据记录集的条数导入到相应的单元格中,
2,为什么第一段代码当 h < 25 时Excel能自动显示,而第二段代码只有当打开任意一Excel表才能显示:
h = Adodc1.Recordset.RecordCount
k = Adodc1.Recordset.Fields.Count
If h < 25 Then
For i = 1 To h
For j = 3 To k
mysheet.Cells(i + 8, j - 1) = Adodc1.Recordset.Fields.Item(j - 1).Value
Next j
Adodc1.Recordset.MoveNext
Next i
myexcel.Visible = True
Exit Sub
End If
If h > 25 And h <= 50 Then
For i = 1 To 25
For j = 3 To k
mysheet.Cells(i + 8, j - 1) = Adodc1.Recordset.Fields.Item(j - 1).Value
Next j
Adodc1.Recordset.MoveNext
Next i
For i = 1 To h
For j = 3 To k - 18
mysheet.Cells(i + 8, j + 4) = Adodc1.Recordset.Fields.Item(j - 1).Value
Next j
Adodc1.Recordset.MoveNext
Next i
myexcel.Visible = True
Exit Sub
End If
EXCEL中使用高级筛选可以将筛选结果直接复制到本工作表的其它区域,可根据需要将筛选出的内容再复制粘贴到其它工作表,或者在其它工作表使用公式,引用复制到的区域中的内容;
高级筛选可以使用通配符“*”筛选出含某些字符的记录,同时满足的条件放在同一行中,只要满足一个条件即可的,放在不同行中;
列出筛选条件,选择:数据--排序和筛选--高级;
查询的数据导出到Excel中,自动显示EXCEL
我将查询的数据导出到Excel中,根据记录集的条数导入到相应的单元格中,为什么第一段代码当 h < 25 时Excel能自动显示,而第二段代码只有当打开任意一Excel表才能显示
h = Adodc1.Recordset.RecordCount
k = Adodc1.Recordset.Fields.Count
If h < 25 Then
For i = 1 To h
For j = 3 To k
mysheet.Cells(i + 8, j - 1) = Adodc1.Recordset.Fields.Item(j - 1).Value
Next j
Adodc1.Recordset.MoveNext
Next i
myexcel.Visible = True
Exit Sub
End If
If h > 25 And h <= 50 Then
For i = 1 To 25
For j = 3 To k
mysheet.Cells(i + 8, j - 1) = Adodc1.Recordset.Fields.Item(j - 1).Value
Next j
Adodc1.Recordset.MoveNext
Next i
For i = 1 To h
For j = 3 To k - 18
mysheet.Cells(i + 8, j + 4) = Adodc1.Recordset.Fields.Item(j - 1).Value
Next j
Adodc1.Recordset.MoveNext
Next i
myexcel.Visible = True
Exit Sub
End If