获取excel对象
- 获取本地文件路径:FilePath = Dialogs.ShowOpenFileDialog
- 获取文件类型:FileType = FilePath.Substring
- 创建excel对象:
1.var excel = new ActiveXObject("Excel.Application")
2.excelWorkBook = excel.Workbooks.Open(FilePath);
3.excelSheet = excelWorkBook.Worksheets(1);
读取excel对象中数据
- 获取遍历行列(行列数为原始文件的行列数,修改后保持不变)
1.行数:rowCount = excelSheet.UsedRange.Rows.count;
2.列数:colCount = excelSheet.UsedRange.Columns.count;- 读取列
var cell = excelSheet.Cells(i,j).Value- 缓存到数组
1.遍历列数组:arrRow = lims.AAdd(arrRow, cell)
2.遍历行数组:arrData = lims.AAdd(arrData,arrRow);
数据持久化到数据库
1.定义键值对平行数组用于操作关系表:
arrColumnName
arrColumnValue
2.为每组键值对数组赋值:
Aadd(arrColumnName, "CLEARANCEID");
Aadd(arrColumnValue, “clearanceid”);
3.插入表字段
1.遍历行执行sql语句
2.遍历每行前清空键值对平行数组
3.拼接sql语句
表:Insert into CLEARANCEFORM
列:BuildStringforin(arrColumnName)
值:StrTran(BuildStringForIn(arrColumnValue),chr(39),chr(63))
将单引号替换为问号(sql变量)