當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
用JavaScript实现简单的excel列转sql字符串
生活随笔
收集整理的這篇文章主要介紹了
用JavaScript实现简单的excel列转sql字符串
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
老慣例,先簡單解說一下再上代碼。有時候會有這樣的業(yè)務場景,即需要在sql的某些條件里面大量用到in或者not in進行篩查。
我們知道,in里面的內容其實就是字符串然后用逗號隔開。
這個工具的作用就是把excel列的內容,如:
蘋果
梨子
櫻桃
轉換成:("蘋果","梨子","櫻桃")
非常簡單,這樣就可以放到sql里面去用了。
<!DOCTYPE html> <html> <head><title>excel列轉sql字符串</title><meta charset="utf-8" /> </head> <body style="width:100%;height:100%;margin:0;"> <div style="line-height:50px;text-align:center;width:100%;height:50px;color:white;background-color:deepskyblue;font-weight:bold;">excel列轉sql字符串</div> <div style='text-align:center;'> <p>請將要處理的內容粘貼進去:</p> <textarea id='textarea' style='width:400px;height:200px;'></textarea></div> <div style='text-align:center;'><button onclick="change()">轉換</button></div> <div style='text-align:center;'> <p>結果:</p> <textarea id='result' disabled="disabled" style='width:400px;height:200px;'></textarea></div> </body> <script type="text/javascript"> function id(x){return document.getElementById(x); }function change() {var t = id("textarea").value.split('\n');var tmp = '(';for(var i=0;i<t.length;i++){tmp += "'"+t[i] + "',";}tmp = tmp.slice(0,-1) + ')';id("result").value = tmp; }</script> </html>總結
以上是生活随笔為你收集整理的用JavaScript实现简单的excel列转sql字符串的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 将oracle select * fro
- 下一篇: c++ 用指针将函数作为参数传参