VBA 把Excel表当做一个大数据库来操作

VBA 把Excel表当做一个大数据库来操作

python 复制代码
Sub SqlQueryBJD(strBillNo As String)

Dim strSql As String
Dim arrCol() As String
Dim strLineWhere
Dim arrWhere() As String
Dim strWhereVal As String

Dim strResultShowRng As String
Dim strWhereRng As String
Dim strShowResultRowRng As String
Dim strShowResultRowMsg As String

Dim strSqlSb As String
Dim wsDbQ As Worksheet
Dim sqlSb As New StringBulider

On Error GoTo er:

'日期,单号,直接费用,管理费,税率,税金,合计,报价单抬头,工程名称,提交单位,客户名称,地址,电话,施工面积,备注,项目类别,项目名称,数量,单位,材料单价,材料合价,人工单价,人工合价,工艺说明,材料成本,材料加价,材料利润,人工成本,人工加价,人工利润,单项利润人工单价    人工合价    工艺说明    材料成本    材料加价    材料利润    人工成本    人工加价    人工利润    单项利润

sqlSb.Append ("select rowNo,项目类别,项目名称,数量,单位,材料单价,材料合价,工艺说明")
sqlSb.Append (" from (")

sqlSb.Append ("select rowNo,项目类别&0 as 项目类别,项目名称,'t1' as 数量,'' as 单位,'' as 材料单价,'' as 材料合价,'' as 工艺说明 from [报价单记录$B1:AG]")
sqlSb.Append (" where 项目名称<>'' And cdbl(iif(数量 is null,0,数量))=0 ")
sqlSb.Append (" and 单号='" & strBillNo & "'")

sqlSb.Append ("union all select rowNo,项目类别&1,项目名称,数量,单位,材料单价,材料合价,工艺说明 from [报价单记录$B1:AG]")
sqlSb.Append (" where 项目名称<>'' And cdbl(iif(数量 is null,0,数量))>0")
sqlSb.Append (" and 单号='" & strBillNo & "'")

sqlSb.Append ("union all select max(rowNo),项目类别&2,'小计' as 项目名称,'t2' as 数量,'' as 单位,sum(iif(材料合价 is null,0,材料合价)) as 材料单价,'' as 材料合价,'' as 工艺说明 from [报价单记录$B1:AG]")
sqlSb.Append (" where 项目名称<>'' And cdbl(iif(数量 is null,0,数量))>0")
sqlSb.Append (" and 单号='" & strBillNo & "'")
sqlSb.Append (" group by 项目类别")

sqlSb.Append (" ) as tbz")

sqlSb.Append (" order by rowNo,项目类别")

strSql = sqlSb.ToString()

strResultShowRng = "A1:P?"
strWhereRng = "Format(日期,'yyyy-MM-dd')>=:B2:D|Format(日期,'yyyy-MM-dd')<=:C2:D|单号 like:B3:S|工程名称 like:E2:S|客户名称 like:E3:S|地址 like:G2:S|电话 like:G3:S"
strShowResultRowRng = ""
strShowResultRowMsg = ""
 

 
    Set wsDbQ = Worksheets("tempBjqdData")
     
'    arrCol = Split(strWhereRng, "|")
'
'
'    For Each strLineWhere In arrCol
'      arrWhere = Split(strLineWhere, ":")
'      strWhereVal = wsDbQ.Range(arrWhere(1)).Value
'
'      If Trim(strWhereVal) <> "" Then
'        strSqlSb = strSqlSb & " and " & arrWhere(0) & GetSqlVal(arrWhere(0), strWhereVal, arrWhere(2))
'      End If
'    Next strLineWhere
    
    Call SqlADODBQuery("tempBjqdData", strResultShowRng, strSql, strShowResultRowRng, strShowResultRowMsg)
    

 Exit Sub
er:
 MsgBox err.Description
 
End Sub
相关推荐
爱学习的阿磊3 分钟前
使用Fabric自动化你的部署流程
jvm·数据库·python
枷锁—sha9 分钟前
【SRC】SQL注入快速判定与应对策略(一)
网络·数据库·sql·安全·网络安全·系统安全
惜分飞22 分钟前
ORA-600 kcratr_nab_less_than_odr和ORA-600 4193故障处理--惜分飞
数据库·oracle
chian-ocean22 分钟前
CANN 生态进阶:利用 `profiling-tools` 优化模型性能
数据库·mysql
m0_5500246325 分钟前
持续集成/持续部署(CI/CD) for Python
jvm·数据库·python
AC赳赳老秦26 分钟前
代码生成超越 GPT-4:DeepSeek-V4 编程任务实战与 2026 开发者效率提升指南
数据库·数据仓库·人工智能·科技·rabbitmq·memcache·deepseek
啦啦啦_999940 分钟前
Redis-2-queryFormat()方法
数据库·redis·缓存
玄同7651 小时前
SQLite + LLM:大模型应用落地的轻量级数据存储方案
jvm·数据库·人工智能·python·语言模型·sqlite·知识图谱
吾日三省吾码2 小时前
别只会“加索引”了!这 3 个 PostgreSQL 反常识优化,能把性能和成本一起打下来
数据库·postgresql
chian-ocean2 小时前
百万级图文检索实战:`ops-transformer` + 向量数据库构建语义搜索引擎
数据库·搜索引擎·transformer