简体   繁体   English

更新Excel工作表单元格(该单元格是一个下拉列表)

[英]Updating Excel sheet cell (the cell is a dropdown list)

Basically I have a template excel sheet that I copy to another directory. 基本上,我有一个模板excel表,可以将其复制到另一个目录。 I open the connection to said new sheet using: 我使用以下命令打开到所述新工作表的连接:

Set cn = Server.CreateObject("ADODB.Connection")
cn.Open "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" &  excel_copy & ";Extended Properties=""Excel 8.0;HDR=No;"""
Set rsHoja = cn.OpenSchema(20)
hoja=rsHoja("Table_Name")
rsHoja.close
Set rsHoja = nothing  
Set rsHoja = Server.CreateObject("ADODB.Recordset")

From This point on I've been successfully doing updates such as: 从这一点开始,我已经成功完成了以下更新:

sql =  " UPDATE [Hoja1$B2:B2] SET F1='"&VALUE&"'"
rsHoja.Open sql, cn

The problem comes when I'm trying to do an update on a cell that takes it's value from a List(that is in the same sheet) 当我尝试对从列表(在同一工作表中)获取值的单元格进行更新时,问题就来了

I keep getting an error: 我不断收到错误消息:

Microsoft Access Database Engine error '80040e10'

Any idea how to assign the value to the cell from the List? 任何想法如何将值分配给列表中的单元格? I've tried the list's name[cell of the value] and other methods but I'm pretty much trying to figure it out blindly now. 我已经尝试过使用列表的名称[值的单元格]和其他方法,但是现在我几乎想盲目地找出它。 I've also looked everywhere with no luck. 我到处也没有运气。

Update 1: 更新1:

I forgot to mention my file doesn't have headers if that's any help. 我忘了提一下我的文件没有标题,如果有帮助的话。

As you are using Microsoft.ACE.OLEDB.12.0 database engine for connection, 当您使用Microsoft.ACE.OLEDB.12.0数据库引擎进行连接时,

Possibilities: 可能性:

1) Make sure you are using Excel 12.0 in Extended Properties if you are using .xlsx file as Data source 1)如果使用.xlsx文件作为数据源,请确保在扩展属性中使用Excel 12.0

2) Make sure you are using Excel 8.0 in Extended Properties if you are using .xls file as Data source 2)如果使用.xls文件作为数据源,请确保在扩展属性中使用Excel 8.0

Check this URL for more info on this: 检查此URL以获取有关此的更多信息:

https://www.connectionstrings.com/excel/ https://www.connectionstrings.com/excel/

所以我终于找到了问题...它与我的SQL或具有列表的单元格无关,问题是(在excel工作表中)该单元格被标记为DATE,但是列表是一个字符串,所以无论何时我试图在它上面写我的字符串给类型错误...改变Excel上的单元格以字符串/一般解决了这个问题,该单元格正确获取值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM