点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)我一直试图通过研究来解决这个问题...
点击此处---> 群内免费提供SAP练习系统(在群公告中)加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)我一直试图通过研究来解决这个问题...
加入QQ群:457200227(SAP S4 HANA技术交流) 群内免费提供SAP练习系统(在群公告中)
我一直试图通过研究来解决这个问题,但是运气不佳。
我想用excel vba创建一个应用程序,该应用程序允许用户连接到HANA,并能够从vba将数据插入到hana视图中。
任何提示将不胜感激!
到目前为止,我已经查看了该线程:
将CONN视作对象'ADODB.Connection
将rs作为对象'ADODB.RecordSet
将Strim设置为字符串
StrSql =" Provider = SAPNewDBMDXProvider.1;数据源= 10.xxx.xxx.30:30015; Password = xxx; User ID = xxx; Location =; Integrated Security =; Persist Security Info = True;假冒级别= 匿名;模式=读取;保护级别=无;扩展属性='SFC_INSTANCE_NUM = 00';初始目录= COMMONTEMP.SAKAPUR; MDX兼容性= 1"
CONN.Open StrSql
我能够创建一个连接,但是我不知道如何在那之后将数据插入到我想要的视图中
嗨,胡安·卡洛斯,
如果您仍在查找,这里是一个示例-代码如下。 不确定如何共享excel示例本身,因此如果要重新创建,请按以下说明进行操作。 但是我认为,如果您相当熟悉Excel/VBA的工作以及与数据库的交互,下面的VBA代码将显示您所需的一切。
在HANA中
在Excel中
在Excel/VBA中
再次在Excel中-添加两个按钮
EXCEL的外观如下:
添加新数据时,不应手动填充以灰色标记的列
HANA脚本:
---------------------------------
放置表格EXCEL_SIMPLE_DEMO;
创建列表EXCEL_SIMPLE_DEMO
(
" ID"整数不为null由默认身份标识生成
,"类别" CHAR(1)不为空
," NAME" VARCHAR(20)不为空
," VALUE"整数不为空
,"已创建"时间戳记不为空
,主键(" ID")
,UNIQUE("名称")
);
插入EXCEL_SIMPLE_DEMO(" CATEGORY"," NAME"," VALUE"," CREATED")值(" A"," ITEM A1",10,current_timestamp);
插入EXCEL_SIMPLE_DEMO(" CATEGORY"," NAME"," VALUE"," CREATED")值(" A"," ITEM A2",100,current_timestamp);
插入EXCEL_SIMPLE_DEMO(" CATEGORY"," NAME"," VALUE"," CREATED")值('A','ITEM A3',1000,current_timestamp);
插入EXCEL_SIMPLE_DEMO(" CATEGORY"," NAME"," VALUE"," CREATED")值(" B"," ITEM B1",20,current_timestamp);
插入EXCEL_SIMPLE_DEMO(" CATEGORY"," NAME"," VALUE"," CREATED")值(" B"," ITEM B2",200,current_timestamp);
插入EXCEL_SIMPLE_DEMO(" CATEGORY"," NAME"," VALUE"," CREATED")值(" B"," ITEM B3",2000,current_timestamp);
插入EXCEL_SIMPLE_DEMO(" CATEGORY"," NAME"," VALUE"," CREATED")值(" C"," ITEM C1",40,current_timestamp);
插入EXCEL_SIMPLE_DEMO(" CATEGORY"," NAME"," VALUE"," CREATED")值(" C"," ITEM C2",400,current_timestamp);
插入EXCEL_SIMPLE_DEMO(" CATEGORY"," NAME"," VALUE"," CREATED")值(" C"," ITEM C3",4000,current_timestamp);
从EXCEL_SIMPLE_DEMO中选择*;
VBA代码
---------------------------------
显式选项
将sDRIVER作为字符串=" HDBODBC32"
将sSERVERNODE设置为String =" 10.xxx.xxx.xxx:30015"
const sUID as String =" EXCEL_DEMO"
将sPWD构造为String =" password"
将oConn转换为ADODB.Connection
私有子ConnectToDB()
昏暗的connStr作为字符串
connStr =""
connStr = connStr&" Driver = {"&sDRIVER&"};"
connStr = connStr&" ServerNode ="&sSERVERNODE&";"
connStr = connStr&" UID ="&sUID&";"
connStr = connStr&" PWD ="&sPWD&";"
设置oConn = CreateObject(" ADODB.Connection")
oConn.Open connStr
结束子
私人子DisconnectFromDB()
oConn.Close
设置oConn =什么
结束子
私有子ExecuteSQL(SQLStr作为字符串)
oConn.Execute SQLStr
结束子
私有子LoadDataFromTable(sTable作为字符串,obj作为ListObject,sFilter作为字符串)
像ADODB.Recordset一样昏暗
将i_ret设置为整数
设置rs =新的ADODB.Recordset
rs.CursorLocation = adUseClient
如果oConn一无所有
MsgBox"没有打开的连接!",vbExclamation
Err.Raise 10001," modDB.RunProcedureAsSQLStmt","没有与DB的开放连接"
如果结束
如果oConn.State <> 1然后
MsgBox"没有打开的连接!",vbExclamation
Err.Raise 10001," modDB.RunProcedureAsSQLStmt","没有与DB的开放连接"
如果结束
rs。打开"从EXCEL_DEMO中选择*"。 &sTable&" where"&sFilter,oConn,adOpenStatic
i_ret = rs.RecordCount
如果obj.ListRows.Count> = 1那么
obj.DataBodyRange.Delete
如果结束
如果rs.RecordCount> 0那么
obj.Range(2,1).CopyFromRecordset rs
如果结束
rs.Close
设置rs =无效
结束子
公共子LoadSimpleDemo()
昏暗的obj作为ListObject
昏暗的sFilter作为字符串
sFilter = Range(" VAR_CATEGORY_FILTER")。值
如果Len(Trim(sFilter))= 0那么
sFilter =" 1 = 1"'对于所有记录始终为真的过滤器
其他
sFilter =" CATEGORY ='"&sFilter&"'"
如果结束
致电ConnectToDB
设置obj = Sheets(" Sheet1")。ListObjects(" TAB_EXCEL_SIMPLE_DEMO")
调用LoadDataFromTable(" EXCEL_SIMPLE_DEMO",obj,sFilter)
呼叫DisconnectFromDB
结束子
公共子SaveSimpleDemo()
昏暗的valId作为字符串
昏暗的valCategory作为字符串
昏暗的valName作为字符串
将valValue设置为字符串
将行作为范围变暗
将SQLStr变暗为字符串
致电ConnectToDB
对于[TAB_EXCEL_SIMPLE_DEMO]中的每一行。行
valId = row.Columns(1).Value
valCategory = row.Columns(2).Value
valName = row.Columns(3).Value
valValue = row.Columns(4).Value
如果不是IsNumeric(valId)那么
SQLStr =""
SQLStr = SQLStr&"插入EXCEL_DEMO.EXCEL_SIMPLE_DEMO("" CATEGORY"","" NAME"","" VALUE"","" CREATED"")"
SQLStr = SQLStr&"值('"&valCategory&"','"&valName&"',"&valValue&",current_timestamp)"
ExecuteSQL SQLStr
如果结束
下一步
呼叫DisconnectFromDB
'重新加载
调用LoadSimpleDemo
结束子
一周热门 更多>