W

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

· 15년 전 · 5325

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

 

우선 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,769
15년 전 조회 592
15년 전 조회 1,079
15년 전 조회 1,048
15년 전 조회 2,839
15년 전 조회 3,152
15년 전 조회 1,830
15년 전 조회 1,336
15년 전 조회 1,954
15년 전 조회 1,459
15년 전 조회 1,063
15년 전 조회 3,757
15년 전 조회 1,399
15년 전 조회 1,496
15년 전 조회 2,724
15년 전 조회 1,425
15년 전 조회 4,149
15년 전 조회 2,361
15년 전 조회 3,141
15년 전 조회 1,758
15년 전 조회 1,987
15년 전 조회 1,286
15년 전 조회 4,364
15년 전 조회 3,938
15년 전 조회 3,767
15년 전 조회 5,181
15년 전 조회 3,401
15년 전 조회 1,782
15년 전 조회 1,744
15년 전 조회 1,887
15년 전 조회 1,581
15년 전 조회 3,980
15년 전 조회 2,893
15년 전 조회 2,078
15년 전 조회 1,656
15년 전 조회 1,891
15년 전 조회 2,371
15년 전 조회 1,456
15년 전 조회 2,390
15년 전 조회 1,724
15년 전 조회 1,820
15년 전 조회 1,475
15년 전 조회 2,164
15년 전 조회 1,493
15년 전 조회 1,908
15년 전 조회 2,101
15년 전 조회 1,178
15년 전 조회 1,237
15년 전 조회 1,880
15년 전 조회 5,326
16년 전 조회 1,628
16년 전 조회 2,136
16년 전 조회 2,336
16년 전 조회 1,485
16년 전 조회 1,293
16년 전 조회 2,207
16년 전 조회 4,922
16년 전 조회 2,199
16년 전 조회 2,856
16년 전 조회 1,736
16년 전 조회 3,588
16년 전 조회 4,426
16년 전 조회 3,095
16년 전 조회 2,341
16년 전 조회 2,421
16년 전 조회 2,672
16년 전 조회 2,159
16년 전 조회 5,501
16년 전 조회 3,352
16년 전 조회 1,345
16년 전 조회 1,690
16년 전 조회 5,061
16년 전 조회 2,297
16년 전 조회 3,401
16년 전 조회 2,634
16년 전 조회 1,554
16년 전 조회 5,345
16년 전 조회 2,462
16년 전 조회 5,954
16년 전 조회 1,928
16년 전 조회 4,005
16년 전 조회 3,021
16년 전 조회 2,206
16년 전 조회 2,225
16년 전 조회 4,402
16년 전 조회 3,285
16년 전 조회 2,822
16년 전 조회 2,954
16년 전 조회 2,074
16년 전 조회 1,760
16년 전 조회 1,670
16년 전 조회 1,393
16년 전 조회 1,665
16년 전 조회 1,894
16년 전 조회 1,586
16년 전 조회 4,835
16년 전 조회 3,817
16년 전 조회 1,782
16년 전 조회 1,526
16년 전 조회 2,261
🐛 버그신고