ASP: How to import data from a merged cell in Excel?
-
08-07-2019 - |
Question
I need to import data from an excel file, but some field is a merged cell.
How can I determine if a field is merged or not, and how many cells are merged together in that field?
My code is like this:
Dim Conn, DBPath ,Rs
Set Conn = Server.CreateObject("ADODB.Connection")
DBPath = "Driver={Microsoft Excel Driver (*.xls)}; DBQ=" & Server.MapPath("program.xls")
Conn.Open Driver & DBPath
Sql="Select F1, F2 From [Sheet1$]"
Set ODBCrs=Conn.Execute(Sql)
while Not ODBCrs.EOF
conn2.execute("insert into....")
ODBCrs.MoveNext
wend
ODBCrs.Close
Conn.Close
The data is like this:
Category A
name 1 desc 1
name 2 desc 2
Category B
name 3 desc 3
name 4 desc 4
Thanks a lot!!
Solution
The merging of cells is just a formatting thing. It won't show up in the data. If you are accessing the Excel file through ADO and the Excel driver, you are just looking at the data, not the formatting.
If you really, really have to do this, you may have to create an Excel.Application object and use the Excel object model to inspect the cells and their formatting. This works ok on the desktop but can't really be done reliably on a server, so, for example, if you're trying to do this in a web application, you may have problems.