W

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

· 16년 전 · 5344

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

 

우선 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,790
15년 전 조회 609
15년 전 조회 1,096
15년 전 조회 1,067
15년 전 조회 2,859
15년 전 조회 3,175
15년 전 조회 1,850
15년 전 조회 1,356
15년 전 조회 1,974
15년 전 조회 1,478
15년 전 조회 1,082
15년 전 조회 3,777
15년 전 조회 1,421
15년 전 조회 1,517
15년 전 조회 2,744
15년 전 조회 1,444
15년 전 조회 4,169
15년 전 조회 2,381
15년 전 조회 3,159
15년 전 조회 1,775
15년 전 조회 2,004
15년 전 조회 1,305
15년 전 조회 4,382
15년 전 조회 3,959
15년 전 조회 3,784
15년 전 조회 5,200
15년 전 조회 3,421
15년 전 조회 1,802
15년 전 조회 1,761
15년 전 조회 1,906
15년 전 조회 1,598
15년 전 조회 3,998
15년 전 조회 2,913
15년 전 조회 2,094
15년 전 조회 1,673
15년 전 조회 1,909
15년 전 조회 2,391
15년 전 조회 1,473
15년 전 조회 2,407
15년 전 조회 1,741
15년 전 조회 1,839
15년 전 조회 1,493
15년 전 조회 2,179
15년 전 조회 1,512
15년 전 조회 1,926
16년 전 조회 2,117
16년 전 조회 1,189
16년 전 조회 1,256
16년 전 조회 1,903
16년 전 조회 5,345
16년 전 조회 1,644
16년 전 조회 2,154
16년 전 조회 2,352
16년 전 조회 1,507
16년 전 조회 1,310
16년 전 조회 2,229
16년 전 조회 4,941
16년 전 조회 2,216
16년 전 조회 2,872
16년 전 조회 1,754
16년 전 조회 3,607
16년 전 조회 4,445
16년 전 조회 3,110
16년 전 조회 2,357
16년 전 조회 2,443
16년 전 조회 2,688
16년 전 조회 2,174
16년 전 조회 5,516
16년 전 조회 3,372
16년 전 조회 1,364
16년 전 조회 1,707
16년 전 조회 5,079
16년 전 조회 2,315
16년 전 조회 3,417
16년 전 조회 2,654
16년 전 조회 1,572
16년 전 조회 5,365
16년 전 조회 2,480
16년 전 조회 5,971
16년 전 조회 1,950
16년 전 조회 4,021
16년 전 조회 3,040
16년 전 조회 2,224
16년 전 조회 2,243
16년 전 조회 4,407
16년 전 조회 3,303
16년 전 조회 2,839
16년 전 조회 2,977
16년 전 조회 2,096
16년 전 조회 1,776
16년 전 조회 1,689
16년 전 조회 1,411
16년 전 조회 1,683
16년 전 조회 1,913
16년 전 조회 1,606
16년 전 조회 4,848
16년 전 조회 3,834
16년 전 조회 1,801
16년 전 조회 1,545
16년 전 조회 2,284
🐛 버그신고