2013-07-18 1 views
4

저는 초급자이며 VBA 형식의 프로그래밍 도구입니다. Filereader 및 Json 배열과 같은 웹 도구보다 VBA에서 Excel 파일을 읽는 것이 Excel 작업을 훨씬 쉽게 수행 할 수 있습니다.Html5 파일 판독기 - 로컬 Json 배열 파일을 읽고 특정 섹션 만 표시

내 Json 배열 파일에 다음 내용이 있습니다.

[ 
    ["TWE",6000,4545.5 ], 
    ["RW",1000,256.3 ] 
] 

나는 253.6

당신이 날 도와 줄 수 값만에게 다음과 같은 HTML 파일에서 읽고 표시하고 싶습니다. 여기

HTML 파일 리더 예를

<!DOCTYPE html> 
<html> 
    <head> 
     <script>   
      function handleFileSelect() 
      {    
       if (window.File && window.FileReader && window.FileList && window.Blob) { 

       } else { 
        alert('The File APIs are not fully supported in this browser.'); 
        return; 
       } 

       input = document.getElementById('fileinput'); 
       if (!input) { 
        alert("Um, couldn't find the fileinput element."); 
       } 
       else if (!input.files) { 
        alert("This browser doesn't seem to support the `files` property of file inputs."); 
       } 
       else if (!input.files[0]) { 
        alert("Please select a file before clicking 'Load'");    
       } 
       else { 
        file = input.files[0]; 
        fr = new FileReader(); 
        fr.onload = receivedText; 
        fr.readAsText(file); 
       } 
      } 

      function receivedText() {   
       //result = fr.result; 
       document.getElementById('editor').appendChild(document.createTextNode(fr.result)) 
      }   

     </script> 
    </head> 
    <body> 
     <input type="file" id="fileinput"/> 
     <input type='button' id='btnLoad' value='Load' onclick='handleFileSelect();'> 
     <div id="editor"></div> 
    </body> 
</html> 
+0

문서에 링크를 올리시겠습니까? 어쩌면 짧은 버전. – RomanGorbatko

답변

6

당신이 문자열로 fr.readAsText로 텍스트를 얻을 경우, 당신은 JSON.parse() (참조 : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse)를 사용할 수있는 JSON으로 문자열로 변환 목적. 그런 다음 일반 배열처럼 특정 컨텐츠에 액세스 할 수 있습니다.

+0

고맙습니다. 여기에 "receivedText"함수 함수 아래에 추가 한 추가 코드 receivedText() { // result = fr.result; var newArr = JSON.parse (fr.result); 알림 (newArr [1] [2]); –