發表文章

[js] import file

圖片
https://www.youtube.com/watch?v=kJT-iMYMPKg&ab_channel=neilscodetutorials <script src=".../jquery.min.js"></script> <div id="buttondiv" >   <input type="file" id="inputfile" />   <input type="button" id="viewfile" value="Import file" /> </div> <div class="container" id="container">   <table class="gridtable" id="tableMain">     <thead>        <tr class="tableheader">           <th> column1</th>           <th> column2</th>           <th> column3</th>           <th> column4</th>        </tr>      </thead>   </table> </div> <script>    $(document).ready(function(){      $('#viewfile').click(function(){          var rdr ...

用JAVA來讀取Excel檔

 https://qaz33326.pixnet.net/blog/post/8684268 首先 1.指定 Workbook 就是指定要打開哪份文件檔 Workbook workbook = Workbook.getWorkbook(new File("test.xls"));   2. 指定Sheet 就是指定要讀取哪個Sheet Sheet sheet = workbook.getSheet("Sheet1");   3.取得Cell中的資料 指定要讀取哪一個位置的資料 sheet.getCell(0, 1).getContents(); 拿(0,1)在這份資料來說,   會讀出2   4.關閉文件 workbook.close(); 讀取就是這麼簡單   再介紹兩個常用的方法 讀出文件有幾列 sheet.getColumns() 讀出文件有幾行 sheet.getRows() 拿這份文件來說,   分別是 sheet.getColumns() = 2 sheet.getRows() = 7 附上程式碼 import java.io.IOException; import java.io.File; import jxl.Sheet; import jxl.Workbook; import jxl.read.biff.BiffException; public class test { public static void main(String[] arge) { try { Workbook workbook = Workbook.getWorkbook(new File("test.xls")); Sheet sheet = workbook.getSheet("Sheet1"); System.out.println(sheet.getCell(0, 1).getContents()); System.out.println(sheet.getColumns()); System.out.println(sheet.getRows()); workbook.close(); } catch (...

ajax上傳excel檔案匯入資料

 https://www.itread01.com/content/1548080108.html 本次上傳檔案是用jsp作為前臺介面,servlet為後臺,沒有使用框架處理,上傳檔案用的ajaxfileupload.js封裝的工具類 上傳檔案需要commons-fileupload-1.3.1.jar,commons-io-2.2.jar。 @處理excel 處理excel使用的是poi包 poi-3.9.jar,poi-ooxml-3.9.jar,poi-ooxml-schemas-3.9.jar,xmlbeans-2.3.0.jar,dom4j-1.6.1.jar, 如果excel字尾是xls的話就不用加xmlbeans-2.3.0.jar,dom4j-1.6.1.jar這個兩個jar。這兩個jar主要解決比較老版的excel字尾為xlsx的 @HTML  <div class="btn-file-box pos-rel"> <input type="file" id="upload" name="upload" style="font-size: 0;opacity: 0;width: 100px;height: 100px;position: absolute; left: 0;top: 0;" /> <span class="btn ">選擇檔案</span> <br/> <br/> <table id="tbList" border="1" width="300px"> <tr> <td width="100px">編號</td> <td width="100px">姓名</td> <td width="100px">年齡</td> </tr> </table> </div> @JS <script type=...

jQuery-File-Upload

 import excel 1.先用Ann 方法接 $( '#uploadImages' ).on( 'change' , function ( ) { var formData = new FormData(); for ( var i = 0 ; i < this .files.length; i++){ formData.append( 'file' , this .files[i]); $.ajax({ url : '/file/upload' , type : 'post' , data : formData, cache : false , contentType : false , processData : false , success : function ( ) { alert( "upload successfully" ) } }) } } $( 'form' )[ 0 ].reset(); }) 2. https://stackoverflow.com/questions/5494387/read-excel-data-with-jquery 2. @{ ViewBag.Title = "djk8888"; } <script src="~/jQuery-File-Upload-8.8.5/js/jquery.min.js"></script> <scr...

jQuery file download

  http://samchu.logdown.com/posts/430528-easy-use-jquery-filedownload https://github.com/johnculviner/jquery.fileDownload/blob/master/src/Scripts/jquery.fileDownload.js $ . fileDownload ( "picCustom.do" ,   { httpMethod : "POST" , data : { act : "downloadZipImages" , jsonstr : JSON . stringify ( jsonObj )} }); 後端部分 public ModelAndView downloadZipImages ( HttpServletRequest request , HttpServletResponse response ) throws PGException { String regEx = "[/\\\\:*?\"<>|]" ; Pattern pattern = Pattern . compile ( regEx ); Matcher matcher = null ; try { request . setCharacterEncoding ( "UTF-8" ); String jsonstr = org . apache . commons . lang . StringUtils . trimToNull ( request . getParameter ( "jsonstr" )); String jsonstrrep = jsonstr . replaceAll ( "," , "," ); JSONO...