W

로컬 텍스트 엑셀 파일 읽기/쓰기

· 16년 전 · 5335

익스플로우의 보안에 허용만 가능하면 자바스크립트 상에서도 읽기/쓰기가 가능하다.

 

우선 text파일 읽고 쓰는 예제이다.(C:\\book1.txt를 읽고 씀)

 

=====================================================================================================================

<html>
<head>
<title>file save/load</title>

 

<script type="text/javascript">

    var fso=new ActiveXObject("Scripting.FileSystemObject");
    var filename="C:\\book1.txt";
    function savefile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,2,true);
        f.Write(myarea.innerHTML);
        f.Close();
    }
   
    function loadfile() {
        if (!fso.FileExists(filename)) {
            fso.CreateTextFile(filename,true);
        }
        var f=fso.OpenTextFile(filename,1);
        r=f.ReadAll();
        f.Close();
        myarea.innerHTML=r;
    }
   
   
    //function window.onload() {
    //    loadfile(filename);
    //}
</script>


</head>
<body>
 <table>
  <tr>
   <td>
    <div id=myarea contenteditable=true style="width:320;height:240;border:solid 2 inset;overflow:scroll;background-color:silver;"></div>
    <br><input type=button value=load onclick=loadfile()><input type=button value=save onclick=savefile()>
   </td>
  </tr>
 </table>
</form>
</body>
</html>

 

======================================Excel 파일 열고 쓰기 =================================================

- 쓰기 -

<script type="text/javascript">

// Declare the variables
var Excel, Book;

// Create the Excel application object.
Excel = new ActiveXObject("Excel.Application");

// Make Excel visible.
Excel.Visible = true;

// Create a new work book.
Book = Excel.Workbooks.Add()

// Place some text in the first cell of the sheet.
Book.ActiveSheet.Cells(1,1).Value = "This is column A, row 1";

// Save the sheet.
Book.SaveAs("C:\\book1.xls");

// Close Excel with the Quit method on the Application object.
Excel.Application.Quit();
</script>

 

- 열기 -

function StartExcel() {
var oExcel;

var oWBook;
oExcel = new ActiveXObject("Excel.Application");

oExcel.Visible = true;

oExcel.workbooks.open("C:/test.xls");

oExcel.Quit();

oExcel = null;
}

 

간단한 파일 읽기의 경우 상당히 유용할 수 있겠다..

 
[이 게시물은 관리자님에 의해 2011-10-31 17:16:08 PHP & HTML에서 이동 됨]
|
댓글을 작성하시려면 로그인이 필요합니다. 로그인

프로그램

+
제목 글쓴이 날짜 조회
15년 전 조회 1,779
15년 전 조회 595
15년 전 조회 1,083
15년 전 조회 1,058
15년 전 조회 2,850
15년 전 조회 3,163
15년 전 조회 1,836
15년 전 조회 1,345
15년 전 조회 1,962
15년 전 조회 1,469
15년 전 조회 1,073
15년 전 조회 3,767
15년 전 조회 1,408
15년 전 조회 1,507
15년 전 조회 2,736
15년 전 조회 1,430
15년 전 조회 4,157
15년 전 조회 2,371
15년 전 조회 3,147
15년 전 조회 1,766
15년 전 조회 1,995
15년 전 조회 1,293
15년 전 조회 4,371
15년 전 조회 3,951
15년 전 조회 3,773
15년 전 조회 5,188
15년 전 조회 3,410
15년 전 조회 1,790
15년 전 조회 1,749
15년 전 조회 1,899
15년 전 조회 1,589
15년 전 조회 3,988
15년 전 조회 2,900
15년 전 조회 2,086
15년 전 조회 1,662
15년 전 조회 1,899
15년 전 조회 2,381
15년 전 조회 1,463
15년 전 조회 2,396
15년 전 조회 1,733
15년 전 조회 1,829
15년 전 조회 1,483
15년 전 조회 2,172
15년 전 조회 1,499
15년 전 조회 1,921
16년 전 조회 2,111
16년 전 조회 1,185
16년 전 조회 1,246
16년 전 조회 1,891
16년 전 조회 5,336
16년 전 조회 1,634
16년 전 조회 2,143
16년 전 조회 2,344
16년 전 조회 1,494
16년 전 조회 1,303
16년 전 조회 2,215
16년 전 조회 4,931
16년 전 조회 2,205
16년 전 조회 2,864
16년 전 조회 1,745
16년 전 조회 3,597
16년 전 조회 4,434
16년 전 조회 3,102
16년 전 조회 2,349
16년 전 조회 2,430
16년 전 조회 2,681
16년 전 조회 2,165
16년 전 조회 5,508
16년 전 조회 3,361
16년 전 조회 1,350
16년 전 조회 1,697
16년 전 조회 5,070
16년 전 조회 2,303
16년 전 조회 3,408
16년 전 조회 2,643
16년 전 조회 1,558
16년 전 조회 5,354
16년 전 조회 2,472
16년 전 조회 5,961
16년 전 조회 1,939
16년 전 조회 4,012
16년 전 조회 3,031
16년 전 조회 2,214
16년 전 조회 2,234
16년 전 조회 4,403
16년 전 조회 3,295
16년 전 조회 2,828
16년 전 조회 2,968
16년 전 조회 2,082
16년 전 조회 1,769
16년 전 조회 1,679
16년 전 조회 1,404
16년 전 조회 1,671
16년 전 조회 1,901
16년 전 조회 1,590
16년 전 조회 4,840
16년 전 조회 3,821
16년 전 조회 1,790
16년 전 조회 1,532
16년 전 조회 2,272
🐛 버그신고